【发布时间】:2013-10-19 16:29:57
【问题描述】:
我想知道是否有可能让音乐播放和某种文本到语音引擎在 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];
}
【问题讨论】:
-
我遇到了同样的问题,但不确定您的解决方案是否适合我。我想让 iPod 在后台播放,我想让 AVSpeechUtterance 库中断 iPod,说出它需要说的话,让 iPod 继续播放。我的 AVSpeechUtterance 代码看起来和你的完全一样。有其他人遇到过这个问题吗?
-
更新了我对我实际使用的内容的回答,并且正在按需要工作。 withOptions 的第二个参数是关键...
标签: objective-c ios7 text-to-speech