Skip to content

Commit

Permalink
Add iOS example for Kokoro TTS (#1737)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Jan 20, 2025
1 parent e2f096b commit a2650b7
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ios-swiftui/SherpaOnnxTts/SherpaOnnxTts/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,34 @@ func getTtsFor_matcha_icefall_zh_baker() -> SherpaOnnxOfflineTtsWrapper {
return SherpaOnnxOfflineTtsWrapper(config: &config)
}

func getTtsFor_kokoro_en_v0_19() -> SherpaOnnxOfflineTtsWrapper {
// please see https://k2-fsa.github.io/sherpa/onnx/tts/pretrained_models/kokoro.html#kokoro-en-v0-19-english-11-speakers

let model = getResource("model", "onnx")
let voices = getResource("voices", "bin")

// tokens.txt
let tokens = getResource("tokens", "txt")

// in this case, we don't need lexicon.txt
let dataDir = resourceURL(to: "espeak-ng-data")

let kokoro = sherpaOnnxOfflineTtsKokoroModelConfig(
model: model, voices: voices, tokens: tokens, dataDir: dataDir)
let modelConfig = sherpaOnnxOfflineTtsModelConfig(kokoro: kokoro)
var config = sherpaOnnxOfflineTtsConfig(model: modelConfig)

return SherpaOnnxOfflineTtsWrapper(config: &config)
}

func createOfflineTts() -> SherpaOnnxOfflineTtsWrapper {
// Please enable only one of them

return getTtsFor_kokoro_en_v0_19()

// return getTtsFor_matcha_icefall_zh_baker()

return getTtsFor_en_US_amy_low()
// return getTtsFor_en_US_amy_low()

// return getTtsForVCTK()

Expand Down

0 comments on commit a2650b7

Please sign in to comment.