@@ -88,7 +88,9 @@ pub fn cancel_recording(
8888 app : tauri:: AppHandle ,
8989) -> Result < ( ) , String > {
9090 let is_recording = app. state :: < crate :: IsRecording > ( ) ;
91+ let is_transcribing = app. state :: < crate :: IsTranscribing > ( ) ;
9192 is_recording. 0 . store ( false , Ordering :: Relaxed ) ;
93+ is_transcribing. 0 . store ( false , Ordering :: Relaxed ) ;
9294
9395 let mut guard = state. 0 . lock ( ) . map_err ( |e| e. to_string ( ) ) ?;
9496 * guard = None ;
@@ -102,35 +104,42 @@ pub fn stop_and_transcribe(
102104 app : tauri:: AppHandle ,
103105) -> Result < String , String > {
104106 let is_recording = app. state :: < crate :: IsRecording > ( ) ;
107+ let is_transcribing = app. state :: < crate :: IsTranscribing > ( ) ;
105108 is_recording. 0 . store ( false , Ordering :: Relaxed ) ;
109+ is_transcribing. 0 . store ( true , Ordering :: Relaxed ) ;
110+
111+ let result = ( || {
112+ let mut recorder = {
113+ let mut guard = recorder_state. 0 . lock ( ) . map_err ( |e| e. to_string ( ) ) ?;
114+ guard
115+ . take ( )
116+ . ok_or_else ( || "No active recording" . to_string ( ) ) ?
117+ } ;
118+ let audio = recorder. stop ( ) ?;
119+
120+ if audio. is_empty ( ) {
121+ return Err ( "No audio captured" . to_string ( ) ) ;
122+ }
106123
107- let mut recorder = {
108- let mut guard = recorder_state. 0 . lock ( ) . map_err ( |e| e. to_string ( ) ) ?;
109- guard
110- . take ( )
111- . ok_or_else ( || "No active recording" . to_string ( ) ) ?
112- } ;
113- let audio = recorder. stop ( ) ?;
114-
115- if audio. is_empty ( ) {
116- return Err ( "No audio captured" . to_string ( ) ) ;
117- }
118-
119- let guard = transcriber_state. 0 . lock ( ) . map_err ( |e| e. to_string ( ) ) ?;
120- let transcriber = guard. as_ref ( ) . ok_or ( "No whisper model loaded" ) ?;
124+ let guard = transcriber_state. 0 . lock ( ) . map_err ( |e| e. to_string ( ) ) ?;
125+ let transcriber = guard. as_ref ( ) . ok_or ( "No whisper model loaded" ) ?;
121126
122- let _ = app. emit ( "transcription-started" , ( ) ) ;
127+ let _ = app. emit ( "transcription-started" , ( ) ) ;
123128
124- match transcriber. transcribe ( & audio) {
125- Ok ( text) => {
126- let _ = app. emit ( "transcription-complete" , text. clone ( ) ) ;
127- Ok ( text)
128- }
129- Err ( e) => {
130- let _ = app. emit ( "transcription-error" , e. clone ( ) ) ;
131- Err ( e)
129+ match transcriber. transcribe ( & audio) {
130+ Ok ( text) => {
131+ let _ = app. emit ( "transcription-complete" , text. clone ( ) ) ;
132+ Ok ( text)
133+ }
134+ Err ( e) => {
135+ let _ = app. emit ( "transcription-error" , e. clone ( ) ) ;
136+ Err ( e)
137+ }
132138 }
133- }
139+ } ) ( ) ;
140+
141+ is_transcribing. 0 . store ( false , Ordering :: Relaxed ) ;
142+ result
134143}
135144
136145#[ tauri:: command]
0 commit comments