【问题标题】:The volume of AVSpeechSynthesizer (Text to Speech) playback increases by itself, ONLY on iPhone7AVSpeechSynthesizer (Text to Speech) 播放的音量会自行增加,仅限 iPhone7
【发布时间】:2017-03-25 20:15:13
【问题描述】:

我的 iOS10 应用程序执行文本到语音和语音识别。发生这种情况时,它会暂停其他应用程序的音频,并在 ASR/TTS 结束时通知其他应用程序,以便他们可以恢复音频。 在 iPhone5 和 6 上一切正常。

问题出在 iPhone7s 上:口语短语的音量一开始非常低,到短语结尾时声音更大。为什么?

我会提供一些我的代码以防万一,因为这似乎是一个 iOS 错误。

音频会话代码:

-(AVAudioSessionCategoryOptions)indigoAudioBehaviorOptions:(AVAudioSession *)s{
    AVAudioSessionCategoryOptions audioIOoptions = [s categoryOptions];
    audioIOoptions |= AVAudioSessionCategoryOptionDefaultToSpeaker;
    audioIOoptions |= AVAudioSessionCategoryOptionAllowBluetooth;
    audioIOoptions |= AVAudioSessionCategoryOptionAllowBluetoothA2DP;
    return audioIOoptions;
}
-(void)notifyIOSthatOtherAppsCanResumeAudioPlayback{
    NSError *err;
    [myAudioSession setActive: NO
                  withOptions: AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation
                        error: &err];
    if(err!=nil){
        NSLog(@"audioIsFreeNotificationForIOS ERROR: %@",err.description);
    }
}


myAudioSession = [AVAudioSession sharedInstance];
NSError *err;
[myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions: [self indigoAudioBehaviorOptions:indigoAudioSession] error:&err];

文字转语音代码:

nativeVocalizer = [[AVSpeechSynthesizer alloc] init];
nativeVocalizer.delegate = self;
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:stringToSpeak];
[utterance setVoice:[AVSpeechSynthesisVoice voiceWithLanguage:lang]];
[nativeVocalizer speakUtterance:utterance];

【问题讨论】:

    标签: ios objective-c avaudiosession avspeechsynthesizer avspeechutterance


    【解决方案1】:

    这可能是由于活动音频会话AVAudioSession 模式而发生的。

    我没有发生这种行为的唯一模式是使用模式AVAudioSessionModeMeasurement

    【讨论】:

      猜你喜欢
      • 2021-10-26
      • 2013-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-30
      • 2019-08-11
      • 1970-01-01
      相关资源
      最近更新 更多