流式数据请求优化。
This commit is contained in:
@@ -479,11 +479,16 @@ const sendMessage = (text) => {
|
||||
console.log('📝 Has job info:', hasJobInfo);
|
||||
|
||||
// 开始朗读当前消息
|
||||
speechIndex.value = index;
|
||||
readMarkdown(message.displayText, index);
|
||||
speechIndex.value = index;
|
||||
readMarkdown(message.displayText, index, { immediate: false });
|
||||
// 一旦开始朗读,就设置speechIndex,避免重复调用
|
||||
speechIndex.value = index;
|
||||
} else {
|
||||
console.log('⏳ Waiting for more content before TTS, current length:', message.displayText.length);
|
||||
}
|
||||
} else {
|
||||
// 已经开始朗读这条消息,不再重复调用
|
||||
console.log('⏭️ Already speaking this message, skipping duplicate TTS call');
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -508,7 +513,7 @@ const sendMessage = (text) => {
|
||||
|
||||
// 开始朗读完整的内容
|
||||
speechIndex.value = lastMessageIndex;
|
||||
readMarkdown(lastMessage.displayText, lastMessageIndex);
|
||||
readMarkdown(lastMessage.displayText, lastMessageIndex, { immediate: true });
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -781,7 +786,10 @@ function confirmFeeBack(value) {
|
||||
// 防抖定时器
|
||||
let ttsDebounceTimer = null;
|
||||
|
||||
function readMarkdown(value, index) {
|
||||
// 保存上一次调用的文本内容,避免重复调用TTS
|
||||
let lastSpeechText = '';
|
||||
|
||||
function readMarkdown(value, index, options = {}) {
|
||||
console.log('🎤 readMarkdown called');
|
||||
console.log('📝 Text to speak:', value ? value.substring(0, 100) + '...' : 'No text');
|
||||
console.log('🔢 Index:', index);
|
||||
@@ -798,17 +806,33 @@ function readMarkdown(value, index) {
|
||||
console.log('🛑 Always stopping current speech before starting new one');
|
||||
speechIndex.value = index;
|
||||
|
||||
// 使用防抖,避免频繁调用TTS
|
||||
ttsDebounceTimer = setTimeout(() => {
|
||||
console.log('🎵 Starting new speech');
|
||||
console.log('🎵 Calling speak function with text length:', value ? value.length : 0);
|
||||
try {
|
||||
speak(value);
|
||||
console.log('✅ Speak function called successfully');
|
||||
} catch (error) {
|
||||
console.error('❌ Error calling speak function:', error);
|
||||
// 立即调用speak,不使用防抖延迟
|
||||
const speakNow = () => {
|
||||
// 检查文本内容是否发生变化,避免重复调用TTS
|
||||
if (value !== lastSpeechText) {
|
||||
console.log('🎵 Starting new speech');
|
||||
console.log('🎵 Calling speak function with text length:', value ? value.length : 0);
|
||||
try {
|
||||
speak(value);
|
||||
console.log('✅ Speak function called successfully');
|
||||
// 更新上一次调用的文本内容
|
||||
lastSpeechText = value;
|
||||
} catch (error) {
|
||||
console.error('❌ Error calling speak function:', error);
|
||||
}
|
||||
} else {
|
||||
console.log('🔄 Same text as last speech, skipping duplicate TTS call');
|
||||
}
|
||||
}, 300); // 300ms防抖延迟
|
||||
};
|
||||
|
||||
// 改进防抖逻辑,确保在短时间内只调用一次
|
||||
if (options.immediate) {
|
||||
// 如果是onComplete回调,立即播放
|
||||
speakNow();
|
||||
} else {
|
||||
// 对于流式数据,总是使用防抖,避免频繁调用
|
||||
ttsDebounceTimer = setTimeout(speakNow, 500); // 延长防抖时间到500ms
|
||||
}
|
||||
}
|
||||
function stopMarkdown(value, index) {
|
||||
console.log('⏸️ stopMarkdown called for index:', index);
|
||||
|
||||
Reference in New Issue
Block a user