flat: 优化语音

This commit is contained in:
史典卓
2025-04-16 14:24:06 +08:00
parent 0d2b8ae65f
commit 446b48ef6d
28 changed files with 1059 additions and 264 deletions

View File

@@ -31,8 +31,8 @@ export function useAudioRecorder(wsUrl) {
// 配置常量
const SAMPLE_RATE = 16000;
const SILENCE_THRESHOLD = 0.02; // 静音阈值 (0-1)
const SILENCE_DURATION = 400; // 静音持续时间(ms)后切片
const MIN_SOUND_DURATION = 300; // 最小有效声音持续时间(ms)
const SILENCE_DURATION = 100; // 静音持续时间(ms)后切片
const MIN_SOUND_DURATION = 200; // 最小有效声音持续时间(ms)
// 音频处理变量
const lastSoundTime = ref(0);
@@ -125,6 +125,7 @@ export function useAudioRecorder(wsUrl) {
socket.value = new WebSocket(wsUrl);
socket.value.onopen = () => {
console.log('open')
isSocketConnected.value = true;
resolve();
};
@@ -191,7 +192,6 @@ export function useAudioRecorder(wsUrl) {
if (audioChunks.value.length === 0 || !socket.value || socket.value.readyState !== WebSocket.OPEN) {
return;
}
try {
// 合并所有块
const totalBytes = audioChunks.value.reduce((total, chunk) => total + chunk.byteLength, 0);