Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVSpeechUtterance maximum volume really quiet and rate really fast

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];
like image 581
tettoffensive Avatar asked Dec 09 '13 00:12

tettoffensive


3 Answers

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.")   
}
like image 183
Guri S Avatar answered Nov 17 '22 03:11

Guri S


@tmr's post here resolved this for me:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord  
                       withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker
                                       error:nil];
like image 34
Glavin001 Avatar answered Nov 17 '22 04:11

Glavin001


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)
like image 1
Max Niagolov Avatar answered Nov 17 '22 04:11

Max Niagolov