AVSpeechUserrance最大音量真的很安静,速度真的很快

我正在为我的应用程序添加语音提示,并在iOS 7中testingAVSpeechUtterance,但默认语速非常快。 最低语速比较容易理解。 但是1的最大音量值太安静了! 我在iPhone 4上进行了testing,音量一路上升。 有些东西一定是错的,否则这怎么可能呢?

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

@ tmr的post在这里为我解决了这个问题:

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

这工作对我来说(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.") } 

iOS 8与iOS 9不同:

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

对于Swift 3来说 (解决数量问题)

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

我的问题是固定的设置模式为AVAudioSessionModeDefaultAVAudioSessionModeSpokenAudio

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

速率只是一个浮点值,常数是为了方便而提供的。 尝试使用[说话setRate:AVSpeechUtteranceMaximumSpeechRate * .25];