openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Local Piper TTS engine fails to initialize on macOS M-series architecture

Open LockedOnDave opened this issue 4 months ago • 2 comments

Summary

When enabling local Piper Text-to-Speech (TTS), the application encounters a 10-second initialization timeout and fails to generate voice output. The underlying failure is caused by an architecture mismatch, as the application downloads Intel (x86_64) binaries instead of native Apple Silicon (arm64) versions.

Problem

What Happened vs. Expected: After installing Piper, choosing a voice, and selecting the test option, the TTS test failed. Expected the test to pass successfully.

Impact: Local voice synthesis is entirely non-functional on all M-series (M1/M2/M3/M4) Macs out of the box.

Version / Platform:

  • OS: macOS (Apple Silicon / arm64 architecture)
  • App Version: Version 0.61.8 (0.61.8)

Steps to Reproduce:

  1. Install and launch OpenHuman on an Apple Silicon Mac.
  2. Navigate to settings and enable the local Piper TTS engine.
  3. Choose a voice and select the "Test" button.
  4. Observe that the test fails to execute.

Solution

Suspected Cause: The application's asset downloader fetches a deployment bundle containing legacy Intel (x86_64) binaries rather than native Apple Silicon (arm64) binaries, compounded by incorrect file permissions. This conclusion was drawn through the following diagnostic steps:

  1. Log Analysis: Reviewed the application logs, which revealed a 10-second initialization hang followed by dyld dynamic library loading errors.
  2. Sandbox Inspection: Located and inspected the local binary sandbox directory automatically generated by the application at ~/.openhuman/bin/piper/.
  3. Architecture Verification: Checked the compilation architecture of the extracted binaries (piper, piper_phonemize, and espeak-ng), confirming they were built for x86_64 instead of native arm64.
  4. Permissions Check: Audited the file permissions within the sandbox directory and found that the espeak-ng binary lacked standard executable (+x) permissions.

Proposed Fix:

  1. Recompile or re-package the piper_macos_aarch64 asset bundle on the distribution server to include genuine native arm64 binaries for piper, piper_phonemize, and espeak-ng.
  2. Ensure the decompression workflow explicitly sets or preserves the executable permissions (chmod +x) for the internal binaries.

Acceptance criteria

  • [ ] Repro gone — Bug no longer reproduces on the stated environment (or root cause documented if intentional).

  • [ ] Regression safety — Unit, integration, or E2E coverage added or updated if this should not come back.

  • [ ] Diff coverage ≥ 80% — the fix PR meets the changed-lines coverage gate (Vitest + cargo-llvm-cov, enforced by .github/workflows/ci-lite.yml).

  • [ ] … — Other verify-before-close items.

Related

  • None / N/A

Implementation Plan

Triage Assessment

This issue is relevant and not a duplicate. The user reports Piper TTS failing on M-series Macs with a 10-second timeout, finding x86_64 binaries in the sandbox directory and missing executable permissions on espeak-ng. Local TTS is entirely non-functional on all M-series Macs out of the box. The architecture detection code at src/openhuman/inference/local/install_piper.rs:76-84 correctly resolves piper_macos_aarch64.tar.gz on arm64 hosts -- the exact location of the bug depends on whether the upstream archive contains wrong-architecture binaries, or the extraction/permissions path is faulty.

Proposed Scope

In-scope:

  1. Verify what piper_macos_aarch64.tar.gz from the upstream Piper release actually contains (architecture of the bundled binaries).
  2. Fix the extraction step to set executable permissions (+x) on all extracted binaries.
  3. Log the detected architecture and the downloaded archive name for diagnostics.

Explicit non-goals:

  • Rebuilding Piper for arm64 (upstream already ships arm64 builds).
  • Supporting additional voice models beyond the bundled en_US-lessac-medium.
  • Changing the voice download path or HuggingFace voice model resolution.

Implementation Steps

  1. Verify upstream asset content

    • Download piper_macos_aarch64.tar.gz from https://github.com/rhasspy/piper/releases/latest/download/piper_macos_aarch64.tar.gz on an M-series Mac.
    • Extract and run file piper piper_phonemize espeak-ng to confirm architecture.
    • If the archive contains x86_64 binaries (the file output shows "Mach-O 64-bit executable x86_64"), the bug is upstream. File an issue with the Piper project or switch to a known-good release tag.
    • If the archive contains arm64 binaries (file shows "Mach-O 64-bit executable arm64"), the bug is in extraction/permissions.
  2. Fix file permissions on extracted binaries

    • File: src/openhuman/inference/local/install_piper.rs. After the archive is extracted (in the install flow, probably around extract_tar_gz or extract_zip call sites), add std::fs::set_permissions calls to set std::os::unix::fs::PermissionsExt::set_mode(0o755) on piper, piper_phonemize, and espeak-ng.
    • File: src/openhuman/inference/local/voice_install_common.rs -- if the extraction logic is shared across whisper and piper installers, add the permissions fix there as a post-extraction step for all extracted binaries. This prevents the same issue from affecting Whisper.
    • The espeak-ng binary is inside the archive as a sibling of piper. Confirm the extraction path: find where the archive is unpacked (likely the piper/ subdirectory of the workspace bin/ directory configured at src/openhuman/inference/paths.rs:271).
  3. Add architecture diagnostics

    • File: src/openhuman/inference/local/install_piper.rs function binary_download_asset() (lines 66-100). Log the detected std::env::consts::ARCH and the chosen suffix, e.g.:
      log::info!("{LOG_PREFIX} host arch={arch}, selecting asset=piper_{suffix}.tar.gz");
      
    • After extraction, log the file permissions stance of the extracted binary, e.g.:
      log::debug!("{LOG_PREFIX} extracted piper binary permissions: {:o}", piper_path.metadata()?.permissions().mode());
      
  4. Improve error messages

    • File: src/openhuman/inference/local/install_piper.rs. The installer currently validates archive size (MIN_BINARY_ARCHIVE_BYTES) and voice file sizes. Add a post-extraction check: verify at least one extracted binary has executable permission. If not, log a diagnostic "extracted binaries lack execute permission -- applying fix" and apply it.

Verification

  • Unit tests (Rust):
    • src/openhuman/inference/local/install_piper_tests.rs or src/openhuman/inference/local/voice_install_common_tests.rs -- add a test that creates a mock archive, runs the extraction, and verifies +x is set on the extracted binary.
    • The existing tests/raw_coverage/inference_local_ops_piper_raw_coverage_e2e.rs tests already exercise the install flow using a mock server. Extend PiperMockState to serve an archive that would trigger the permissions issue, and verify the fix applies +x.
  • Manual verification (ARM Mac required):
    • Run install_piper on an M-series Mac and confirm:
      • The log shows the correct aarch64 architecture.
      • The downloaded filename contains macos_aarch64.
      • After extraction, file ~/.openhuman/bin/piper/piper/piper shows arm64.
      • ls -la ~/.openhuman/bin/piper/piper/espeak-ng shows -rwxr-xr-x (executable).
      • The "Test" button in Settings -> Voice -> Piper TTS produces audible speech.

Risks and Open Questions

  • Upstream Piper providing wrong-architecture binaries. If the upstream piper_macos_aarch64.tar.gz actually contains x86_64 binaries, the fix is out of our hands (file an upstream issue). In that case, the code-level fix is to add a post-extraction lipo / file check that warns the user and falls back to running under Rosetta, or pins to a known-good release tag.
  • Rosetta fallback. If the upstream archive contains x86_64, the binary would still run under Rosetta (slower startup, hence the 10-second timeout). Adding a --rosetta detection and warning would help users self-diagnose.
  • CI cannot test native ARM Mac. The existing mock-based tests cover the install flow but not the actual binary execution. Manual testing on M-series hardware is required for final verification.

Acceptance Criteria

  • Piper TTS installation on an M-series Mac downloads the correct arm64 archive.
  • Extracted binaries (piper, piper_phonemize, espeak-ng) have executable permissions.
  • The "Test" button in Voice settings produces audible speech on M-series Macs.
  • Post-extraction logging includes architecture and permissions diagnostics.
  • Existing mock-based installer tests pass unchanged.

LockedOnDave avatar Jul 19 '26 22:07 LockedOnDave

this bug is present on your first release and also present not resolved.... is functional only whith pay... BUUUUUUUU delete your app.

gianlucafiuzzi-byte avatar Jul 25 '26 07:07 gianlucafiuzzi-byte