app添加工作经历开发

This commit is contained in:
冯辉
2025-10-13 16:01:49 +08:00
parent 3d7cb0c561
commit 3d2c26650c
12 changed files with 840 additions and 74 deletions

View File

@@ -370,7 +370,57 @@ const sendMessage = (text) => {
filesList.value = [];
useChatGroupDBStore()
.getStearm(values, normalArr, scrollToBottom, {
onComplete: () => console.log('Display complete'),
onDataReceived: (data, message, index) => {
// 流式朗读:只在内容足够长且包含完整信息时才开始朗读
if (!message.self && message.displayText && message.displayText.trim()) {
// 检查是否已经开始朗读这条消息
if (speechIndex.value !== index) {
// 延迟TTS等待内容更完整
// 只有在内容长度超过50个字符或者包含岗位信息时才开始朗读
const hasJobInfo = message.displayText.includes('```job-json') ||
message.displayText.includes('岗位') ||
message.displayText.includes('公司') ||
message.displayText.includes('薪资');
if (message.displayText.length > 50 || hasJobInfo) {
console.log('🎵 Starting streaming TTS for message index:', index);
console.log('📝 Current text length:', message.displayText.length);
console.log('📝 Has job info:', hasJobInfo);
// 开始朗读当前消息
speechIndex.value = index;
readMarkdown(message.displayText, index);
} else {
console.log('⏳ Waiting for more content before TTS, current length:', message.displayText.length);
}
}
}
},
onComplete: () => {
console.log('🎯 onComplete callback triggered');
console.log('📊 Messages array length:', messages.value.length);
// 确保最后一条AI消息的朗读完成
const lastMessageIndex = messages.value.length - 1;
if (lastMessageIndex >= 0) {
const lastMessage = messages.value[lastMessageIndex];
if (!lastMessage.self && lastMessage.displayText && lastMessage.displayText.trim()) {
console.log('🎵 Final TTS for complete message');
console.log('📝 Final text length:', lastMessage.displayText.length);
console.log('📝 Final text preview:', lastMessage.displayText.substring(0, 100) + '...');
// 停止当前的朗读(如果有的话)
if (isSpeaking.value) {
console.log('🛑 Stopping current TTS to start final complete TTS');
cancelAudio();
}
// 开始朗读完整的内容
speechIndex.value = lastMessageIndex;
readMarkdown(lastMessage.displayText, lastMessageIndex);
}
}
},
})
.then(() => {
getGuess();
@@ -620,21 +670,71 @@ function confirmFeeBack(value) {
});
}
// 防抖定时器
let ttsDebounceTimer = null;
function readMarkdown(value, index) {
speechIndex.value = index;
if (speechIndex.value !== index) {
console.log('🎤 readMarkdown called');
console.log('📝 Text to speak:', value ? value.substring(0, 100) + '...' : 'No text');
console.log('🔢 Index:', index);
console.log('🔢 Current speechIndex:', speechIndex.value);
console.log('⏸️ Is paused:', isPaused.value);
console.log('🔊 Is speaking:', isSpeaking.value);
// 清除之前的防抖定时器
if (ttsDebounceTimer) {
clearTimeout(ttsDebounceTimer);
}
// 如果当前正在播放其他消息,先停止
if (speechIndex.value !== index && speechIndex.value !== 0) {
console.log('🛑 Stopping current speech and starting new one');
speechIndex.value = index;
speak(value);
return;
}
if (isPaused.value) {
speechIndex.value = index;
// 如果当前正在播放且暂停了,直接恢复
if (isPaused.value && isSpeaking.value) {
console.log('▶️ Resuming paused speech');
resume();
} else {
speak(value);
return;
}
// 如果当前正在播放且没有暂停,不需要重新开始
if (isSpeaking.value && !isPaused.value) {
console.log('🔊 Already speaking, no need to restart');
return;
}
// 使用防抖避免频繁调用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);
}
}, 300); // 300ms防抖延迟
}
function stopMarkdown(value, index) {
pause(value);
console.log('⏸️ stopMarkdown called for index:', index);
console.log('🔢 Current speechIndex:', speechIndex.value);
console.log('🔊 Is speaking:', isSpeaking.value);
console.log('⏸️ Is paused:', isPaused.value);
// 清除防抖定时器
if (ttsDebounceTimer) {
clearTimeout(ttsDebounceTimer);
ttsDebounceTimer = null;
}
speechIndex.value = index;
pause();
}
function refreshMarkdown(index) {
if (isTyping.value) {