AVSpeechUtterance maximum volume really quiet and rate really fast

落花浮王杯 提交于 2019-12-04 04:32:11
Garry

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

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

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