swiftmacosavfoundationavspeechsynthesizernsspeechsynthesizer

NSSpeechSynthesizer get Siri voices on macOS


Is there a way to get the Siri voices for NSSpeechSynthesizer? NSSpeechSynthesizer.availableVoices() does not list them, but maybe there is an undocumented trick or something?

I've also tried to use AVSpeech​Synthesizer, even tough it should be available on macOS 10.14+, I couldn't get it to read out loud …

I've used a Playground to test this with the following code from NSHipster:

import Cocoa
import AVFoundation

let string = "Hello, World!"
let utterance = AVSpeechUtterance(string: string)

let synthesizer = AVSpeechSynthesizer()
synthesizer.speak(utterance)

Solution

  • Siri voice

    I'm not aware of any trick to make the Siri voice available and I'm afraid it's impossible to make it working via public API.

    All the voices are stored in the /System/Library/Speech/Voices folder. Tried to copy the voice, change Info.plist values to make it look like another voice, but still not available/working.

    How far do you want to go? Do you want to disable SIP, modify framework, preload your stuff, ... Is it worth it?

    AVSpeech​Synthesizer on macOS

    It works, but it's buggy and you have to kill the service from time to time.

    List of available voices

    AVSpeechSynthesisVoice.speechVoices().forEach { voice in
        print("Name: \(voice.name) Language: \(voice.language) Identifier: \(voice.identifier)")
    }
    

    Speak

    let utterance = AVSpeechUtterance(string: "Ahoj, jak se máš?")
    utterance.voice = AVSpeechSynthesisVoice(identifier: "com.apple.speech.synthesis.voice.zuzana.premium")
    
    let synthesizer = AVSpeechSynthesizer()
    synthesizer.speak(utterance)
    

    Doesn't speak?

    All the following methods (delegate) are called when you call speak(utterance) and it works as it should:

    Something's wrong if you get just the speechSynthesizer(_:didCancel:) method call and you have to kill the speechsynthesisd process:

    kill `pgrep speechsynthesisd`
    

    Then try again, it fixes the issue for me.

    Additional voices installation