Skip to content

Commit e2f096b

Browse files
authored
Add iOS TTS example for MatchaTTS (#1736)
1 parent 9d6c0e5 commit e2f096b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

ios-swiftui/SherpaOnnxTts/SherpaOnnxTts/ViewModel.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,44 @@ func getTtsFor_zh_en_melo_tts() -> SherpaOnnxOfflineTtsWrapper {
127127
return SherpaOnnxOfflineTtsWrapper(config: &config)
128128
}
129129

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+
130163
func createOfflineTts() -> SherpaOnnxOfflineTtsWrapper {
131164
// Please enable only one of them
132165

166+
// return getTtsFor_matcha_icefall_zh_baker()
167+
133168
return getTtsFor_en_US_amy_low()
134169

135170
// return getTtsForVCTK()

0 commit comments

Comments
 (0)