I am unable to get AVSpeechSynthesizer to write or to acknowledge the delegate did finish.
when I call the function, it merely speaks the string aloud.
I am running on macOS 10.15.7 (Catalina).
What am I missing?
when I call the function, it merely speaks the string aloud.
I am running on macOS 10.15.7 (Catalina).
What am I missing?
Code Block language code-block SpeakerTest().writeToBuffer("This should write to buffer and call didFinish delegate.") class SpeakerTest: NSObject, AVSpeechSynthesizerDelegate { let synth = AVSpeechSynthesizer() override init() { super.init() synth.delegate = self } func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) { print("Utterance didFinish") } func speak(_ string: String) { let utterance = AVSpeechUtterance(string: string) synth.speak(utterance) } func writeToBuffer(_ string: String) { let utterance = AVSpeechUtterance(string: string) synth.write(utterance) { (buffer: AVAudioBuffer) in guard let pcmBuffer = buffer as? AVAudioPCMBuffer else { fatalError("unknown buffer type: \(buffer)") } if pcmBuffer.frameLength == 0 { print("buffer is empty") } else { print("buffer has content \(buffer)") } } } }