fix: 修复自动播放时机问题,audioBtnId作用域修复
This commit is contained in:
BIN
logs/server.log
BIN
logs/server.log
Binary file not shown.
@@ -879,6 +879,8 @@
|
||||
const msg = document.createElement('div');
|
||||
msg.className = `message ${role}`;
|
||||
|
||||
let audioBtnId = ''; // 在函数顶部声明
|
||||
|
||||
if (role === 'user' && content instanceof Blob) {
|
||||
const audioUrl = URL.createObjectURL(content);
|
||||
msg.innerHTML = `
|
||||
@@ -892,7 +894,6 @@
|
||||
`;
|
||||
} else if (role === 'assistant') {
|
||||
let audioHtml = '';
|
||||
let audioBtnId = '';
|
||||
if (audioData) {
|
||||
audioBtnId = `audioBtn_${Date.now()}`;
|
||||
audioHtml = `<button class="play-btn tts-play-btn" id="${audioBtnId}" onclick="playAudio('${audioData}', this)">
|
||||
@@ -904,9 +905,15 @@
|
||||
<div class="role">AI</div>
|
||||
<div class="content">${content}${audioHtml}</div>
|
||||
`;
|
||||
} else {
|
||||
msg.innerHTML = `<div class="role">我</div><div class="content">${content}</div>`;
|
||||
}
|
||||
|
||||
// 自动播放(如果开启)
|
||||
if (audioData && autoPlay) {
|
||||
chatSection.appendChild(msg);
|
||||
chatSection.scrollTop = chatSection.scrollHeight;
|
||||
|
||||
// 自动播放(在元素添加到DOM后)
|
||||
if (role === 'assistant' && audioData && autoPlay && audioBtnId) {
|
||||
setTimeout(() => {
|
||||
const btn = document.getElementById(audioBtnId);
|
||||
if (btn) {
|
||||
@@ -914,12 +921,6 @@
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
} else {
|
||||
msg.innerHTML = `<div class="role">我</div><div class="content">${content}</div>`;
|
||||
}
|
||||
|
||||
chatSection.appendChild(msg);
|
||||
chatSection.scrollTop = chatSection.scrollHeight;
|
||||
}
|
||||
|
||||
// 播放音频
|
||||
|
||||
Reference in New Issue
Block a user