class MyClass { func playSamples(samples: [Float]) { print("Play \(samples.count) samples") } } func run() { let acousticModel = "./matcha-icefall-zh-baker/model-steps-3.onnx" let vocoder = "./vocos-22khz-univ.onnx" let lexicon = "./matcha-icefall-zh-baker/lexicon.txt" let tokens = "./matcha-icefall-zh-baker/tokens.txt" let dictDir = "./matcha-icefall-zh-baker/dict" let ruleFsts = "./matcha-icefall-zh-baker/phone.fst,./matcha-icefall-zh-baker/date.fst,./matcha-icefall-zh-baker/number.fst" let matcha = sherpaOnnxOfflineTtsMatchaModelConfig( acousticModel: acousticModel, vocoder: vocoder, lexicon: lexicon, tokens: tokens, dictDir: dictDir ) let modelConfig = sherpaOnnxOfflineTtsModelConfig(matcha: matcha, debug: 0) var ttsConfig = sherpaOnnxOfflineTtsConfig(model: modelConfig, ruleFsts: ruleFsts) let myClass = MyClass() // We use Unretained here so myClass must be kept alive as the callback is invoked // // See also // https://medium.com/codex/swift-c-callback-interoperability-6d57da6c8ee6 let arg = Unmanaged.passUnretained(myClass).toOpaque() let callback: TtsCallbackWithArg = { samples, n, arg in let o = Unmanaged.fromOpaque(arg!).takeUnretainedValue() var savedSamples: [Float] = [] for index in 0..