Merge pull request 'fix: 修复新旧 TTS 语音重叠播放的问题' (#61) from fix-redio into develop
Reviewed-on: http://8.161.227.145:3000/XEngineers/CamTalk/pulls/61
This commit was merged in pull request #61.
This commit is contained in:
@@ -158,6 +158,10 @@ export function useVisionSession() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 停止上一轮的 TTS 播放,防止新旧音频重叠
|
||||
ttsPlayerRef.current?.stop();
|
||||
setIsAudioPlaying(false);
|
||||
|
||||
const frame = captureFrame();
|
||||
if (!frame) {
|
||||
console.warn("[Session] 无法捕获图像帧");
|
||||
|
||||
@@ -47,6 +47,19 @@ export class TTSPlayer {
|
||||
this._isPlaying = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止当前正在播放的音频(不清空 chunks)
|
||||
* 用于 play() 开始前,防止新旧音频重叠
|
||||
*/
|
||||
private stopCurrentAudio(): void {
|
||||
if (this.audio) {
|
||||
this.audio.pause();
|
||||
this.audio.removeAttribute("src");
|
||||
this.audio = null;
|
||||
}
|
||||
this._isPlaying = false;
|
||||
}
|
||||
|
||||
/** 暂停播放 */
|
||||
pause(): void {
|
||||
this.audio?.pause();
|
||||
@@ -61,6 +74,9 @@ export class TTSPlayer {
|
||||
private play(mimeType: string): void {
|
||||
if (this.chunks.length === 0) return;
|
||||
|
||||
// 停止当前正在播放的音频,防止重叠
|
||||
this.stopCurrentAudio();
|
||||
|
||||
// 拼接所有 Base64 片段
|
||||
const combined = this.chunks.join("");
|
||||
this.chunks = [];
|
||||
|
||||
Reference in New Issue
Block a user