@@ -173,6 +173,8 @@ impl Track for TtsTrack {
173173 let synthesize_done = Arc :: new ( AtomicBool :: new ( false ) ) ;
174174 let synthesize_done_clone = synthesize_done. clone ( ) ;
175175 let session_id = self . session_id . clone ( ) ;
176+ let current_text = Arc :: new ( Mutex :: new ( None ) ) ;
177+ let current_text_clone = current_text. clone ( ) ;
176178 let subtitles = Arc :: new ( Mutex :: new ( Vec :: < TTSSubtitle > :: new ( ) ) ) ;
177179 let subtitles_clone = subtitles. clone ( ) ;
178180 let total_audio_len = Arc :: new ( AtomicUsize :: new ( 0 ) ) ;
@@ -181,6 +183,10 @@ impl Track for TtsTrack {
181183 let mut last_play_id = None ;
182184 while let Some ( command) = command_rx. recv ( ) . await {
183185 let text = command. text ;
186+ {
187+ let mut current_text = current_text_clone. lock ( ) . await ;
188+ * current_text = Some ( text. clone ( ) ) ;
189+ }
184190 let play_id = command. play_id ;
185191 let mut option = command. option ;
186192 if option. speaker . is_none ( ) {
@@ -230,7 +236,6 @@ impl Track for TtsTrack {
230236 let duration = bytes_size_to_duration ( audio. len ( ) , sample_rate) ;
231237 total_audio_len_clone. store ( audio. len ( ) , Ordering :: Relaxed ) ;
232238 subtitles. push ( TTSSubtitle :: new (
233- & text,
234239 0 ,
235240 duration,
236241 0 ,
@@ -438,26 +443,26 @@ impl Track for TtsTrack {
438443 let remaining_size = buffer. lock( ) . await . len( ) * 2 ;
439444 debug!( session_id, "total_size: {} remaining_size: {}" , total_size, remaining_size) ;
440445 let sended_size = total_size - remaining_size;
441- let mut text = "" . into ( ) ;
442- let mut position = 0 ;
443- let mut current = bytes_size_to_duration( sended_size, sample_rate) ;
444- let total_duration = bytes_size_to_duration( total_size, sample_rate) ;
446+ let text = current_text . lock ( ) . await . take ( ) ;
447+ let mut position = None ;
448+ let current = bytes_size_to_duration( sended_size, sample_rate) ;
449+ let total_duration = bytes_size_to_duration( total_size, sample_rate) ;
445450 let subtitles = subtitles. lock( ) . await ;
446- debug!( "subtitles: {:?}" , subtitles) ;
447451 for subtitle in subtitles. iter( ) . rev( ) {
448452 if subtitle. begin_time <= current {
449- text = subtitle. text. clone( ) ;
450- position = subtitle. begin_index;
451- current = subtitle. begin_time;
453+ position = Some ( subtitle. begin_index) ;
452454 break ;
453455 }
454456 }
455- let _ = event_sender_clone. send( SessionEvent :: OnInterrupt {
457+ let event = SessionEvent :: Interruption {
458+ track_id: track_id. clone( ) ,
459+ timestamp: crate :: get_timestamp( ) ,
456460 subtitle: text,
457461 position,
458462 total_duration,
459463 current,
460- } ) ;
464+ } ;
465+ let _ = event_sender_clone. send( event) ;
461466 }
462467 }
463468 event_sender_clone
0 commit comments