Ios AVSpeechOutrance最大音量非常安静,速度非常快

Ios AVSpeechOutrance最大音量非常安静,速度非常快,ios,ios7,text-to-speech,Ios,Ios7,Text To Speech,我当时正在尝试在我的应用程序中添加语音提示,并在iOS 7中测试了AVSpeechEarth,但默认的语音速率非常快。最低语速更容易理解。但是最大体积值1非常安静!我在iPhone4上测试了它,音量一直调高。一定是出了什么问题,否则这怎么会有用呢 AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init]; NSString *mystring = [NSString stringWithFor

我当时正在尝试在我的应用程序中添加语音提示,并在iOS 7中测试了AVSpeechEarth,但默认的语音速率非常快。最低语速更容易理解。但是最大体积值1非常安静!我在iPhone4上测试了它,音量一直调高。一定是出了什么问题,否则这怎么会有用呢

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

速率只是一个浮点值,提供常数是为了方便。 尝试使用[话语设置速率:avspeechoutancemaximumspeechrate*.25]

@tmr的帖子为我解决了这个问题:

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

iOS 8与iOS 9不同:

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

对于Swift 3do(解决批量问题)

这对我很有用(Swift 3.0)


我的问题已修复,将模式设置为
AVAudioSessionModeDefault
AVAudioSessionModeSpokenAudio

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

对于Swift 5,您可以尝试以下操作(在合成器初始化之前添加):


你有没有找到解决办法?我在音量方面也遇到了同样的问题。不,我没有,但我也没有处理它。似乎没有一个好的解决方案。我把对我有用的东西贴在下面()。也许这会有帮助?@Glavin001关于音量,你找到什么解决办法了吗?我被困在这里非常严重。未找到任何SOUTION
rate
已经是一个浮动值,范围为0.0到1.0,其中
avspeechutranceminimumspeechrate
=0.0和
avspeechutrancemaximumspeechrate
=1.0。因为
avspeechutranceminimumspeechrate
是0.0,所以它再乘以任何数字都是0.0。你刚才为我节省了很多时间!!谢谢这对我来说很管用,但当我将耳机连接到iPhone时,只有耳机的一侧有声音,另一侧没有声音。有线索吗?
let audioSession = AVAudioSession.sharedInstance()  
do {
  try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: AVAudioSessionCategoryOptions.defaultToSpeaker)  
} catch {   
  print("audioSession properties weren't set because of an error.")   
}
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: .defaultToSpeaker)
try audioSession.setMode(AVAudioSessionModeSpokenAudio)
        let audioSession = AVAudioSession.sharedInstance()
        try? audioSession.setCategory(AVAudioSession.Category.playAndRecord, mode: AVAudioSession.Mode.default, options: AVAudioSession.CategoryOptions.defaultToSpeaker)
        try? audioSession.setMode(AVAudioSession.Mode.spokenAudio)