在iOS7上同时使用TTS和音乐?

le *_*fre 2 objective-c text-to-speech ios7

我想知道是否可以在iOS7上同时播放音乐和某种文字转语音引擎.我正在使用Apple的新内置API,其中一个正在运行,而不是两者都有效.有人在想吗?我的TTS播放代码,也在后台工作

 -(void)speak:(NSString*)string
{
   AVAudioSession *audioSession = [AVAudioSession sharedInstance];

   NSError *setCategoryError = nil;
   [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];

   NSError *activationError = nil;
   [audioSession setActive:YES error:&activationError];

   AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:string];
   utterance.rate = 0.3f;
   utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:[AVSpeechSynthesisVoice currentLanguageCode]];

   AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init];
   [synth speakUtterance:utterance];

}
Run Code Online (Sandbox Code Playgroud)

le *_*fre 6

Ok, found it myself reading the docs.

Using

BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback
  withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&setCategoryError];
Run Code Online (Sandbox Code Playgroud)

does mix audio playback with the tts engine.