我正在开发一个导航应用程序,它使用AVSpeechSynthesizer来调用方向。如果我正在播放播客,我希望能够暂停音频时,一个方向被说出来,然后继续它。这是通过以下途径成功实现的:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers
error:nil];
但是,如果我使用上述代码播放音乐,那么指令就会与音乐混在一起,而不会减少音乐的音量--因此很难听到指令。所以我试着:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionDuckOthers
error:nil];
现在背景音乐的音量减少了,这正是我想要的,但当我播放口语音频(即播客)时,它不再停顿,而是与指令混合--尽管音量变小了。
我真正想要的是: AVAudioSessionCategoryOptionInterruptSpokenAudioAndDuckWithOthers.然而,这并不存在。我知道这种组合是可能的,因为其他应用程序(比如Waze)也有这种行为。
我知道,当音频播放时,您可以使用:
BOOL isOtherAudioPlaying = [[AVAudioSession sharedInstance] isOtherAudioPlaying];
但是,我找不到一种方法来确定那个音频是否被说出来了。如果可以的话,我可以根据任何特定的时间来安排比赛。有人能帮忙吗,最好是在目标C中?
发布于 2019-01-24 17:14:51
这是怎么做到的:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionDuckOthers | AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers
error:nil];
很有魅力!
https://stackoverflow.com/questions/53092824
复制相似问题