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');
|
const msg = document.createElement('div');
|
||||||
msg.className = `message ${role}`;
|
msg.className = `message ${role}`;
|
||||||
|
|
||||||
|
let audioBtnId = ''; // 在函数顶部声明
|
||||||
|
|
||||||
if (role === 'user' && content instanceof Blob) {
|
if (role === 'user' && content instanceof Blob) {
|
||||||
const audioUrl = URL.createObjectURL(content);
|
const audioUrl = URL.createObjectURL(content);
|
||||||
msg.innerHTML = `
|
msg.innerHTML = `
|
||||||
@@ -892,7 +894,6 @@
|
|||||||
`;
|
`;
|
||||||
} else if (role === 'assistant') {
|
} else if (role === 'assistant') {
|
||||||
let audioHtml = '';
|
let audioHtml = '';
|
||||||
let audioBtnId = '';
|
|
||||||
if (audioData) {
|
if (audioData) {
|
||||||
audioBtnId = `audioBtn_${Date.now()}`;
|
audioBtnId = `audioBtn_${Date.now()}`;
|
||||||
audioHtml = `<button class="play-btn tts-play-btn" id="${audioBtnId}" onclick="playAudio('${audioData}', this)">
|
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="role">AI</div>
|
||||||
<div class="content">${content}${audioHtml}</div>
|
<div class="content">${content}${audioHtml}</div>
|
||||||
`;
|
`;
|
||||||
|
} else {
|
||||||
|
msg.innerHTML = `<div class="role">我</div><div class="content">${content}</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
// 自动播放(如果开启)
|
chatSection.appendChild(msg);
|
||||||
if (audioData && autoPlay) {
|
chatSection.scrollTop = chatSection.scrollHeight;
|
||||||
|
|
||||||
|
// 自动播放(在元素添加到DOM后)
|
||||||
|
if (role === 'assistant' && audioData && autoPlay && audioBtnId) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const btn = document.getElementById(audioBtnId);
|
const btn = document.getElementById(audioBtnId);
|
||||||
if (btn) {
|
if (btn) {
|
||||||
@@ -914,12 +921,6 @@
|
|||||||
}
|
}
|
||||||
}, 100);
|
}, 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