✨ New in 1.0.5: Voice styles are moved out of the library to the integrating application. Please check Kokoro Test App how to use them.
Kokoro is a high-quality TTS (text-to-speech) model, providing faster than real-time English audio generation.
NOTE: This is a SPM package of the TTS engine. For an application integrating Kokoro and showing how the neural speech synthesis works, please see KokoroTestApp project.
Kokoro TTS port is based on the great work done in MLX-Audio project, where the model was ported from PyTorch to MLX Python. This project ports the MLX Python code to MLX Swift.
Currently the library generates audio ~3.3 times faster than real-time on the release build on iPhone 13 Pro after warm up / first run.
- iOS 18.0+
- macOS 15.0+
- (Other Apple platforms may work as well)
Add KokoroSwift to your project using Swift Package Manager:
dependencies: [
.package(url: "https://github.com/mlalma/kokoro-ios.git", from: "1.0.0")
]
Then add it to your target:
.target(
name: "YourTarget",
dependencies: [
.product(name: "KokoroSwift", package: "kokoro-ios")
]
)
import KokoroSwift
// Initialize the TTS engine
let modelPath = URL(fileURLWithPath: "path/to/your/model")
let tts = KokoroTTS(modelPath: modelPath, g2p: .misaki)
// Generate speech
let voiceEmbedding = ... // See KokoroTestApp on how to get a voice style as an `MLXArray`
let text = "Hello, this is a test of Kokoro TTS."
let audioBuffer = try tts.generateAudio(voice: voiceEmbedding, language: .enUS, text: text)
// audioBuffer now contains the synthesized speech
.misaki
- MisakiSwift, default G2P processor.espeak
- eSpeakNG, an alternative G2P processor (commented out in current version)
You'll need to provide your own Kokoro TTS model file due to its large size as well as voice style. Please see example project Kokoro Test App how they can be included as a part of the application package.
This package depends on:
- MLX Swift - Apple's MLX framework for Swift
- MisakiSwift - G2P processor
- MLXUtilsLibrary - Utility library
This project is licensed under MIT License - see the LICENSE file for details.