@@ -221,7 +221,7 @@ async fn send_stream_chunk(
221221 text : String ,
222222 resp : reqwest:: Response ,
223223) -> anyhow:: Result < f32 > {
224- log:: info !( "llm chunk:{:?}" , text) ;
224+ log:: debug !( "[GSV_Stream] llm chunk:{:?}" , text) ;
225225
226226 let in_hz = 16000 ;
227227 let mut stream = resp. bytes_stream ( ) ;
@@ -231,7 +231,8 @@ async fn send_stream_chunk(
231231 let mut duration_sec = 0.0 ;
232232
233233 ' next_chunk: while let Some ( item) = stream. next ( ) . await {
234- // 小端字节序
234+ // little-endian
235+ // chunk len may be not odd number
235236 let mut chunk = item?;
236237
237238 log:: trace!( "Received audio chunk of size: {}" , chunk. len( ) ) ;
@@ -631,18 +632,22 @@ async fn submit_to_ai(
631632 if chunk_. is_empty ( ) {
632633 continue ;
633634 }
634- if tx . send ( WsCommand :: StartAudio ( chunk . clone ( ) ) ) . is_ok ( ) {
635- let st = std :: time :: Instant :: now ( ) ;
636- let r = tts_and_send ( pool , tx , chunk) . await ;
637- log :: info! ( "tts took: {:?}" , st . elapsed ( ) ) ;
638- if tx . send ( WsCommand :: EndAudio ) . is_err ( ) {
639- continue ;
640- } ;
641-
642- if let Err ( e ) = r {
643- log :: error! ( "tts error:{e}" ) ;
644- }
635+
636+ tx . send ( WsCommand :: StartAudio ( chunk . clone ( ) ) ) . map_err ( |_| {
637+ anyhow :: anyhow! ( "error sending start audio ws command for chunk `{}`" , chunk)
638+ } ) ? ;
639+
640+ let st = std :: time :: Instant :: now ( ) ;
641+ let r = tts_and_send ( pool , tx , chunk . clone ( ) ) . await ;
642+ log :: info! ( "tts took: {:?}" , st . elapsed ( ) ) ;
643+
644+ if let Err ( e ) = r {
645+ log :: error! ( "tts error:{e}" ) ;
645646 } ;
647+
648+ tx. send ( WsCommand :: EndAudio ) . map_err ( |_| {
649+ anyhow:: anyhow!( "error sending end audio ws command for chunk `{}`" , chunk)
650+ } ) ?;
646651 }
647652 Ok ( StableLLMResponseChunk :: Functions ( functions) ) => {
648653 log:: info!( "llm functions: {:#?}" , functions) ;
0 commit comments