【问题标题】:TTS and Music simultaneously on iOS7?在 iOS7 上同时播放 TTS 和音乐?
【发布时间】: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


【解决方案1】:

好的,我自己在阅读文档时发现了它。

使用

BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback
  withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&setCategoryError];

确实将音频播放与 tts 引擎混合。

【讨论】:

  • 太好了,谢谢你发帖我会试试这个。几天前我实际上发布了一个关于这个主题的问题,但没有人有任何答案或建议。我发布了我的代码的完整描述。您能否检查一下,看看我所做的是否与您在项目中使用 audioSessions 的方式相关?线程在这里找到:stackoverflow.com/questions/20403331/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多