TTS
Extend Speech Synthesis with personal and custom voices
Creating an audio unit extension
It describes how to set a parameter from the host app
xcode, create project, select ios or macos, select Audio Unit Extension App
Product name: sherpa-onnx-tts
Team: None
Organization identifier: org.k2-fsa
Organization name: Next-gen Kaldi
Audio unit type: Speech synthesizer
Subtype code: k2k2
Manufacturer code: k2k2
User interface: No user interface
Include tests: Don't check it
example:
public override var internalRenderBlock: AUInternalRenderBlock {
return { [weak self]
actionFlags, timestamp, frameCount, outputBusNumber, outputAudioBufferList, _, _ in
guard let self else { return kAudio_ParamError }
// This is the audio buffer we are going to fill up
var unsafeBuffer = UnsafeMutableAudioBufferListPointer(outputAudioBufferList)[0]
let frames = unsafeBuffer.mData!.assumingMemoryBound(to: Float32.self)
var sourceBuffer = UnsafeMutableAudioBufferListPointer(self.currentBuffer!.mutableAudioBufferList)[0]
let sourceFrames = sourceBuffer.mData!.assumingMemoryBound(to: Float32.self)
for frame in 0..<frameCount {
if frames.count > frame && sourceFrames.count > self.framePosition {
frames[Int(frame)] = sourceFrames[Int(self.framePosition)]
self.framePosition += 1
if self.framePosition >= self.currentBuffer!.frameLength {
break
}
}
}
return noErr
}