AVSpeechUtterance maximum volume really quiet and rate really fast

删除回忆录丶 提交于 2019-12-21 12:17:36

问题


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];

回答1:


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.")   
}



回答2:


@tmr's post here resolved this for me:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord  
                       withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker
                                       error:nil];



回答3:


iOS 8 differs to iOS 9:

AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:utteranceString];
if([iOSVersionDetector isiOS9OrHigher])
    utterance.rate = AVSpeechUtteranceDefaultSpeechRate;
else
    utterance.rate = 0.1f;



回答4:


For Swift 3 do (to fix the volume issue)

let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: AVAudioSessionCategoryOptions.defaultToSpeaker)



回答5:


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)



回答6:


The rate is just a float value and the constants are provided for convenience. Try using [utterance setRate:AVSpeechUtteranceMaximumSpeechRate*.25];



来源:https://stackoverflow.com/questions/20461178/avspeechutterance-maximum-volume-really-quiet-and-rate-really-fast

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!