feat : tts 和 asr 重构暂存

This commit is contained in:
2025-12-26 16:44:11 +08:00
parent 29615c394a
commit 2c5ff4220a
5 changed files with 1677 additions and 20 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -20,8 +20,8 @@
>
{{ item }}
</view>
<view class="chat-item self" v-if="isRecording">
<view class="message">{{ recognizedText }} {{ lastFinalText }}</view>
<view class="chat-item self" v-if="isRecording || isProcessing">
<view class="message">{{ recognizedText || (isProcessing ? '正在识别语音...' : '正在录音 '+recordingDuration+'s') }}</view>
</view>
</view>
<scroll-view class="chat-list scrollView" :scroll-top="scrollTop" :scroll-y="true" scroll-with-animation>
@@ -118,9 +118,8 @@
</view>
</view>
</view>
<view class="chat-item self" v-if="isRecording">
<!-- <view class="message">{{ recognizedText }} {{ lastFinalText }}</view> -->
<view class="message">{{ recognizedText }}</view>
<view class="chat-item self" v-if="isRecording || isProcessing">
<view class="message">{{ recognizedText || (isProcessing ? '正在识别语音...' : '正在录音 '+recordingDuration+'s') }}</view>
</view>
<view v-if="isTyping" class="self">
<text class="message msg-loading">
@@ -275,7 +274,7 @@ import AudioWave from './AudioWave.vue';
import WaveDisplay from './WaveDisplay.vue';
import useScreenStore from '@/stores/useScreenStore'
const screenStore = useScreenStore();
import { useAudioRecorder } from '@/hook/useRealtimeRecorder.js';
import { useRealtimeRecorderOnce } from '@/hook/useRealtimeRecorderOnce.js';
import { useAudioSpeak } from '@/hook/useAudioSpeak.js';
// 全局
const { $api, navTo, throttle } = inject('globalFunction');
@@ -290,14 +289,24 @@ import { FileValidator } from '@/utils/fileValidator.js'; //文件校验
// 语音识别
const {
isRecording,
isProcessing,
startRecording,
stopRecording,
cancelRecording,
audioDataForDisplay,
volumeLevel,
recognizedText,
lastFinalText,
} = useAudioRecorder();
recordingDuration
} = useRealtimeRecorderOnce();
watch(recognizedText, (newText) => {
if (newText && newText.trim() && !isProcessing.value) {
setTimeout(() => {
sendMessage(newText);
}, 300);
}
});
// 语音合成
const { speak, pause, resume, isSpeaking, isPaused, isLoading, cancelAudio,cleanup } = useAudioSpeak();
@@ -382,6 +391,8 @@ function showControll(index) {
return true;
}
const sendMessage = (text) => {
const values = textInput.value || text;
showfile.value = false;
@@ -660,19 +671,12 @@ const handleTouchMove = (e) => {
}
};
const handleTouchEnd = () => {
const handleTouchEnd = async () => {
if (status.value === 'cancel') {
console.log('取消发送');
cancelRecording();
} else {
stopRecording();
if (isAudioPermission.value) {
if (recognizedText.value) {
sendMessage(recognizedText.value);
} else {
$api.msg('说话时长太短');
}
}
await stopRecording();
}
status.value = 'idle';
};