ios - AVSpeechUtterance 静音模式下的发音

标签 ios objective-c iphone avspeechsynthesizer onutterancecompleted

我正在使用 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/

相关文章:

ios - 获取Major/Minor值 'without'监控?

ios - 在谷歌地图上难以获得 X 和 Y 中标记的位置?

ios - 在我的 ios 应用程序中获取用户在他/她的 iphone 中使用的苹果 ID

objective-c - 为 dispatch_queue_t 属性调用 getter 会导致崩溃

iphone - Snow Leopard/Xcode 升级后 Xcode 的共享工作组 'Unreachable'

ios - 将 UITableView 添加到现有的 ViewController

objective-c - Objective-C 中按位数智能舍入

iphone - 使用 MKCoordinateRegion 将 MKMapView 聚焦在 NSString 经纬度坐标上

ios - 在应用商店中仅限制 Ipad 1

ios - 确定与登录到 iOS 设备的 Apple ID 关联的国家/地区