create html <audio> element from Tone.js object

故事扮演 提交于 2020-06-29 03:52:26

问题


I am using Tone.js to modify sounds:

audio_url = "/sounds/damncoolbeats.m4a"
player = new Tone.Player(audio_url)
modified_player = <some Tone.js modifications to player>

To play the modified sound I would like to use a web audio element so that I can make use of audio.currentTime and eventlisteners to 'play' 'pause' and 'timeupdate' (which I can't seem to do with Tone.js).

The only way I managed to create an audio element so far is by loading from an url:

audio = new Audio(audio_url)

My current hacky solution is to load the original url twice, once in Tone.js and once as web audio, then I play both players simultaneously while keeping the web audio volume at zero. Loading the same http resource twice really messes with my website speed though...

Is there a way to create the web audio element from a Tone.js object?

audio = new Audio(modified_player) //does not work
audio = new Audio(modified_player.buffer) //does not work
audio = new Audio(URL.createObjectURL(modified_player.buffer)) //does not work

来源:https://stackoverflow.com/questions/61446808/create-html-audio-element-from-tone-js-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!