以下の内容はhttps://tech.motoki-watanabe.net/entry/2024/10/06/175258より取得しました。


p5.js で The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. とでてマイクのデータをとれないとき

事象

The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.

とでてマイクのデータをとれないときがある。
ユーザーの操作ない状態でマイクのデータをとれないと。

解決方法

以下のようにすればとれる。(コンソールにwarningは出たままだが)

function setup() {

  ~~(省略)~~

  mic = new p5.AudioIn();
}

let isStartAudio = false;

async function touchStarted() {
  if (!isStartAudio) {
    // これで画面触ったときにマイクの音声の取得を問題なくできるようになる
    await userStartAudio();
    mic.start();
    console.info("success start audio");
    isStartAudio = true;
  }
}

参考文献

himco.jp




以上の内容はhttps://tech.motoki-watanabe.net/entry/2024/10/06/175258より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14