文字转语音在后台模式下不起作用

时间:2018-07-03 07:02:20

标签: ios objective-c iphone

我正在使用一段代码在AVSpeechSynthesizer的帮助下说出我的信息。但我希望在后台模式下运行相同的功能。我们能做到吗?请告诉我,我该怎么做。

谢谢

AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"Driver Reached On Your Location"];
[utterance setRate:0.5f];
[synthesizer speakUtterance:utterance];

1 个答案:

答案 0 :(得分:0)

将此代码添加到AppDelegate.m(didFinishLaunchingWithOptions)

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

请在您的plist文件的“ 所需背景模式”属性下添加应用程序使用AirPlay播放音频或流音频/视频

enter image description here