Reputation: 3454
I have a Text to Speech App and all is good, but I was looking for a voice.
In Settings/Accessibility/Voice Over/Speech/Voice there is a list of voices. I wanted to select one of those, for example "Susan (Enhanced)". How would I go about doing that?
I am new to Text to Speech and AVSpeechSynthesizer so I was hoping for some advice how to select that voice?
When I try it in General/Settings it sounds good, but when I select, what I thought was that voice it in my App, it sounds different. This happens with all of the voices I tried.
Here is the code I used to speak the text:
for voice in AVSpeechSynthesisVoice.speechVoices()
{
print("\(voice.name)")
if voice.name == "Susan (Enhanced)" {
self.voiceToUse = voice
}
}
let textToSpeak = self.tvTextToSpeak.text
if (!textToSpeak!.isEmpty)
{
let speechSynthesizer = AVSpeechSynthesizer()
let speechUtterance: AVSpeechUtterance = AVSpeechUtterance(string: textToSpeak!)
speechUtterance.voice = self.voiceToUse
speechSynthesizer.speak(speechUtterance)
}
So if I use the same text as the example in the iOS settings it sounds different in my App, why?
Thanks for any clarification.
Upvotes: 3
Views: 3134
Reputation: 2078
Set speechUtterance.prefersAssistiveTechnologySettings = true
to use Spoken content selected voice in your iPhone. And you don't need to specify what voice to use in this case.
A Boolean that specifies whether assistive technology settings take precedence over the property values of this utterance.
Upvotes: 1
Reputation: 53870
Many of the voices, especially the "enhanced" ones, need to be downloaded on the device first. On your device go to Settings->Accessibility->Spoken Content->Voices, and make sure that you download the voice that you're trying to use.
I was able to use "Samantha (Enhanced)", once I downloaded it.
Upvotes: 0