Fangjun Kuang
Committed by GitHub

Add iOS demo for Kokoro TTS 1.0 (#1812)

@@ -180,10 +180,43 @@ func getTtsFor_kokoro_en_v0_19() -> SherpaOnnxOfflineTtsWrapper { @@ -180,10 +180,43 @@ func getTtsFor_kokoro_en_v0_19() -> SherpaOnnxOfflineTtsWrapper {
180 return SherpaOnnxOfflineTtsWrapper(config: &config) 180 return SherpaOnnxOfflineTtsWrapper(config: &config)
181 } 181 }
182 182
  183 +func getTtsFor_kokoro_multi_lang_v1_0() -> SherpaOnnxOfflineTtsWrapper {
  184 + // please see https://k2-fsa.github.io/sherpa/onnx/tts/pretrained_models/kokoro.html
  185 +
  186 + let model = getResource("model", "onnx")
  187 + let voices = getResource("voices", "bin")
  188 +
  189 + // tokens.txt
  190 + let tokens = getResource("tokens", "txt")
  191 +
  192 + let lexicon_en = getResource("lexicon-us-en", "txt")
  193 + let lexicon_zh = getResource("lexicon-zh", "txt")
  194 + let lexicon = "\(lexicon_en),\(lexicon_zh)"
  195 +
  196 + // in this case, we don't need lexicon.txt
  197 + let dataDir = resourceURL(to: "espeak-ng-data")
  198 + let dictDir = resourceURL(to: "dict")
  199 +
  200 + let numFst = getResource("number-zh", "fst")
  201 + let dateFst = getResource("date-zh", "fst")
  202 + let phoneFst = getResource("phone-zh", "fst")
  203 + let ruleFsts = "\(dateFst),\(phoneFst),\(numFst)"
  204 +
  205 + let kokoro = sherpaOnnxOfflineTtsKokoroModelConfig(
  206 + model: model, voices: voices, tokens: tokens, dataDir: dataDir,
  207 + dictDir: dictDir, lexicon: lexicon)
  208 + let modelConfig = sherpaOnnxOfflineTtsModelConfig(kokoro: kokoro)
  209 + var config = sherpaOnnxOfflineTtsConfig(model: modelConfig)
  210 +
  211 + return SherpaOnnxOfflineTtsWrapper(config: &config)
  212 +}
  213 +
183 func createOfflineTts() -> SherpaOnnxOfflineTtsWrapper { 214 func createOfflineTts() -> SherpaOnnxOfflineTtsWrapper {
184 // Please enable only one of them 215 // Please enable only one of them
185 216
186 - return getTtsFor_kokoro_en_v0_19() 217 + return getTtsFor_kokoro_multi_lang_v1_0()
  218 +
  219 + // return getTtsFor_kokoro_en_v0_19()
187 220
188 // return getTtsFor_matcha_icefall_zh_baker() 221 // return getTtsFor_matcha_icefall_zh_baker()
189 222