Skip to content

Commit

Permalink
Add iOS TTS example for MatchaTTS (#1736)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Jan 20, 2025
1 parent 9d6c0e5 commit e2f096b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ios-swiftui/SherpaOnnxTts/SherpaOnnxTts/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,44 @@ func getTtsFor_zh_en_melo_tts() -> SherpaOnnxOfflineTtsWrapper {
return SherpaOnnxOfflineTtsWrapper(config: &config)
}

func getTtsFor_matcha_icefall_zh_baker() -> SherpaOnnxOfflineTtsWrapper {
// please see https://k2-fsa.github.io/sherpa/onnx/tts/pretrained_models/matcha.html#matcha-icefall-zh-baker-chinese-1-female-speaker

let acousticModel = getResource("model-steps-3", "onnx")
let vocoder = getResource("hifigan_v2", "onnx")

let tokens = getResource("tokens", "txt")
let lexicon = getResource("lexicon", "txt")

let dictDir = resourceURL(to: "dict")

let numFst = getResource("number", "fst")
let dateFst = getResource("date", "fst")
let phoneFst = getResource("phone", "fst")
let ruleFsts = "\(dateFst),\(phoneFst),\(numFst)"

let matcha = sherpaOnnxOfflineTtsMatchaModelConfig(
acousticModel: acousticModel,
vocoder: vocoder,
lexicon: lexicon,
tokens: tokens,
dictDir: dictDir
)

let modelConfig = sherpaOnnxOfflineTtsModelConfig(matcha: matcha)
var config = sherpaOnnxOfflineTtsConfig(
model: modelConfig,
ruleFsts: ruleFsts
)

return SherpaOnnxOfflineTtsWrapper(config: &config)
}

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

// return getTtsFor_matcha_icefall_zh_baker()

return getTtsFor_en_US_amy_low()

// return getTtsForVCTK()
Expand Down

0 comments on commit e2f096b

Please sign in to comment.