Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Siri voice selected by user in Settings in iOS 11

I am writing an app that includes text-to-speech using AVSpeechSynthesizer. The code for generating the utterance and using the speech synthesizer has been working fine.

let utterance = AVSpeechUtterance(string: text)
utterance.voice = currentVoice
speechSynthesizer.speak(utterance)

Now with iOS 11, I want to match the voice to the one selected by the user in the phone's Settings app, but I do not see any way to get that setting.

I have tried getting the list of installed voices and looking for one that has a quality of .enhanced, but sometimes there is no enhanced voice installed, and even when there is, it may or may not be the voice selected by the user in the Settings app.

static var enhanced: AVSpeechSynthesisVoice? {
    for voice in AVSpeechSynthesisVoice.speechVoices() {
        if voice.quality == .enhanced {
            return voice
        }
    }

    return nil
}

The questions are twofold:

  1. How can I determine which voice has been selected by the user in the Setting app?
  2. Why on some iOS 11 phones that are using the new Siri voice am I not finding an "enhanced" voice installed?

enter image description here

like image 232
picciano Avatar asked Sep 20 '17 22:09

picciano


People also ask

How do you change Siri settings on iPhone 11?

Change Siri settings for a specific app You can change which apps you can use with Siri, as well as the Siri Suggestions and Siri Shortcuts settings for any app. Go to Settings > Siri & Search, then scroll down and select an app. Turn settings on or off.

Who is the voice of Siri on iPhone 11?

Susan Alice Bennett (née Cameron, born July 31, 1949) is an American voice actress and a former backup singer for Roy Orbison and Burt Bacharach. She is best known as the female American voice of Apple's Siri personal assistant, since the service was introduced on the iPhone 4S on October 4, 2011.

How do I access Siri on my iPhone 11?

If you want to activate Siri with your voice: Turn on Listen for “Hey Siri.” If you want to activate Siri with a button: Turn on Press Side Button for Siri (on an iPhone with Face ID) or Press Home for Siri (on an iPhone with a Home button).


2 Answers

I suppose if there was a method available for selecting the same voice as in the Settings app, it'd be shown on the documentation for class AVSpeechSynthesisVoice under the Finding Voices topic. Jumping to the definition in code of AVSpeechSynthesisVoice, I couldn’t find any different methods to retrieve voices.

Here's my workaround on getting an enhanced voice over for the app I am working on:

Enhanced versions of voices are probably not present in new iOS devices by default in order to save storage. Iterating thru available voices on my brand new iPhone, I only found Default quality voices such as: [AVSpeechSynthesisVoice 0x1c4e11cf0] Language: en-US, Name: Samantha, Quality: Default [com.apple.ttsbundle.Samantha-compact]

I found this article on how to enable additional voice over voices and downloaded the one named “Samantha (Enhanced)” among them. Checking the list of available voices again, I noticed the following addition: [AVSpeechSynthesisVoice 0x1c4c03060] Language: en-US, Name: Samantha (Enhanced), Quality: Enhanced [com.apple.ttsbundle.Samantha-premium]

As of now I was able to select an enhanced language on Xcode. Given that the AVSpeechSynthesisVoice.currentLanguageCode() method exposes the currently selected language, ran the following code to make a selection of the first enhanced voice I could find. If no enhanced version was available I’d just pick the available default (the code below is for a VoiceOver custom class I am creating to handle all speeches in my app. The piece below updates its voice variable).

var voice: AVSpeechSynthesisVoice!

for availableVoice in AVSpeechSynthesisVoice.speechVoices(){
        if ((availableVoice.language == AVSpeechSynthesisVoice.currentLanguageCode()) &&
            (availableVoice.quality == AVSpeechSynthesisVoiceQuality.enhanced)){ // If you have found the enhanced version of the currently selected language voice amongst your available voices... Usually there's only one selected.
            self.voice = availableVoice
            print("\(availableVoice.name) selected as voice for uttering speeches. Quality: \(availableVoice.quality.rawValue)")
        }
}
if let selectedVoice = self.voice { // if sucessfully unwrapped, the previous routine was able to identify one of the enhanced voices
        print("The following voice identifier has been loaded: ",selectedVoice.identifier)
} else {
        self.voice = AVSpeechSynthesisVoice(language: AVSpeechSynthesisVoice.currentLanguageCode()) // load any of the voices that matches the current language selection for the device in case no enhanced voice has been found.

}

I am also hoping Apple will expose a method to directly load the selected language, but I hope this work around can serve you in the meantime. I guess Siri’s enhanced voice is downloaded on the go, so maybe this is the reason it takes so long to answer my voice commands :)

Best regards.

like image 50
Andre Guerra Avatar answered Oct 08 '22 14:10

Andre Guerra


It looks like the new Siri voice in iOS 11 isn't part of the AVSpeechSynthesis API, and isn't available to developers.

In macOS 10.13 High Sierra (which also gets the new voice), there seems to be a new SiriTTS framework that's probably related to this functionality, but it's in PrivateFrameworks so it doesn't have a developer API.

like image 2
rickster Avatar answered Oct 08 '22 15:10

rickster