Fangjun Kuang
Committed by GitHub

Add iOS TTS example for MatchaTTS (#1736)

@@ -127,9 +127,44 @@ func getTtsFor_zh_en_melo_tts() -> SherpaOnnxOfflineTtsWrapper { @@ -127,9 +127,44 @@ func getTtsFor_zh_en_melo_tts() -> SherpaOnnxOfflineTtsWrapper {
127 return SherpaOnnxOfflineTtsWrapper(config: &config) 127 return SherpaOnnxOfflineTtsWrapper(config: &config)
128 } 128 }
129 129
  130 +func getTtsFor_matcha_icefall_zh_baker() -> SherpaOnnxOfflineTtsWrapper {
  131 + // please see https://k2-fsa.github.io/sherpa/onnx/tts/pretrained_models/matcha.html#matcha-icefall-zh-baker-chinese-1-female-speaker
  132 +
  133 + let acousticModel = getResource("model-steps-3", "onnx")
  134 + let vocoder = getResource("hifigan_v2", "onnx")
  135 +
  136 + let tokens = getResource("tokens", "txt")
  137 + let lexicon = getResource("lexicon", "txt")
  138 +
  139 + let dictDir = resourceURL(to: "dict")
  140 +
  141 + let numFst = getResource("number", "fst")
  142 + let dateFst = getResource("date", "fst")
  143 + let phoneFst = getResource("phone", "fst")
  144 + let ruleFsts = "\(dateFst),\(phoneFst),\(numFst)"
  145 +
  146 + let matcha = sherpaOnnxOfflineTtsMatchaModelConfig(
  147 + acousticModel: acousticModel,
  148 + vocoder: vocoder,
  149 + lexicon: lexicon,
  150 + tokens: tokens,
  151 + dictDir: dictDir
  152 + )
  153 +
  154 + let modelConfig = sherpaOnnxOfflineTtsModelConfig(matcha: matcha)
  155 + var config = sherpaOnnxOfflineTtsConfig(
  156 + model: modelConfig,
  157 + ruleFsts: ruleFsts
  158 + )
  159 +
  160 + return SherpaOnnxOfflineTtsWrapper(config: &config)
  161 +}
  162 +
130 func createOfflineTts() -> SherpaOnnxOfflineTtsWrapper { 163 func createOfflineTts() -> SherpaOnnxOfflineTtsWrapper {
131 // Please enable only one of them 164 // Please enable only one of them
132 165
  166 + // return getTtsFor_matcha_icefall_zh_baker()
  167 +
133 return getTtsFor_en_US_amy_low() 168 return getTtsFor_en_US_amy_low()
134 169
135 // return getTtsForVCTK() 170 // return getTtsForVCTK()