I was toying with adding speech cues to my app and was testing out AVSpeechUtterance in iOS 7, but the default speech rate is REALLY fast. The minimum speech rate is much more understandable. But the maximum volume value of 1 is soooo quiet! I tested it on my iPhone 4 with the volume turned all the way up. Something must be wrong or else how would this be usuable at all.
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
NSString *mystring = [NSString stringWithFormat:@"Talk String Here %@",myObject.name];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:mystring];
[utterance setRate:AVSpeechUtteranceMinimumSpeechRate];
[utterance setVolume:1];
[synthesizer speakUtterance:utterance];
This worked for me ( Swift 3.0 )
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: AVAudioSessionCategoryOptions.defaultToSpeaker)
} catch {
print("audioSession properties weren't set because of an error.")
}
@tmr's post here resolved this for me:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker
error:nil];
For Swift 5 you can try this (add it before the synthesizer initialization):
let audioSession = AVAudioSession.sharedInstance()
try? audioSession.setCategory(AVAudioSession.Category.playAndRecord, mode: AVAudioSession.Mode.default, options: AVAudioSession.CategoryOptions.defaultToSpeaker)
try? audioSession.setMode(AVAudioSession.Mode.spokenAudio)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With