浏览代码

fix: resume browser audio context for live listen

master
Jan Svabenik 1 天前
父节点
当前提交
7b8152e33a
共有 1 个文件被更改,包括 4 次插入0 次删除
  1. +4
    -0
      web/app.js

+ 4
- 0
web/app.js 查看文件

@@ -226,6 +226,7 @@ class LiveListenWS {
this.audioCtx = new (window.AudioContext || window.webkitAudioContext)({
sampleRate: this.sampleRate
});
this.audioCtx.resume().catch(() => {});
this.nextTime = 0;
this.started = false;
}
@@ -233,6 +234,9 @@ class LiveListenWS {
_playChunk(buf) {
const ctx = this.audioCtx;
if (!ctx) return;
if (ctx.state === 'suspended') {
ctx.resume().catch(() => {});
}

const samples = new Int16Array(buf);
const nFrames = Math.floor(samples.length / this.channels);


正在加载...
取消
保存