Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions backend/engines/omnivoice_gguf/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
#: ``bin/checksums.sha256``. backend/engines/omnivoice_gguf/ → root.
_REPO_ROOT = _PKG_DIR.parent.parent.parent

#: Absolute directory that holds the bundled runtime, set by the desktop app.
#: An installed app runs a copy of ``backend/`` staged in its runtime folder
#: (``<app environment>/project``), which has no ``bin/``; the installer keeps
#: the runtime in ``resources/bin`` (#4051).
BIN_DIR_ENV = "OMNIVOICE_GGUF_BIN_DIR"

#: HuggingFace repo ID for the quants. Pinned by SHA via ``quant_map.json``.
_HF_REPO_ID = "Serveurperso/OmniVoice-GGUF"

Expand Down Expand Up @@ -133,13 +139,25 @@ def _platform_slug() -> str:
return "linux-x86_64"


def _bin_dir() -> Path:
"""Directory of the bundled runtime and its ``checksums.sha256``.

``OMNIVOICE_GGUF_BIN_DIR`` when it is an absolute path, else ``bin/`` at
the repo root (source checkouts and builds that run from ``resources/``).
"""
raw = os.environ.get(BIN_DIR_ENV, "").strip()
if raw and os.path.isabs(raw):
return Path(raw)
return _REPO_ROOT / "bin"


def _binary_path(slug: Optional[str] = None) -> Path:
"""Resolve the on-disk path for the platform binary."""
s = slug or _platform_slug()
name = "omnivoice-tts-" + s
if s.startswith("windows"):
name += ".exe"
return _REPO_ROOT / "bin" / name
return _bin_dir() / name


def _generate_timeout_s() -> float:
Expand Down Expand Up @@ -747,7 +765,7 @@ def _load_checksum_manifest() -> dict[str, str]:
:class:`ChecksumManifestError`: an entry that may have declared a checksum
must never be skipped silently.
"""
manifest = _REPO_ROOT / "bin" / "checksums.sha256"
manifest = _bin_dir() / "checksums.sha256"
out: dict[str, str] = {}
if not manifest.is_file():
return out
Expand Down
1 change: 1 addition & 0 deletions changelog.d/4053.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The OmniVoice GGUF engine finds its bundled runtime again in installed apps instead of reporting it missing — thanks @b84330808! (#4053)
4 changes: 4 additions & 0 deletions docs/engines/omnivoice-gguf.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ The desktop installers ship this native binary under `resources/bin/`
Windows on ARM (the x64 binary, run under emulation like the rest of the local
backend), macOS Apple Silicon and the Linux AppImage/deb. The Windows binary
carries its own Visual C++ runtime, so no redistributable install is needed.
The app passes that folder to the backend as `OMNIVOICE_GGUF_BIN_DIR`, so the
engine finds it wherever the app environment lives
([#4051](https://github.com/debpalash/VoiceStudio/issues/4051)).
The Intel Mac download has no binary because Intel Macs cannot run the local
backend at all ([macOS install](../install/macos.md)). Store builds (Microsoft
Store, Mac App Store, Snap Store) and the Docker image do not include it yet;
Expand Down Expand Up @@ -394,6 +397,7 @@ log says why once.

| Variable | Default | Meaning |
| --- | --- | --- |
| `OMNIVOICE_GGUF_BIN_DIR` | `bin/` at the repo root | Absolute folder holding `omnivoice-tts-<platform>` and `checksums.sha256`; the desktop app sets it to its `resources/bin/` |
| `OMNIVOICE_GGUF_GENERATE_TIMEOUT_S` | (generous built-in) | Per-generation timeout for the spawned binary |
| `OMNIVOICE_GGUF_QUANT` | `auto` | Pin a quant (`Q4_K_M`, `Q8_0`, `BF16`, `F32`); overrides Settings |
| `OMNIVOICE_GGUF_RESIDENT` | `0` | `1` keeps a bundled `tts-server` loaded between requests (opt-in, see Resident server); overrides Settings |
Expand Down
19 changes: 19 additions & 0 deletions electron/src/main/backend-setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ vi.mock('./setup-downloads', async (importOriginal) => ({
}));
import {
BackendSupervisor,
bundledGgufBinPath,
bundledUvPath,
bundledWebUiPath,
isExpectedPipeClose,
Expand Down Expand Up @@ -1042,6 +1043,24 @@ it('keeps a web UI directory the user pinned themselves', () => {
expect(managedBackendSpawnOptions(3900).env.OMNIVOICE_FRONTEND_DIST).toBe('/custom/web');
});

it('points the GGUF engine at the runtime packaged with this app version', () => {
// #4051: the backend runs from a staged copy of backend/ that has no bin/.
vi.stubEnv('OMNIVOICE_GGUF_BIN_DIR', '');
stubResourcesPath(join('/opt', 'VoiceStudio', 'resources'));

const { env } = managedBackendSpawnOptions(3900);

expect(env.OMNIVOICE_GGUF_BIN_DIR).toBe(join('/opt', 'VoiceStudio', 'resources', 'bin'));
expect(bundledGgufBinPath()).toBe(env.OMNIVOICE_GGUF_BIN_DIR);
});

it('keeps a GGUF runtime directory the user pinned themselves', () => {
vi.stubEnv('OMNIVOICE_GGUF_BIN_DIR', '/custom/bin');
stubResourcesPath(join('/opt', 'VoiceStudio', 'resources'));

expect(managedBackendSpawnOptions(3900).env.OMNIVOICE_GGUF_BIN_DIR).toBe('/custom/bin');
});

it('exposes the current process signal separately from the durable crash journal', async () => {
vi.useFakeTimers();
vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new Error('offline')));
Expand Down
11 changes: 11 additions & 0 deletions electron/src/main/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ export function bundledWebUiPath(): string {
return join(backendRoot(), 'frontend', 'dist');
}

/** The OmniVoice GGUF runtime packaged with this app version (omnivoice-tts-bundle.mjs). */
export function bundledGgufBinPath(): string {
return join(backendRoot(), 'bin');
}

function samePath(left: string, right: string): boolean {
const normalizedLeft = resolve(left);
const normalizedRight = resolve(right);
Expand Down Expand Up @@ -744,6 +749,12 @@ function childEnv(
if (app.isPackaged && process.resourcesPath && !env.OMNIVOICE_FRONTEND_DIST?.trim()) {
env.OMNIVOICE_FRONTEND_DIST = bundledWebUiPath();
}
// #4051: the managed runtime runs a copy of backend/ staged in the runtime
// folder, which has no bin/, so the GGUF engine's `<root>/bin` lookup found
// no runtime there. Point it at the one shipped in this version's resources.
if (app.isPackaged && process.resourcesPath && !env.OMNIVOICE_GGUF_BIN_DIR?.trim()) {
env.OMNIVOICE_GGUF_BIN_DIR = bundledGgufBinPath();
}
// Region defaults must leave HF_ENDPOINT unset so the backend can probe and
// fail over. Only an explicit user endpoint may disable automatic selection.
if (platform === 'win32') {
Expand Down
48 changes: 48 additions & 0 deletions tests/backend/engines/test_omnivoice_gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,54 @@ def test_is_available_passes_when_manifest_absent(monkeypatch, tmp_path, cached_
assert ok is True, reason


def test_installed_app_finds_the_runtime_outside_the_staged_backend(
monkeypatch, tmp_path, cached_weights
):
"""#4051 — an installed app runs a copy of backend/ staged in its runtime
folder (``<app environment>/project``), which has no bin/. The runtime and
its manifest stay in the installer's resources/bin, which the desktop app
passes as OMNIVOICE_GGUF_BIN_DIR."""
import hashlib

from engines.omnivoice_gguf import backend as gguf_backend

project = tmp_path / "project"
project.mkdir()
resources_bin = tmp_path / "resources" / "bin"
resources_bin.mkdir(parents=True)
exe = resources_bin / "omnivoice-tts-linux-x86_64"
exe.write_bytes(b"\x7fELF-real-enough")
exe.chmod(0o755)
digest = hashlib.sha256(exe.read_bytes()).hexdigest()
(resources_bin / "checksums.sha256").write_text(
f"{digest} {exe.name}\n", encoding="utf-8"
)
monkeypatch.setattr(gguf_backend, "_REPO_ROOT", project)
monkeypatch.setattr(gguf_backend, "_platform_slug", lambda: "linux-x86_64")
monkeypatch.setattr(gguf_backend, "_is_macos_quarantined", lambda p: False)
monkeypatch.setenv("OMNIVOICE_GGUF_BIN_DIR", str(resources_bin))

ok, reason = gguf_backend._make_backend_class().is_available()
assert ok is True, reason
assert gguf_backend._binary_path() == exe
assert gguf_backend._load_checksum_manifest() == {exe.name: digest}


def test_runtime_dir_defaults_to_the_repo_bin(monkeypatch):
"""Source checkouts (no OMNIVOICE_GGUF_BIN_DIR) keep using <repo>/bin, and a
relative value is ignored rather than resolved against the working directory."""
from engines.omnivoice_gguf import backend as gguf_backend

monkeypatch.delenv("OMNIVOICE_GGUF_BIN_DIR", raising=False)
assert gguf_backend._binary_path("linux-x86_64") == (
gguf_backend._REPO_ROOT / "bin" / "omnivoice-tts-linux-x86_64"
)
monkeypatch.setenv("OMNIVOICE_GGUF_BIN_DIR", "bin")
assert gguf_backend._binary_path("linux-x86_64") == (
gguf_backend._REPO_ROOT / "bin" / "omnivoice-tts-linux-x86_64"
)


def test_probe_load_timeout(monkeypatch, tmp_path):
"""T-04-06 — a hung binary surfaces as subprocess.TimeoutExpired."""
from engines.omnivoice_gguf import backend as gguf_backend
Expand Down
12 changes: 9 additions & 3 deletions tests/test_gguf_desktop_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ def test_release_builds_the_runtime_from_the_release_ref():
assert "release_tag" in build["with"]["ref"]


def test_packaged_layout_matches_the_backend_lookup():
# The packaged backend runs from resources/, so `<root>/bin` is
# resources/bin — exactly where the installer puts the runtime.
def test_packaged_layout_matches_the_backend_lookup(monkeypatch):
# Without OMNIVOICE_GGUF_BIN_DIR the lookup is `<root>/bin`: resources/bin
# for a backend that runs from resources/ (store builds, a selected Python).
from engines.omnivoice_gguf import backend

monkeypatch.delenv(backend.BIN_DIR_ENV, raising=False)
assert (backend._REPO_ROOT / "backend" / "engines" / "omnivoice_gguf").resolve() == \
backend._PKG_DIR
assert backend._binary_path("windows-x86_64") == backend._REPO_ROOT / "bin" / \
Expand All @@ -94,6 +95,11 @@ def test_packaged_layout_matches_the_backend_lookup():
assert "from: '../backend',\n to: 'backend'" in config
bundle = (REPO / "electron" / "omnivoice-tts-bundle.mjs").read_text(encoding="utf-8")
assert "OMNIVOICE_TTS_RESOURCE_DIR = 'bin'" in bundle
# The managed runtime runs a copy of backend/ staged outside resources/,
# with no bin/ beside it, so the app names resources/bin explicitly (#4051).
main = (REPO / "electron" / "src" / "main" / "backend.ts").read_text(encoding="utf-8")
assert f"env.{backend.BIN_DIR_ENV} = bundledGgufBinPath()" in main
assert "return join(backendRoot(), 'bin');" in main


def _run_windows_build(tmp_path: Path, runtime: dict[str, str]):
Expand Down
Loading