Skip to content

Commit

Permalink
Merge pull request #60 from solaoi/main
Browse files Browse the repository at this point in the history
add online support
  • Loading branch information
solaoi authored Apr 5, 2023
2 parents 7cde3f3 + ca0a78b commit 198ab0e
Show file tree
Hide file tree
Showing 21 changed files with 395 additions and 69 deletions.
20 changes: 20 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ hound = "3.4.0"
whisper-rs = "0.4.0"
rusqlite = "*"
samplerate-rs = "0.1.0"
# download model
reqwest = { version = "0.11", features = ["stream"] }
# download model and openai request
reqwest = { version = "0.11", features = ["stream", "multipart", "json"] }
tokio = { version = "1", features = ["full"] }
futures-util = "0.3.26"
# serve audio
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/migrations/001.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ CREATE TABLE settings (
);
INSERT INTO settings(setting_name, setting_status) VALUES("speakerLanguage", NULL);
INSERT INTO settings(setting_name, setting_status) VALUES("transcriptionAccuracy", "off");
INSERT INTO settings(setting_name, setting_status) VALUES("settingKey", "");
INSERT INTO settings(setting_name, setting_status) VALUES("settingLanguage", "日本語");
CREATE TABLE models (
id INTEGER PRIMARY KEY AUTOINCREMENT,
model_name TEXT,
Expand Down
30 changes: 18 additions & 12 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ fn start_command(
let mut lock = state.0.lock().unwrap();
let (stop_record_tx, stop_record_rx) = unbounded();
*lock = Some(stop_record_tx);

std::thread::spawn(move || {
let record = module::record::Record::new(window.app_handle().clone());
record.start(
Expand Down Expand Up @@ -107,13 +106,23 @@ fn start_trace_command(
*lock = Some(stop_convert_tx);

std::thread::spawn(move || {
let mut transcription = module::transcription::Transcription::new(
window.app_handle(),
transcription_accuracy,
speaker_language,
note_id,
);
transcription.start(stop_convert_rx, true);
if transcription_accuracy.starts_with("online") {
let mut transcription_online = module::transcription_online::TranscriptionOnline::new(
window.app_handle(),
transcription_accuracy,
speaker_language,
note_id,
);
transcription_online.start(stop_convert_rx, true);
} else {
let mut transcription = module::transcription::Transcription::new(
window.app_handle(),
transcription_accuracy,
speaker_language,
note_id,
);
transcription.start(stop_convert_rx, true);
}
});
}

Expand All @@ -124,10 +133,7 @@ fn stop_trace_command(state: State<'_, RecordState>, window: tauri::Window) {
stop_convert_tx.send(()).unwrap_or_else(|_| {
window
.app_handle()
.emit_all(
"traceCompletion",
TraceCompletion {},
)
.emit_all("traceCompletion", TraceCompletion {})
.unwrap();
})
}
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ pub mod record;
mod sqlite;
mod transcriber;
pub mod transcription;
pub mod transcription_online;
mod writer;
30 changes: 20 additions & 10 deletions src-tauri/src/module/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use crossbeam_channel::{unbounded, Receiver};
use tauri::{api::path::data_dir, AppHandle, Manager};

use super::{
recognizer::MyRecognizer, sqlite::Sqlite, transcription::Transcription, writer::Writer,
recognizer::MyRecognizer, sqlite::Sqlite, transcription::Transcription,
transcription_online::TranscriptionOnline, writer::Writer,
};

pub struct Record {
Expand Down Expand Up @@ -140,7 +141,6 @@ impl Record {
let is_converting = Arc::new(Mutex::new(false));
let (stop_convert_tx, stop_convert_rx) = unbounded();
let is_no_transcription = transcription_accuracy == "off";

let app_handle = self.app_handle.clone();
thread::spawn(move || loop {
match notify_decoding_state_is_finalized_rx.try_recv() {
Expand Down Expand Up @@ -177,7 +177,6 @@ impl Record {
.lock()
.unwrap()
.replace(Writer::build(&audio_path.to_str().expect("error"), spec));

if !is_no_transcription && !*is_converting.lock().unwrap() {
let is_converting_clone = Arc::clone(&is_converting);
let app_handle_clone = app_handle.clone();
Expand All @@ -188,13 +187,24 @@ impl Record {
let mut lock = is_converting_clone.lock().unwrap();
*lock = true;
drop(lock);
let mut transcription = Transcription::new(
app_handle_clone,
transcription_accuracy_clone,
speaker_language_clone,
note_id,
);
transcription.start(stop_convert_rx_clone, false);
if transcription_accuracy_clone.starts_with("online") {
let mut transcription_online = TranscriptionOnline::new(
app_handle_clone,
transcription_accuracy_clone,
speaker_language_clone,
note_id,
);
transcription_online.start(stop_convert_rx_clone, false);
} else {
let mut transcription = Transcription::new(
app_handle_clone,
transcription_accuracy_clone,
speaker_language_clone,
note_id,
);
transcription.start(stop_convert_rx_clone, false);
}

let mut lock = is_converting_clone.lock().unwrap();
*lock = false;
drop(lock);
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/module/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ impl Sqlite {
});
}

pub fn select_whisper_token(&self) -> Result<String, rusqlite::Error> {
return self.conn.query_row(
"SELECT setting_status FROM settings WHERE setting_name = \"settingKey\"",
params![],
|row| Ok(row.get_unwrap(0)),
);
}

pub fn update_model_vosk_to_whisper(
&self,
id: u16,
Expand Down
45 changes: 24 additions & 21 deletions src-tauri/src/module/transcriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,47 @@ impl Transcriber {
speaker_language: String,
transcription_accuracy: String,
) -> FullParams<'static, 'static> {
let mut language = "ja";
if speaker_language.starts_with("en-us") || speaker_language.starts_with("small-en-us") {
language = "en";
let language = if speaker_language.starts_with("en-us")
|| speaker_language.starts_with("small-en-us")
{
"en"
} else if speaker_language.starts_with("cn") || speaker_language.starts_with("small-cn") {
language = "zh";
"zh"
} else if speaker_language.starts_with("small-ko") {
language = "ko";
"ko"
} else if speaker_language.starts_with("fr") || speaker_language.starts_with("small-fr") {
language = "fr";
"fr"
} else if speaker_language.starts_with("de") || speaker_language.starts_with("small-de") {
language = "de";
"de"
} else if speaker_language.starts_with("ru") || speaker_language.starts_with("small-ru") {
language = "ru";
"ru"
} else if speaker_language.starts_with("es") || speaker_language.starts_with("small-es") {
language = "es";
"es"
} else if speaker_language.starts_with("small-pt") {
language = "pt";
"pt"
} else if speaker_language.starts_with("small-tr") {
language = "tr";
"tr"
} else if speaker_language.starts_with("vn") || speaker_language.starts_with("small-vn") {
language = "vi";
"vi"
} else if speaker_language.starts_with("it") || speaker_language.starts_with("small-it") {
language = "it";
"it"
} else if speaker_language.starts_with("small-nl") {
language = "nl";
"nl"
} else if speaker_language.starts_with("small-ca") {
language = "ca";
"ca"
} else if speaker_language.starts_with("uk") || speaker_language.starts_with("small-uk") {
language = "uk";
"uk"
} else if speaker_language.starts_with("small-sv") {
language = "sv";
"sv"
} else if speaker_language.starts_with("hi") || speaker_language.starts_with("small-hi") {
language = "hi";
"hi"
} else if speaker_language.starts_with("small-cs") {
language = "cs";
"cs"
} else if speaker_language.starts_with("small-pl") {
language = "pl";
}
"pl"
} else {
"ja"
};
let mut params = FullParams::new(SamplingStrategy::BeamSearch {
beam_size: 5,
patience: 1.0,
Expand Down
Loading

0 comments on commit 198ab0e

Please sign in to comment.