audio-playback-module.js 407 B

12345678910111213141516
  1. var AudioContext = window.AudioContext || window.webkitAudioContext;
  2. var ctx;
  3. export async function play(chunk) {
  4. if (!ctx) {
  5. ctx = new AudioContext();
  6. }
  7. const source = ctx.createBufferSource();
  8. source.buffer = await ctx.decodeAudioData(chunk.buffer);
  9. source.connect(ctx.destination);
  10. source.ended = () => { source.disconnect(ctx.destination); }
  11. source.start(0);
  12. }