Skip to content

Commit a2650b7

Browse files
authored
Add iOS example for Kokoro TTS (#1737)
1 parent e2f096b commit a2650b7

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

ios-swiftui/SherpaOnnxTts/SherpaOnnxTts/ViewModel.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,34 @@ func getTtsFor_matcha_icefall_zh_baker() -> SherpaOnnxOfflineTtsWrapper {
160160
return SherpaOnnxOfflineTtsWrapper(config: &config)
161161
}
162162

163+
func getTtsFor_kokoro_en_v0_19() -> SherpaOnnxOfflineTtsWrapper {
164+
// please see https://k2-fsa.github.io/sherpa/onnx/tts/pretrained_models/kokoro.html#kokoro-en-v0-19-english-11-speakers
165+
166+
let model = getResource("model", "onnx")
167+
let voices = getResource("voices", "bin")
168+
169+
// tokens.txt
170+
let tokens = getResource("tokens", "txt")
171+
172+
// in this case, we don't need lexicon.txt
173+
let dataDir = resourceURL(to: "espeak-ng-data")
174+
175+
let kokoro = sherpaOnnxOfflineTtsKokoroModelConfig(
176+
model: model, voices: voices, tokens: tokens, dataDir: dataDir)
177+
let modelConfig = sherpaOnnxOfflineTtsModelConfig(kokoro: kokoro)
178+
var config = sherpaOnnxOfflineTtsConfig(model: modelConfig)
179+
180+
return SherpaOnnxOfflineTtsWrapper(config: &config)
181+
}
182+
163183
func createOfflineTts() -> SherpaOnnxOfflineTtsWrapper {
164184
// Please enable only one of them
165185

186+
return getTtsFor_kokoro_en_v0_19()
187+
166188
// return getTtsFor_matcha_icefall_zh_baker()
167189

168-
return getTtsFor_en_US_amy_low()
190+
// return getTtsFor_en_US_amy_low()
169191

170192
// return getTtsForVCTK()
171193

0 commit comments

Comments
 (0)