Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.37k stars 976 forks source link

Recorder on Chrome #1155

Closed git-esad closed 1 year ago

git-esad commented 1 year ago

I try this : https://codepen.io/benoitwimart/pen/jOpMENN?editors=1111

const recorder = new Tone.Recorder();
const synth = new Tone.Synth().connect(recorder);
// start recording
recorder.start();
// generate a few notes
synth.triggerAttackRelease("C3", 0.5);
synth.triggerAttackRelease("C4", 0.5, "+1");
synth.triggerAttackRelease("C5", 0.5, "+2");
// wait for the notes to end and stop the recording
setTimeout(async () => {
    // the recorded audio is returned as a blob
    const recording = await recorder.stop();
  console.log(recording.size);
}, 4000);

I have a 0 in console with Chrome :(

marcelblum commented 1 year ago

I think it's just because of Chrome's rules about needing a user interaction to unsuspend the context, if you create a button and wrap your code in the following it works for me in Chrome:

document.querySelector("button").addEventListener("click", () => {
  Tone.start();
  // your code here...
});
git-esad commented 1 year ago

Good!