bugfic
This commit is contained in:
parent
63564940dc
commit
999c9ba93e
@ -323,53 +323,6 @@ bricks.SttClient = class extends bricks.VBox {
|
||||
}
|
||||
}
|
||||
|
||||
bricks.ContinueAudioPlayer = class extends bricks.AudioPlayer {
|
||||
constructor(opts){
|
||||
this.options = opts
|
||||
this.audioContext = null;
|
||||
this.nextStartTime = 0;
|
||||
this.started = false;
|
||||
this.initAudioContext(); // 初始化音频上下文
|
||||
}
|
||||
initAudioContext() {
|
||||
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
||||
this.nextStartTime = this.audioContext.currentTime;
|
||||
this.started = true;
|
||||
}
|
||||
handleAudioTrack(arrayBuffer) {
|
||||
this.audioContext.decodeAudioData(arrayBuffer).then(decodedBuffer => {
|
||||
const source = this.audioContext.createBufferSource();
|
||||
source.buffer = decodedBuffer;
|
||||
source.connect(this.audioContext.destination);
|
||||
|
||||
// 连续播放安排
|
||||
const startTime = Math.max(this.audioContext.currentTime, this.nextStartTime);
|
||||
source.start(startTime);
|
||||
|
||||
this.nextStartTime = startTime + decodedBuffer.duration;
|
||||
}).catch(err => {
|
||||
console.error("Error decoding audio data:", err);
|
||||
});
|
||||
}
|
||||
pauseAudio() {
|
||||
if (this.audioContext && this.audioContext.state === 'running') {
|
||||
this.audioContext.suspend().then(() => {
|
||||
console.log("Audio playback paused.");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ▶️ 恢复音频播放(继续 AudioContext)
|
||||
*/
|
||||
resumeAudio() {
|
||||
if (this.audioContext && this.audioContext.state === 'suspended') {
|
||||
this.audioContext.resume().then(() => {
|
||||
console.log("Audio playback resumed.");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
bricks.Factory.register('AudioPlayer', bricks.AudioPlayer);
|
||||
bricks.Factory.register('AudioRecorder', bricks.AudioRecorder);
|
||||
bricks.Factory.register('SttClient', bricks.SttClient);
|
||||
|
Loading…
Reference in New Issue
Block a user