我正在使用 AVSpeechUtterance 来朗读给定的文本。我正在使用下面的代码,并且在“iPhone 铃声模式”下工作正常,但是当我将 iPhone 更改为“静音模式”时,话语声音变得静音。当它是“静音模式”时,我听不到说话的声音。我应该怎么做才能听到“静音模式”中的语音。
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:@"Hello World"];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
[utterance setRate:AVSpeechUtteranceMinimumSpeechRate];
[utterance setVolume:1];
[self.speechSynthesizer speakUtterance:utterance];
最佳答案
在您的代码之前添加以下代码。您也可以在 appDelegate 中编写相同的代码。
NSError *setCategoryErr = nil;
NSError *activationErr = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];
关于ios - AVSpeechUtterance 静音模式下的发音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25105283/