guest271314 / SpeechSynthesisRecorder

Get audio output from window.speechSynthesis.speak() call as ArrayBuffer, AudioBuffer, Blob, MediaSource, MediaStream, ReadableStream, other object or data types
82 stars 19 forks source link

Can the recorded audioOutput be saved to the file system? #11

Closed fninsiima closed 6 years ago

fninsiima commented 6 years ago

Just wondering if there is an option of saving the recording to file system

guest271314 commented 6 years ago

@fninsiima Yes, you can use tts.blob(), <a> element with download attribute, and href attribute set to Blob URL

let ttsRecorder = new SpeechSynthesisRecorder({
  text:"The revolution will not be televised", 
  utteranceOptions:{
    voice: "english-us espeak",
    lang: "en-US",
    pitch: .75,
    rate: 1,
    volume: 1
  }
});

ttsRecorder.start()
.then(tts => tts.blob())
.then(({tts, data}) => {
  const a = document.createElement("a");
  const blobURL = URL.createObjectURL(data);
  a.download = "synthesizedAudio";
  a.href = blobURL;
  document.body.appendChild(a);
  a.click();
})
.catch(err => console.log(err))