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];
iOS 8 differs to iOS 9:
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:utteranceString];
if([iOSVersionDetector isiOS9OrHigher])
utterance.rate = AVSpeechUtteranceDefaultSpeechRate;
else
utterance.rate = 0.1f;
For Swift 3 do (to fix the volume issue)
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: AVAudioSessionCategoryOptions.defaultToSpeaker)
My problem was fixed setting the mode to AVAudioSessionModeDefault
or AVAudioSessionModeSpokenAudio
:
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: .defaultToSpeaker)
try audioSession.setMode(AVAudioSessionModeSpokenAudio)
The rate is just a float value and the constants are provided for convenience.
Try using [utterance setRate:AVSpeechUtteranceMaximumSpeechRate*.25];