Add "Translate to English" setting: Introduced a new setting to enable automatic translation of speech to English. Updated relevant components, settings modules, and transcription logic to support this feature. Adjusted accessibility permission calls for consistency.
This commit is contained in:
parent
d8927f1289
commit
c3aa2d7c1b
5 changed files with 33 additions and 5 deletions
|
|
@ -175,6 +175,7 @@ pub fn run() {
|
|||
shortcut::reset_binding,
|
||||
shortcut::change_ptt_setting,
|
||||
shortcut::change_audio_feedback_setting,
|
||||
shortcut::change_translate_to_english_setting,
|
||||
trigger_update_check,
|
||||
commands::models::get_available_models,
|
||||
commands::models::get_model_info,
|
||||
|
|
|
|||
|
|
@ -173,6 +173,9 @@ impl TranscriptionManager {
|
|||
)
|
||||
})?;
|
||||
|
||||
// Get current settings to check translation preference
|
||||
let settings = get_settings(&self.app_handle);
|
||||
|
||||
// Initialize parameters
|
||||
let mut params = FullParams::new(SamplingStrategy::default());
|
||||
params.set_language(Some("auto"));
|
||||
|
|
@ -182,6 +185,11 @@ impl TranscriptionManager {
|
|||
params.set_print_timestamps(false);
|
||||
params.set_suppress_blank(true);
|
||||
params.set_suppress_non_speech_tokens(true);
|
||||
|
||||
// Enable translation to English if requested
|
||||
if settings.translate_to_english {
|
||||
params.set_translate(true);
|
||||
}
|
||||
|
||||
state
|
||||
.full(params, &audio)
|
||||
|
|
@ -199,7 +207,8 @@ impl TranscriptionManager {
|
|||
}
|
||||
|
||||
let et = std::time::Instant::now();
|
||||
println!("\ntook {}ms", (et - st).as_millis());
|
||||
let translation_note = if settings.translate_to_english { " (translated)" } else { "" };
|
||||
println!("\ntook {}ms{}", (et - st).as_millis(), translation_note);
|
||||
|
||||
Ok(result.trim().to_string())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ pub struct AppSettings {
|
|||
pub selected_microphone: Option<String>,
|
||||
#[serde(default)]
|
||||
pub selected_output_device: Option<String>,
|
||||
#[serde(default = "default_translate_to_english")]
|
||||
pub translate_to_english: bool,
|
||||
}
|
||||
|
||||
fn default_model() -> String {
|
||||
|
|
@ -40,6 +42,11 @@ fn default_always_on_microphone() -> bool {
|
|||
false
|
||||
}
|
||||
|
||||
fn default_translate_to_english() -> bool {
|
||||
// Default to false - users need to opt-in to translation
|
||||
false
|
||||
}
|
||||
|
||||
pub const SETTINGS_STORE_PATH: &str = "settings_store.json";
|
||||
|
||||
pub fn get_default_settings() -> AppSettings {
|
||||
|
|
@ -47,12 +54,12 @@ pub fn get_default_settings() -> AppSettings {
|
|||
#[cfg(target_os = "windows")]
|
||||
let default_shortcut = "ctrl+space";
|
||||
#[cfg(target_os = "macos")]
|
||||
let default_shortcut = "alt+space"; // Alt key on macOS (Option key)
|
||||
let default_shortcut = "alt+space"; // Alt key on macOS (Option key)
|
||||
#[cfg(target_os = "linux")]
|
||||
let default_shortcut = "ctrl+space";
|
||||
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
|
||||
let default_shortcut = "alt+space"; // Fallback for other platforms
|
||||
|
||||
let default_shortcut = "alt+space"; // Fallback for other platforms
|
||||
|
||||
let mut bindings = HashMap::new();
|
||||
bindings.insert(
|
||||
"transcribe".to_string(),
|
||||
|
|
@ -83,6 +90,7 @@ pub fn get_default_settings() -> AppSettings {
|
|||
always_on_microphone: false,
|
||||
selected_microphone: None,
|
||||
selected_output_device: None,
|
||||
translate_to_english: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +138,8 @@ pub fn get_settings(app: &AppHandle) -> AppSettings {
|
|||
.expect("Failed to initialize store");
|
||||
|
||||
if let Some(settings_value) = store.get("settings") {
|
||||
serde_json::from_value::<AppSettings>(settings_value).unwrap_or_else(|_| get_default_settings())
|
||||
serde_json::from_value::<AppSettings>(settings_value)
|
||||
.unwrap_or_else(|_| get_default_settings())
|
||||
} else {
|
||||
get_default_settings()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,6 +111,14 @@ pub fn change_audio_feedback_setting(app: AppHandle, enabled: bool) -> Result<()
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn change_translate_to_english_setting(app: AppHandle, enabled: bool) -> Result<(), String> {
|
||||
let mut settings = settings::get_settings(&app);
|
||||
settings.translate_to_english = enabled;
|
||||
settings::write_settings(&app, settings);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn _register_shortcut(app: &AppHandle, binding: ShortcutBinding) -> Result<(), String> {
|
||||
// Parse shortcut and return error if it fails
|
||||
let shortcut = match binding.current_binding.parse::<Shortcut>() {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ export const SettingsSchema = z.object({
|
|||
always_on_microphone: z.boolean(),
|
||||
selected_microphone: z.string().nullable().optional(),
|
||||
selected_output_device: z.string().nullable().optional(),
|
||||
translate_to_english: z.boolean(),
|
||||
});
|
||||
|
||||
export const BindingResponseSchema = z.object({
|
||||
|
|
|
|||
Loading…
Reference in a new issue