From f362b625a3b6cd28a4d2ec242bbe1186578f64f4 Mon Sep 17 00:00:00 2001 From: Kodai Aoyama Date: Sat, 19 Aug 2023 11:32:44 +0900 Subject: [PATCH 1/3] update whisper-rs to 0.5.0 --- src-tauri/Cargo.lock | 4 ++-- src-tauri/Cargo.toml | 2 +- src-tauri/src/module/transcription.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index a8ba2f6..bb4fe82 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -4654,9 +4654,9 @@ dependencies = [ [[package]] name = "whisper-rs" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "124d641b84e8aa4a1ef0a2155d4da393155099c4b7fa6ad296506272cb98d01f" +checksum = "fa7e1b9b003aa3285a0e4469219566266aa1d51ced1be38587251a4f713a1677" dependencies = [ "whisper-rs-sys", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 01c8e85..79b991b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -25,7 +25,7 @@ once_cell = "1.13.1" crossbeam-channel = "0.5.6" chrono = "0.4.22" hound = "3.4.0" -whisper-rs = "0.4.0" +whisper-rs = "0.5.0" rusqlite = "*" samplerate-rs = "0.1.0" # download model and openai request diff --git a/src-tauri/src/module/transcription.rs b/src-tauri/src/module/transcription.rs index 716c298..57da81a 100644 --- a/src-tauri/src/module/transcription.rs +++ b/src-tauri/src/module/transcription.rs @@ -103,7 +103,7 @@ impl Transcription { ), } let data = if spec.channels != 1 { - whisper_rs::convert_stereo_to_mono_audio(&data) + whisper_rs::convert_stereo_to_mono_audio(&data).unwrap() } else { data }; From 569a5138682b3709a22ae3237bf19624440dd1f0 Mon Sep 17 00:00:00 2001 From: Kodai Aoyama Date: Thu, 31 Aug 2023 23:22:37 +0900 Subject: [PATCH 2/3] support coreml on m1/m2 mac --- src-tauri/Cargo.lock | 9 +++++---- src-tauri/Cargo.toml | 4 +++- src-tauri/src/module/downloader/whisper.rs | 22 ++++++++++++++++++++-- src-tauri/src/module/transcription.rs | 12 ++++++------ 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index bb4fe82..cec426a 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -4654,20 +4654,21 @@ dependencies = [ [[package]] name = "whisper-rs" -version = "0.5.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7e1b9b003aa3285a0e4469219566266aa1d51ced1be38587251a4f713a1677" +checksum = "2c950fb18ad556b053ba615b88fd4d01ed6020be740c3371eb0fc4aec64a0639" dependencies = [ "whisper-rs-sys", ] [[package]] name = "whisper-rs-sys" -version = "0.3.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "761859cea9cd0b640f33db272747437ce4b83871741cc3e68605564b840bf39b" +checksum = "094a5bd86f6f52562bbc74c28f27cd80197e54656cfb7213cf4ba37b5246cc9e" dependencies = [ "bindgen 0.64.0", + "cfg-if", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 79b991b..5642d77 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -25,7 +25,7 @@ once_cell = "1.13.1" crossbeam-channel = "0.5.6" chrono = "0.4.22" hound = "3.4.0" -whisper-rs = "0.5.0" +whisper-rs = "0.8.0" rusqlite = "*" samplerate-rs = "0.1.0" # download model and openai request @@ -41,6 +41,8 @@ features = ["sqlite"] [dependencies.tauri-plugin-window-state] git = "https://github.com/tauri-apps/plugins-workspace" branch = "dev" +[target.'cfg(target_arch = "aarch64")'.dependencies.whisper-rs] +features = ["coreml"] [features] # by default Tauri runs in production mode diff --git a/src-tauri/src/module/downloader/whisper.rs b/src-tauri/src/module/downloader/whisper.rs index ddd8465..943846d 100644 --- a/src-tauri/src/module/downloader/whisper.rs +++ b/src-tauri/src/module/downloader/whisper.rs @@ -25,7 +25,7 @@ impl WhisperModelDownloader { #[tokio::main] pub async fn download(&self, model_type: ModelTypeWhisper) { - let model_path: &str = &format!("resources/whisper/ggml-{}.bin", model_type.as_str()); + let model_path: &str = &format!("resources/whisper/ggml-{}.zip", model_type.as_str()); let path: &str = &self .app_handle .path_resolver() @@ -34,7 +34,7 @@ impl WhisperModelDownloader { .to_string_lossy() .to_string(); let url: &str = &format!( - "https://object-storage.tyo1.conoha.io/v1/nc_b22de95e3cf1434da07499038766e2b7/lycoris/ggml-{}.bin", + "https://object-storage.tyo1.conoha.io/v1/nc_b22de95e3cf1434da07499038766e2b7/lycoris/ggml-{}.zip", model_type.as_str() ); let res = reqwest::get(url).await.unwrap(); @@ -91,6 +91,24 @@ impl WhisperModelDownloader { } } + let dir: &str = &self + .app_handle + .path_resolver() + .resolve_resource("resources/whisper") + .unwrap() + .to_string_lossy() + .to_string(); + let _ = std::process::Command::new("sh") + .arg("-c") + .arg(format!("unzip {} -d {}", path, dir)) + .output() + .expect("failed"); + let _ = std::process::Command::new("sh") + .arg("-c") + .arg(format!("rm {}", path)) + .output() + .expect("failed"); + let _ = Sqlite::new().update_model_is_downloaded(model_type.as_str().to_string(), 1); let _ = &self.app_handle.emit_all( diff --git a/src-tauri/src/module/transcription.rs b/src-tauri/src/module/transcription.rs index 57da81a..6d6c06a 100644 --- a/src-tauri/src/module/transcription.rs +++ b/src-tauri/src/module/transcription.rs @@ -116,9 +116,8 @@ impl Transcription { ) .unwrap(); - // let mut ctx = Transcriber::build(self.app_handle.clone()); - // let mut ctx = self.ctx; - let result = self.ctx.full( + let mut state = self.ctx.create_state().expect("failed to create state"); + let result = state.full( Transcriber::build_params( self.speaker_language.clone(), self.transcription_accuracy.clone(), @@ -126,11 +125,12 @@ impl Transcription { &audio_data[..], ); if result.is_ok() { - let num_segments = self.ctx.full_n_segments(); + let num_segments = state + .full_n_segments() + .expect("failed to get number of segments"); let mut converted: Vec = vec!["".to_string()]; for i in 0..num_segments { - let segment = self - .ctx + let segment = state .full_get_segment_text(i) .expect("failed to get segment"); converted.push(segment.to_string()); From 31b6868082a729d9effb121e4b911f3f4e4d66fd Mon Sep 17 00:00:00 2001 From: Kodai Aoyama Date: Thu, 31 Aug 2023 23:23:08 +0900 Subject: [PATCH 3/3] update to 0.9.4 --- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index d6933a0..eca167e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "lycoris", "private": true, - "version": "0.9.3", + "version": "0.9.4", "type": "module", "license": "MIT", "engines": { diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index cec426a..e213e8c 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2004,7 +2004,7 @@ dependencies = [ [[package]] name = "lycoris" -version = "0.9.3" +version = "0.9.4" dependencies = [ "chrono", "cpal", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 5642d77..582074e 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lycoris" -version = "0.9.3" +version = "0.9.4" description = "Lycoris is an offline voice memo" authors = ["solaoi"] license = "MIT" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 47f2f4e..4c8d701 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "Lycoris", - "version": "0.9.3" + "version": "0.9.4" }, "tauri": { "allowlist": {