-
Notifications
You must be signed in to change notification settings - Fork 5
feat(ios): Add TTS support for iOS using ONNX Runtime #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AnthonyRonning
wants to merge
11
commits into
master
Choose a base branch
from
ios-tts-working
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c0dd653
feat(ios): add TTS support using ONNX Runtime
AnthonyRonning d5953c7
ci: enable TestFlight submission for ios-tts PR builds
AnthonyRonning 2100258
feat(ios): add local iOS TTS development tooling and documentation
AnthonyRonning fae1862
fix(ios): handle AudioContext unavailability and show error for Lockd…
AnthonyRonning 0970fd7
fix(ios): set audioSession type for TTS playback routing
AnthonyRonning 6e3ed8e
fix(ios): set Media Session metadata for TTS
AnthonyRonning 12f3bc9
fix(ios): clean up build config and harden TestFlight workflow
AnthonyRonning 9d74727
fix(ios): store TTS models under Library/Caches
AnthonyRonning b3c283a
ci: restore TestFlight workflow if conditions
AnthonyRonning f06e242
chore(ios): remove unused setup-ios-onnxruntime script
AnthonyRonning a85a9f9
fix(ios): omit simulator slice when not built
AnthonyRonning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| # iOS TTS Local Development Guide | ||
|
|
||
| This guide explains how to build and test the iOS TTS (Text-to-Speech) feature locally using the iOS Simulator or a physical device. | ||
|
|
||
| ## Overview | ||
|
|
||
| The iOS TTS feature uses ONNX Runtime to run Kokoro TTS models. ONNX Runtime must be built from source for iOS because: | ||
| 1. Pre-built binaries from HuggingFace are missing Abseil symbols | ||
| 2. We need both device (arm64) and simulator (arm64) builds | ||
| 3. The simulator build requires a workaround for a libiconv linking bug | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - macOS with Xcode installed (16.x+) | ||
| - CMake 3.26+ | ||
| - Python 3.8+ | ||
| - Git | ||
| - Nix (recommended) or manually install Rust toolchain | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ### 1. Build ONNX Runtime | ||
|
|
||
| ```bash | ||
| just ios-build-onnxruntime | ||
| ``` | ||
|
|
||
| This builds ONNX Runtime for both device and simulator (~5-10 minutes) and automatically generates the cargo config. | ||
|
|
||
| The output will be in `frontend/src-tauri/onnxruntime-ios/onnxruntime.xcframework/`. | ||
|
|
||
| ### 2. Regenerate Cargo Config (if needed) | ||
|
|
||
| If you move the project or need to regenerate the cargo config: | ||
|
|
||
| ```bash | ||
| just ios-setup-cargo-config | ||
| ``` | ||
|
|
||
| This creates `frontend/src-tauri/.cargo/config.toml` with the correct absolute paths for your machine. | ||
|
|
||
| ### 3. Fix arm64-sim Xcode Issue (if needed) | ||
|
|
||
| If you see this error: | ||
| ``` | ||
| clang: error: version '-sim' in target triple 'arm64-apple-ios13.0-simulator-sim' is invalid | ||
| ``` | ||
|
|
||
| See [troubleshooting-ios-build.md](./troubleshooting-ios-build.md) for details. | ||
|
|
||
| Quick fix: | ||
| ```bash | ||
| just ios-fix-arch | ||
| ``` | ||
|
|
||
| ### 4. Run on Simulator | ||
|
|
||
| ```bash | ||
| # Boot simulator first | ||
| xcrun simctl boot "iPhone 16 Pro" | ||
|
|
||
| # Run the app | ||
| just ios-dev-sim "iPhone 16 Pro" | ||
| ``` | ||
|
|
||
| ### 5. Run on Physical Device | ||
|
|
||
| ```bash | ||
| just ios-dev | ||
| ``` | ||
|
|
||
| Note: If you have a device connected (even wirelessly), `just ios-dev` may deploy to it instead of the simulator. Use `just ios-dev-sim` to explicitly target the simulator. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Vite Server Not Reachable | ||
|
|
||
| The iOS simulator needs to connect to your development server. Ensure `frontend/vite.config.ts` has: | ||
|
|
||
| ```typescript | ||
| server: { | ||
| host: "0.0.0.0", | ||
| port: 5173, | ||
| strictPort: true | ||
| } | ||
| ``` | ||
|
|
||
| ### Missing Abseil Symbols | ||
|
|
||
| If you see linker errors like: | ||
| ``` | ||
| Undefined symbols for architecture arm64: | ||
| "_AbslInternalSpinLockDelay_lts_20240722" | ||
| ``` | ||
|
|
||
| This means the ONNX Runtime library wasn't built from source. Pre-built binaries are missing these symbols. Run `./scripts/build-ios-onnxruntime-all.sh` to build from source. | ||
|
|
||
| ### Simulator Build Fails with libiconv Error | ||
|
|
||
| If the simulator build fails with: | ||
| ``` | ||
| ld: building for 'iOS-simulator', but linking in dylib built for 'iOS' | ||
| ``` | ||
|
|
||
| This is fixed by adding `CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=NEVER` to the cmake flags. The `build-ios-onnxruntime-all.sh` script already includes this fix. | ||
|
|
||
| ### Cargo Not Finding Library | ||
|
|
||
| 1. Ensure `.cargo/config.toml` uses absolute paths | ||
| 2. Clean and rebuild: `cd frontend/src-tauri && cargo clean` | ||
| 3. Verify the library exists: `ls -la onnxruntime-ios/onnxruntime.xcframework/ios-arm64-simulator/` | ||
|
|
||
| ## Architecture Notes | ||
|
|
||
| ### Why Build from Source? | ||
|
|
||
| 1. **Abseil symbols**: ONNX Runtime depends on Abseil (Google's C++ library). Pre-built binaries don't include these statically linked. | ||
|
|
||
| 2. **Simulator support**: Pre-built libraries often only include device builds. | ||
|
|
||
| 3. **Version compatibility**: Building from source ensures compatibility with our ort-sys Rust crate version. | ||
|
|
||
| ### Build Artifacts | ||
|
|
||
| After building, you'll have: | ||
| ``` | ||
| frontend/src-tauri/ | ||
| ├── onnxruntime-build/ # Build directory (can be deleted after build) | ||
| │ └── onnxruntime/ # ONNX Runtime source | ||
| └── onnxruntime-ios/ # Output directory | ||
| └── onnxruntime.xcframework/ | ||
| ├── Headers/ | ||
| ├── Info.plist | ||
| ├── ios-arm64/ | ||
| │ └── libonnxruntime.a # Device library (~69MB) | ||
| └── ios-arm64-simulator/ | ||
| └── libonnxruntime.a # Simulator library (~69MB) | ||
| ``` | ||
|
|
||
| ### .cargo/config.toml | ||
|
|
||
| The cargo config tells the Rust `ort-sys` crate where to find the ONNX Runtime library. The keys are: | ||
| - `[target.aarch64-apple-ios.onnxruntime]` - Device builds | ||
| - `[target.aarch64-apple-ios-sim.onnxruntime]` - Simulator builds (ARM64 Mac) | ||
| - `[target.x86_64-apple-ios.onnxruntime]` - Simulator builds (Intel Mac) | ||
|
|
||
| ### CI/CD | ||
|
|
||
| The CI workflow (`mobile-build.yml`) builds ONNX Runtime from source and caches it. The cache key includes the version number, so updating `ORT_VERSION` will trigger a rebuild. | ||
|
|
||
| ## Cleaning Up | ||
|
|
||
| To free disk space after testing: | ||
|
|
||
| ```bash | ||
| # Remove build directory (keeps the built xcframework) | ||
| rm -rf frontend/src-tauri/onnxruntime-build | ||
|
|
||
| # Remove everything (requires rebuilding) | ||
| rm -rf frontend/src-tauri/onnxruntime-build frontend/src-tauri/onnxruntime-ios | ||
| ``` | ||
|
|
||
| ## Related Documentation | ||
|
|
||
| - [troubleshooting-ios-build.md](./troubleshooting-ios-build.md) - arm64-sim architecture fix | ||
| - [tts-research.md](./tts-research.md) - TTS implementation details |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.