Skip to content

Otosaku/KokoroTTS-iOS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KokoroTTS-iOS

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!

Installation

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.

Required Resources

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

Usage

Initialize the Pipeline

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
)

Generate Speech

// 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)

Available Languages

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

Available Voices

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

Example Project

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:

  1. Open Example/Example.xcodeproj in Xcode
  2. Build and run on an iOS device

Requirements

  • iOS 16.0+
  • Swift 6.0+
  • Xcode 16.0+

License

MIT License