@@ -237,7 +237,7 @@ <h1>语音识别与合成测试</h1>
237237 window . AudioContext = window . AudioContext || window . webkitAudioContext ;
238238 audioContext = new AudioContext ( ) ;
239239 } catch ( e ) {
240- log . error ( "无法创建音频上下文:" , e ) ;
240+ console . error ( "无法创建音频上下文:" , e ) ;
241241 updateStatus ( '浏览器不支持AudioContext' , true , 'stt' ) ;
242242 disableButtons ( ) ;
243243 return ;
@@ -273,7 +273,7 @@ <h1>语音识别与合成测试</h1>
273273 sampleRate : 16000 // 强制使用16kHz采样率
274274 } ) ;
275275
276- log . log ( `音频上下文创建成功,采样率: ${ audioContext . sampleRate } Hz` ) ;
276+ console . log ( `音频上下文创建成功,采样率: ${ audioContext . sampleRate } Hz` ) ;
277277 } catch ( error ) {
278278 updateStatus ( `无法访问麦克风: ${ error . message } ` , true , 'stt' ) ;
279279 disableButtons ( ) ;
@@ -308,7 +308,7 @@ <h1>语音识别与合成测试</h1>
308308 sampleRate : 16000 // 强制使用16kHz采样率
309309 } ) ;
310310
311- log . log ( `音频上下文创建成功,采样率: ${ audioContext . sampleRate } Hz` ) ;
311+ console . log ( `音频上下文创建成功,采样率: ${ audioContext . sampleRate } Hz` ) ;
312312 updateStatus ( '麦克风权限已获取,连接服务器...' , false , 'stt' ) ;
313313 } catch ( error ) {
314314 updateStatus ( `无法访问麦克风: ${ error . message } ` , true , 'stt' ) ;
@@ -334,14 +334,14 @@ <h1>语音识别与合成测试</h1>
334334
335335 websocket . onmessage = function ( event ) {
336336 const data = JSON . parse ( event . data ) ;
337- log . log ( "Received data:" , data ) ;
337+ console . log ( "Received data:" , data ) ;
338338
339339 if ( data . status === 'ready' ) {
340340 // 服务器准备就绪后启动录音
341341 startMediaRecorder ( audioStream ) ;
342342 } else if ( data . status === 'processing' ) {
343343 // 处理中状态,不需要显示任何内容
344- log . log ( "Processing status received" ) ;
344+ console . log ( "Processing status received" ) ;
345345 } else if ( data . error ) {
346346 updateStatus ( `错误: ${ data . error } ` , true , 'stt' ) ;
347347 stopRecording ( ) ;
@@ -357,7 +357,7 @@ <h1>语音识别与合成测试</h1>
357357 }
358358 } else if ( data . trans_result ) {
359359 // 新格式处理
360- log . log ( "Recognition result:" , data ) ;
360+ console . log ( "Recognition result:" , data ) ;
361361 const text = data . trans_result . text || '' ;
362362 if ( text && text . trim ( ) !== '' ) {
363363 appendResult ( text , data . is_final || false ) ;
@@ -370,15 +370,15 @@ <h1>语音识别与合成测试</h1>
370370 }
371371 } else {
372372 // 未知格式,记录但不显示空结果
373- log . log ( "Received unrecognized data format:" , data ) ;
373+ console . log ( "Received unrecognized data format:" , data ) ;
374374 if ( JSON . stringify ( data ) !== '{}' && ! data . audio_info ) {
375375 appendResult ( JSON . stringify ( data ) , false ) ;
376376 }
377377 }
378378 } ;
379379
380380 websocket . onclose = function ( event ) {
381- log . log ( "WebSocket关闭:" , event ) ;
381+ console . log ( "WebSocket关闭:" , event ) ;
382382 if ( isRecording ) {
383383 updateStatus ( 'WebSocket连接已关闭' , false , 'stt' ) ;
384384 stopLocalRecording ( ) ;
@@ -392,7 +392,7 @@ <h1>语音识别与合成测试</h1>
392392 } ;
393393
394394 websocket . onerror = function ( error ) {
395- log . error ( "WebSocket错误:" , error ) ;
395+ console . error ( "WebSocket错误:" , error ) ;
396396 updateStatus ( `WebSocket错误,请检查服务器是否运行` , true , 'stt' ) ;
397397 stopLocalRecording ( ) ;
398398
@@ -410,7 +410,7 @@ <h1>语音识别与合成测试</h1>
410410
411411 } catch ( error ) {
412412 updateStatus ( `启动录音失败: ${ error . message } ` , true , 'stt' ) ;
413- log . error ( "启动录音错误:" , error ) ;
413+ console . error ( "启动录音错误:" , error ) ;
414414
415415 // 恢复UI状态
416416 document . getElementById ( 'startBtn' ) . disabled = false ;
@@ -444,7 +444,7 @@ <h1>语音识别与合成测试</h1>
444444 // 直接发送PCM数据到服务器
445445 if ( websocket && websocket . readyState === WebSocket . OPEN && isRecording ) {
446446 // 输出调试信息
447- log . log ( `发送PCM数据: 长度=${ pcmData . length } , 采样率=${ audioContext . sampleRate } Hz, 第一个样本值=${ pcmData [ 0 ] } ` ) ;
447+ console . log ( `发送PCM数据: 长度=${ pcmData . length } , 采样率=${ audioContext . sampleRate } Hz, 第一个样本值=${ pcmData [ 0 ] } ` ) ;
448448
449449 // 将Int16Array发送为二进制数据
450450 websocket . send ( pcmData . buffer ) ;
@@ -495,18 +495,18 @@ <h1>语音识别与合成测试</h1>
495495 if ( websocket && websocket . readyState === WebSocket . OPEN ) {
496496 try {
497497 // 发送一个空的buffer作为结束标记,服务器会将其识别为最后一个音频包
498- log . log ( "发送空的结束标记..." ) ;
498+ console . log ( "发送空的结束标记..." ) ;
499499 websocket . send ( new ArrayBuffer ( 0 ) ) ;
500500
501501 // 等待一段时间后关闭WebSocket,给服务器处理最后一个音频包的时间
502502 setTimeout ( ( ) => {
503- log . log ( "关闭WebSocket连接..." ) ;
503+ console . log ( "关闭WebSocket连接..." ) ;
504504 updateStatus ( '识别已终止' , false , 'stt' ) ;
505505 websocket . close ( 1000 , "正常关闭" ) ;
506506 websocket = null ;
507507 } , 1000 ) ;
508508 } catch ( error ) {
509- log . error ( "关闭WebSocket时出错:" , error ) ;
509+ console . error ( "关闭WebSocket时出错:" , error ) ;
510510 websocket = null ;
511511 }
512512 }
@@ -681,7 +681,7 @@ <h1>语音识别与合成测试</h1>
681681 audioPlayer . play ( ) . then ( ( ) => {
682682 updateStatus ( '正在播放...' , false , 'tts' ) ;
683683 } ) . catch ( error => {
684- log . error ( '播放失败:' , error ) ;
684+ console . error ( '播放失败:' , error ) ;
685685 updateStatus ( '播放失败' , true , 'tts' ) ;
686686 } ) ;
687687
@@ -693,19 +693,19 @@ <h1>语音识别与合成测试</h1>
693693 }
694694 // 处理错误消息
695695 else if ( data . error ) {
696- log . error ( 'TTS服务错误:' , data . error ) ;
696+ console . error ( 'TTS服务错误:' , data . error ) ;
697697 updateStatus ( `错误: ${ data . error } ` , true , 'tts' ) ;
698698
699699 // 服务器端可能有async iterator错误,提供更友好的错误信息
700700 if ( data . error . includes ( '__aiter__' ) || data . error . includes ( 'coroutine' ) ) {
701701 updateStatus ( '服务器配置错误: TTS生成器实现有问题' , true , 'tts' ) ;
702- log . error ( '服务器端async iterator实现错误,需要修复voice_service.py中generate_speech方法' ) ;
702+ console . error ( '服务器端async iterator实现错误,需要修复voice_service.py中generate_speech方法' ) ;
703703 }
704704
705705 button . disabled = false ;
706706 }
707707 } catch ( e ) {
708- log . error ( '解析消息错误:' , e ) ;
708+ console . error ( '解析消息错误:' , e ) ;
709709 }
710710 }
711711 } ;
@@ -719,13 +719,13 @@ <h1>语音识别与合成测试</h1>
719719
720720 ttsWebsocket . onerror = function ( error ) {
721721 updateStatus ( `WebSocket错误: ${ error . message || '未知错误' } ` , true , 'tts' ) ;
722- log . error ( 'TTS WebSocket错误:' , error ) ;
722+ console . error ( 'TTS WebSocket错误:' , error ) ;
723723 button . disabled = false ;
724724 } ;
725725
726726 } catch ( error ) {
727727 updateStatus ( `错误: ${ error . message } ` , true , 'tts' ) ;
728- log . error ( 'TTS错误:' , error ) ;
728+ console . error ( 'TTS错误:' , error ) ;
729729 button . disabled = false ;
730730 }
731731 }
0 commit comments