Swift Package for text-to-speech on iOS using the Kokoro TTS model.
Note: Currently, the model is adapted and tested only for English (en_us, en_gb) and French (fr) languages. All other languages require preprocessor improvements. Contributors are welcome!
Add the package to your project via Swift Package Manager:
dependencies: [
.package(url: "https://github.com/Otosaku/KokoroTTS-iOS", from: "1.0.0")
]Or in Xcode: File → Add Package Dependencies... and enter the repository URL.
Before using the library, you need to download the following resources:
| Resource | Description | URL |
|---|---|---|
| TTS Models | Core ML models for speech synthesis | Download |
| G2P Vocab | Grapheme-to-phoneme vocabulary files | Download |
| POS Model | Part-of-speech tagging model | Download |
| Espeak Data | Espeak-ng phoneme data | Download |
import iOS_TTS
import CoreML
// Configure ML compute units (optional)
let configuration = MLModelConfiguration()
configuration.computeUnits = .all // or .cpuAndNeuralEngine, .cpuOnly
// Initialize the pipeline
let pipeline = try TTSPipeline(
modelPath: modelsDirectory, // URL to extracted TTS models
vocabURL: vocabDirectory, // URL to extracted G2P vocab
postaggerModelURL: posModelsDirectory, // URL to extracted POS model
language: .englishUS, // Language selection
espeakDataPath: espeakDataDirectory.path, // Path to espeak-ng data
configuration: configuration
)// Basic generation
let audioSamples = try await pipeline.generate(text: "Hello, world!")
// With options
let options = GenerationOptions(
style: .afHeart, // Voice style
speed: 1.0 // Speech speed
)
let audioSamples = try await pipeline.generate(text: "Hello, world!", options: options)| Language | Code | Status |
|---|---|---|
| English (US) | .englishUS |
Supported |
| English (GB) | .englishGB |
Supported |
| French | .french |
Supported |
| Spanish | .spanish |
Needs work |
| Italian | .italian |
Needs work |
| Portuguese | .portuguese |
Needs work |
| Hindi | .hindi |
Needs work |
| Japanese | .japanese |
Needs work |
| Chinese | .chinese |
Needs work |
English (US): afHeart, afAlloy, afAoede, afBella, afJessica, afKore, afNicole, afNova, afRiver, afSarah, afSky, amAdam, amEcho, amEric, amFenrir, amLiam, amMichael, amOnyx, amPuck, amSanta
English (GB): bfAlice, bfEmma, bfIsabella, bfLily, bmDaniel, bmFable, bmGeorge, bmLewis
French: ffSiwis
The repository includes an Example app that demonstrates:
- Downloading and extracting required resources
- Initializing the TTS pipeline
- Generating and playing speech
- Voice and language selection
To run the example:
- Open
Example/Example.xcodeprojin Xcode - Build and run on an iOS device
- iOS 16.0+
- Swift 6.0+
- Xcode 16.0+
MIT License