Skip to content

armgit / Handy

Public Imported from GitHub
0

A free, open source, and extensible speech-to-text application that works completely offline.

Merge branch 'main' of github.com:cjpais/Handy

CJ Pais0e5036721ef6
diff --cc src-tauri/src/managers/transcription.rs
index 248736f5,c8cd4491..ddfcfc56
--- a/src-tauri/src/managers/transcription.rs
+++ b/src-tauri/src/managers/transcription.rs
@@@ -1969,78 -1951,85 +1951,63 @@@ fn resolve_device_index(index: usize) -
/// Map Handy's whisper accelerator setting to a transcribe-cpp [`Backend`].
///
-/// `Auto` lets the library pick the best device (with CPU fallback). `Cpu` forces
-/// strict CPU. `Gpu` requests the platform GPU backend, but only if a device for
-/// it is actually registered — otherwise it falls back to `Auto` so the load
-/// never fails outright on a machine without that GPU backend. An emulated x64
-/// process on Windows ARM64 forces strict CPU for every setting.
+/// `Auto` lets the library pick the best device (with CPU fallback), while
+/// `Cpu` forces strict CPU. `Gpu` only remains as the companion setting for an
+/// exact device; without a valid exact device it has the retired generic GPU
+/// state's new Auto semantics. An emulated x64 process on Windows ARM64 forces
+/// strict CPU for every setting.
fn select_transcribe_backend(setting: TranscribeAcceleratorSetting) -> Backend {
- <<<<<<< Updated upstream
- match effective_transcribe_accelerator(setting, transcribe_gpu_disabled_for_host()) {
- TranscribeAcceleratorSetting::Cpu => Backend::Cpu,
- TranscribeAcceleratorSetting::Auto => Backend::Auto,
- TranscribeAcceleratorSetting::Gpu => {
- #[cfg(target_os = "macos")]
- let candidates = [Backend::Metal];
- #[cfg(not(target_os = "macos"))]
- let candidates = [Backend::Cuda, Backend::Vulkan];
- ||||||| Stash base
-- match effective_transcribe_accelerator(setting, transcribe_gpu_disabled_for_host()) {
- TranscribeAcceleratorSetting::Cpu => Backend::Cpu,
- TranscribeAcceleratorSetting::Auto => Backend::Auto,
- TranscribeAcceleratorSetting::Gpu => {
- #[cfg(target_os = "macos")]
- let candidates = [Backend::Metal];
- #[cfg(not(target_os = "macos"))]
- let candidates = [Backend::Cuda, Backend::Rocm, Backend::Vulkan];
- =======
+ select_transcribe_backend_for_host(setting, transcribe_gpu_disabled_for_host())
+}
- >>>>>>> Stashed changes
+
+fn select_transcribe_backend_for_host(
+ setting: TranscribeAcceleratorSetting,
+ gpu_disabled: bool,
+) -> Backend {
+ match effective_transcribe_accelerator(setting, gpu_disabled) {
TranscribeAcceleratorSetting::Cpu => Backend::Cpu,
- TranscribeAcceleratorSetting::Auto => Backend::Auto,
- TranscribeAcceleratorSetting::Gpu => {
- #[cfg(target_os = "macos")]
- let candidates = [Backend::Metal];
- #[cfg(not(target_os = "macos"))]
- let candidates = [Backend::Cuda, Backend::Rocm, Backend::Vulkan];
-
- match candidates
- .into_iter()
- .find(|&b| transcribe_cpp::backend_available(b))
- {
- Some(b) => b,
- None => {
- #[cfg(target_os = "linux")]
- warn!(
- "GPU acceleration was requested, but no transcribe.cpp GPU backend is \
- registered; falling back to Auto (usually CPU). Run with \
- --list-devices to inspect detected devices; VK_LOADER_DEBUG=error can \
- reveal Vulkan loader or driver failures"
- );
- #[cfg(not(target_os = "linux"))]
- warn!(
- "GPU acceleration was requested, but no transcribe.cpp GPU backend is \
- registered; falling back to Auto (usually CPU). Run with \
- --list-devices to inspect detected devices"
- );
- Backend::Auto
- }
- }
- }
+ TranscribeAcceleratorSetting::Auto | TranscribeAcceleratorSetting::Gpu => Backend::Auto,
}
}
- /// Resolve the user's stored GPU device choice into a [`ModelOptions::gpu_device`]
- /// registry index for the next model load.
- ///
- /// Settings store a registry index into [`transcribe_cpp::devices`] (`-1` is the
- /// UI's auto/CPU sentinel); transcribe-cpp treats `0` as "auto / first match" and
- /// rejects an out-of-range or non-GPU index. So an explicit selection is honored
- /// only when the user chose the GPU accelerator and the stored index still
- /// resolves to a registered GPU device — otherwise fall back to `0` so a stale
- /// selection can never fail the load.
- fn resolve_gpu_device(setting: TranscribeAcceleratorSetting, gpu_device: i32) -> i32 {
- if transcribe_gpu_disabled_for_host()
- || setting != TranscribeAcceleratorSetting::Gpu
- || gpu_device <= 0
- {
- return 0;
+ /// Resolve the user's persisted GPU identity to a fresh opaque 0.2 device
+ /// handle. Registry indices and handles are process-local, so settings store a
+ /// key based on the backend's stable `device_id` (falling back to name for
+ /// backends such as Metal that do not report one).
+ fn resolve_gpu_device(
+ setting: TranscribeAcceleratorSetting,
+ gpu_device: Option<&str>,
+ ) -> Option<transcribe_cpp::Device> {
+ if transcribe_gpu_disabled_for_host() || setting != TranscribeAcceleratorSetting::Gpu {
+ return None;
}
- let still_valid = transcribe_compute_devices()
- .iter()
- .any(|d| d.index == Some(gpu_device as usize) && is_transcribe_gpu_device(d));
- if still_valid {
- gpu_device
- } else {
+ let gpu_device = gpu_device?;
+ let resolved = transcribe_compute_devices().into_iter().find(|device| {
+ is_transcribe_gpu_device(device) && transcribe_device_key(device) == gpu_device
+ });
+ if resolved.is_none() {
warn!(
- <<<<<<< Updated upstream
- "Stored transcribe GPU device index {} is no longer available; using auto",
- ||||||| Stash base
-- "Stored transcribe GPU device '{}' is no longer available; using automatic GPU selection",
- =======
+ "Stored transcribe GPU device '{}' is no longer available; using automatic device selection",
- >>>>>>> Stashed changes
gpu_device
);
- 0
+ }
+ resolved
+ }
+
+ fn transcribe_device_key(device: &transcribe_cpp::Device) -> String {
+ let (identity_kind, identity) = match device.device_id.as_deref() {
+ Some(device_id) => ("id", device_id),
+ None => ("name", device.name.as_str()),
+ };
+ serde_json::to_string(&(device.kind.as_str(), identity_kind, identity))
+ .expect("transcribe device identity is always JSON serializable")
+ }
+
+ fn transcribe_device_label(device: &transcribe_cpp::Device) -> String {
+ if device.description.is_empty() {
+ device.name.clone()
+ } else {
+ device.description.clone()
}
}
diff --cc src-tauri/src/settings.rs
index 821c32fd,8e8fdcb5..68081bda
--- a/src-tauri/src/settings.rs
+++ b/src-tauri/src/settings.rs
@@@ -1079,19 -1103,10 +1103,8 @@@ fn apply_settings_migrations
}
if stored_schema_version < 2 {
// transcribe.cpp 0.2 replaced integer registry indices with opaque
- // process-local handles. Clear every old index once; keeping the GPU
- // accelerator preference for schema-1 users preserves their intent and
- // lets the backend choose a valid GPU automatically.
+ // process-local handles. Clear every old index once.
settings.transcribe_gpu_device = default_transcribe_gpu_device();
- >>>>>>> Stashed changes
settings.settings_schema_version = CURRENT_SETTINGS_SCHEMA_VERSION;
updated = true;
}
@@@ -1294,25 -1301,8 +1308,8 @@@ mod tests
assert_eq!(settings.sound_theme, SoundTheme::Pop);
assert!(settings.filler_word_removal_enabled);
- <<<<<<< Updated upstream
- // A current-format store must not be rewritten on every read.
- assert!(!apply_settings_migrations(&mut settings, &stored));
- ||||||| Stash base
-- // The 0.1 integer device index is cleared once for transcribe.cpp 0.2,
-- // while preserving this user's explicit GPU accelerator preference.
- assert!(apply_settings_migrations(&mut settings, &stored));
- assert_eq!(
- settings.settings_schema_version,
- CURRENT_SETTINGS_SCHEMA_VERSION
- );
- assert_eq!(
- settings.transcribe_accelerator,
- TranscribeAcceleratorSetting::Gpu
- );
- assert_eq!(settings.transcribe_gpu_device, None);
- =======
+ // The 0.1 integer device index is cleared once for transcribe.cpp 0.2.
+ // Without an exact device, the retired generic GPU choice becomes Auto.
assert!(apply_settings_migrations(&mut settings, &stored));
assert_eq!(
settings.settings_schema_version,
@@@ -1320,10 -1310,9 +1317,9 @@@
);
assert_eq!(
settings.transcribe_accelerator,
- TranscribeAcceleratorSetting::Gpu
+ TranscribeAcceleratorSetting::Auto
);
assert_eq!(settings.transcribe_gpu_device, None);
- >>>>>>> Stashed changes
}
#[test]
@@@ -1507,29 -1492,7 +1499,7 @@@
}
#[test]
- <<<<<<< Updated upstream
- fn gpu_device_migration_keeps_current_schema_positive_selection() {
- ||||||| Stash base
-- fn gpu_device_migration_clears_v1_index_but_keeps_gpu_preference() {
- let raw = serde_json::json!({
- "settings_schema_version": 1,
- "transcribe_accelerator": "gpu",
- "transcribe_gpu_device": 2
- });
- let mut settings: AppSettings = serde_json::from_value(raw.clone()).unwrap();
-
- assert!(apply_settings_migrations(&mut settings, &raw));
- assert_eq!(
- settings.transcribe_accelerator,
- TranscribeAcceleratorSetting::Gpu
- );
- assert_eq!(settings.transcribe_gpu_device, None);
- }
-
- #[test]
- fn gpu_device_migration_keeps_current_stable_selection() {
- =======
+ fn gpu_device_migration_maps_v1_automatic_gpu_to_auto() {
let raw = serde_json::json!({
"settings_schema_version": 1,
"transcribe_accelerator": "gpu",
diff --cc src/components/settings/AccelerationSelector.tsx
index 9c97152f,a2276cb8..080e6388
--- a/src/components/settings/AccelerationSelector.tsx
+++ b/src/components/settings/AccelerationSelector.tsx
@@@ -24,55 -24,31 +24,28 @@@ interface AccelerationSelectorProps
/**
* transcribe.cpp dropdown encodes accelerator + device in a single value:
- <<<<<<< Updated upstream
- * "auto" → accelerator=auto, gpu_device=-1
- * "cpu" → accelerator=cpu, gpu_device=-1
- * "gpu:0" → accelerator=gpu, gpu_device=0
- * "gpu:1" → accelerator=gpu, gpu_device=1
- ||||||| Stash base
* "auto" → accelerator=auto, gpu_device=null
* "cpu" → accelerator=cpu, gpu_device=null
-- * "gpu" → accelerator=gpu, auto GPU selection
* "gpu:<id>" → accelerator=gpu, stable opaque device identity
- =======
- * "auto" → accelerator=auto, gpu_device=null
- * "cpu" → accelerator=cpu, gpu_device=null
- * "gpu:<id>" → accelerator=gpu, stable opaque device identity
- >>>>>>> Stashed changes
*/
function encodeTranscribeValue(
accelerator: TranscribeAcceleratorSetting,
- gpuDevice: number,
+ gpuDevice: string | null,
): string {
if (accelerator === "cpu") return "cpu";
- <<<<<<< Updated upstream
- if (accelerator === "gpu" && gpuDevice >= 0) return `gpu:${gpuDevice}`;
- ||||||| Stash base
-- if (accelerator === "gpu")
-- return gpuDevice === null ? "gpu" : `gpu:${gpuDevice}`;
- =======
+ if (accelerator === "gpu" && gpuDevice !== null) return `gpu:${gpuDevice}`;
- >>>>>>> Stashed changes
return "auto";
}
function decodeTranscribeValue(value: string): {
accelerator: TranscribeAcceleratorSetting;
- gpuDevice: number;
+ gpuDevice: string | null;
} {
- <<<<<<< Updated upstream
- if (value === "cpu") return { accelerator: "cpu", gpuDevice: -1 };
- ||||||| Stash base
- if (value === "cpu") return { accelerator: "cpu", gpuDevice: null };
- if (value === "gpu") return { accelerator: "gpu", gpuDevice: null };
- =======
if (value === "cpu") return { accelerator: "cpu", gpuDevice: null };
- >>>>>>> Stashed changes
- if (value === "gpu") return { accelerator: "gpu", gpuDevice: null };
if (value.startsWith("gpu:")) {
- const id = parseInt(value.slice(4), 10);
- return { accelerator: "gpu", gpuDevice: id };
+ return { accelerator: "gpu", gpuDevice: value.slice(4) };
}
- return { accelerator: "auto", gpuDevice: -1 };
+ return { accelerator: "auto", gpuDevice: null };
}
export const AccelerationSelector: FC<AccelerationSelectorProps> = ({