22pub struct TranscriptManager {
33 id : uuid:: Uuid ,
44 partial_words : Vec < owhisper_interface:: Word > ,
5- final_words : Vec < owhisper_interface:: Word > ,
65}
76
87#[ derive( Debug , Default , Clone ) ]
@@ -36,8 +35,6 @@ impl TranscriptManager {
3635 #[ cfg( debug_assertions) ]
3736 Self :: log ( self . id , & response) ;
3837
39- let mut diff = Diff :: default ( ) ;
40-
4138 if let owhisper_interface:: StreamResponse :: TranscriptResponse {
4239 is_final, channel, ..
4340 } = response
@@ -57,36 +54,31 @@ impl TranscriptManager {
5754 . collect :: < Vec < _ > > ( ) ;
5855
5956 if is_final {
60- self . process_final_words ( & mut diff, words) ;
57+ let last_final_word_end = words. last ( ) . unwrap ( ) . end ;
58+ let partial_words = self
59+ . partial_words
60+ . iter ( )
61+ . filter ( |w| w. start > last_final_word_end)
62+ . cloned ( )
63+ . collect :: < Vec < _ > > ( ) ;
64+
65+ return Diff {
66+ final_words : words. clone ( ) ,
67+ partial_words,
68+ } ;
6169 } else {
62- self . process_partial_words ( & mut diff, words) ;
70+ self . partial_words = words. clone ( ) ;
71+
72+ return Diff {
73+ final_words : vec ! [ ] ,
74+ partial_words : words. clone ( ) ,
75+ } ;
6376 }
6477 }
6578
66- diff
67- }
68-
69- fn process_final_words ( & mut self , diff : & mut Diff , words : & Vec < owhisper_interface:: Word > ) {
70- diff. final_words = words. clone ( ) ;
71- self . final_words . extend ( words. clone ( ) ) ;
72- self . partial_words . clear ( ) ;
79+ Diff :: default ( )
7380 }
7481
75- fn process_partial_words ( & mut self , diff : & mut Diff , words : & Vec < owhisper_interface:: Word > ) {
76- let last_final_end = self . get_last_final_end_time ( ) ;
77-
78- self . partial_words = words
79- . into_iter ( )
80- . filter ( |w| w. end > last_final_end)
81- . cloned ( )
82- . collect ( ) ;
83-
84- diff. partial_words = self . partial_words . clone ( ) ;
85- }
86-
87- fn get_last_final_end_time ( & self ) -> f64 {
88- self . final_words . last ( ) . map ( |w| w. end ) . unwrap_or ( 0.0 )
89- }
9082 fn log ( id : uuid:: Uuid , response : & owhisper_interface:: StreamResponse ) {
9183 use std:: fs:: OpenOptions ;
9284 use std:: io:: Write ;
0 commit comments