Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 280
alexkaessner Avatar asked May 18 '20 20:05

alexkaessner


People also ask

Can you download additional Siri voices?

Tap each voice to hear a preview. Switching to a new voice will require your iPhone or iPad to download the necessary files to make the swap. You'll see Downloading… with a loading animation on each voice as you select it. Once the download is complete, your device will start using that voice going forward.

How do I change the voice of Siri on OSX?

Go to Settings > Siri & Search. Tap Language to change the language that Siri uses for requests and responses. Tap Siri Voice to change the voice that Siri speaks.

How do I change the voice on my Mac terminal?

Choose a voice On your Mac, choose Apple menu > System Preferences, click Accessibility , then click Spoken Content. Click the System Voice pop-up menu, then choose a voice. To adjust how fast the voice speaks, drag the Speaking Rate slider. Click Play to test the voice and speaking rate.

Is Siri a speech synthesizer?

Siri is a personal assistant that communicates using speech synthesis. Starting in iOS 10 and continuing with new features in iOS 11, we base Siri voices on deep learning. The resulting voices are more natural, smoother, and allow Siri's personality to shine through.


1 Answers

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.

  • Both NSSpeechSynthesizer and AVSpeechSynthesizer do utilize SpeechSynthesis.framework (included in the ApplicationServices.framework).
  • Quickly checked it and the function BuildDefaultVoiceList(bool) checks bundle identifier (via PermitAllVoices which compares it with com.apple.VoiceOverUtility, com.apple.VoiceOver, com.apple.VoiceOverUtilityCacheBuilder).
  • There're other checks probably.

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:

  • speechSynthesizer(_:didStart:)
  • speechSynthesizer(_:willSpeakRangeOfSpeechString:utterance:)
  • speechSynthesizer(_:didFinish:)

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

  • System Preferences - Accessibility - Speech
  • System Voice - click & scroll down & select Customize...
  • Select additional voice to install
like image 166
zrzka Avatar answered Sep 21 '22 04:09

zrzka