`media_data` accept media in any format
(&self, window: &Window, media_data: Vec<u8>, general_config: super::configuration::GeneralConfig, smtp_config: super::configuration::SMTPConfig, save_to: PathBuf, email: bool)
| 407 | |
| 408 | /// `media_data` accept media in any format |
| 409 | pub fn transcribe(&self, window: &Window, media_data: Vec<u8>, general_config: super::configuration::GeneralConfig, smtp_config: super::configuration::SMTPConfig, save_to: PathBuf, email: bool) { |
| 410 | println!("Using model {:?}", self.model); |
| 411 | |
| 412 | if !self.model.is_downloaded() { |
| 413 | panic!("Selected model is not downloaded"); |
| 414 | } |
| 415 | |
| 416 | println!("Transcribing audio"); |
| 417 | |
| 418 | let transcription_uuid = gst::glib::uuid_string_random().to_string(); |
| 419 | |
| 420 | crate::util::emit_all(window, "app://transcriber_start", transcription_uuid.clone()); |
| 421 | |
| 422 | // let mut ctx = self.ctx.lock().unwrap(); |
| 423 | // |
| 424 | // if let None = *ctx { |
| 425 | // let whisper_context = WhisperContext::new_with_params(self.model.model_path().to_str().unwrap(), WhisperContextParameters::default()).unwrap(); |
| 426 | // *ctx = Some(whisper_context) |
| 427 | // } |
| 428 | |
| 429 | // drop(ctx); |
| 430 | |
| 431 | let language = self.language.clone(); |
| 432 | |
| 433 | let w = window.clone(); |
| 434 | let whisper_context = WhisperContext::new_with_params(self.model.path().to_str().unwrap(), WhisperContextParameters::default()).unwrap(); |
| 435 | std::thread::spawn(move || { |
| 436 | let mut state = whisper_context.create_state().unwrap(); |
| 437 | |
| 438 | let mut params = FullParams::new(SamplingStrategy::Greedy { best_of: 5 }); |
| 439 | |
| 440 | params.set_language(Some(&language)); |
| 441 | params.set_translate(general_config.translate); |
| 442 | params.set_tdrz_enable(true); |
| 443 | |
| 444 | // FIXME: TRANSCRIBE-PROGRESS find out why this doesn't work. |
| 445 | // params.set_progress_callback_safe({ |
| 446 | // let w = w.clone(); |
| 447 | // |
| 448 | // move |progress: i32| { |
| 449 | // println!("Transcribing {}%", progress); |
| 450 | // util::emit_all(&w, "update-state", serde_json::json!({ |
| 451 | // "type": "transcribe-progress", |
| 452 | // "value": progress, |
| 453 | // })); |
| 454 | // } |
| 455 | // }); |
| 456 | // |
| 457 | |
| 458 | let transcription = (|| { |
| 459 | state.full(params, &decode_audio(media_data.into())?)?; |
| 460 | |
| 461 | let mut fragments = Vec::new(); |
| 462 | |
| 463 | for s in 0..state.full_n_segments()? { |
| 464 | let speaker_turn = state.full_get_segment_speaker_turn_next(s); |
| 465 | |
| 466 | let mut text = state.full_get_segment_text(s)?; |
no test coverage detected