简体   繁体   English

以编程方式禁用麦克风

[英]Disabling microphone programmatically

I wonder if there is any way to disable microphone programmatically (to get rid of the red bar in the background)? 我想知道是否有任何方法可以通过编程方式禁用麦克风(摆脱背景中的红色条)?

I use OpenEars to listen for commands in the app. 我使用OpenEars来监听应用程序中的命令。 When I go to the background red bar appears (which is obvious, as microphone is active). 当我进入背景时出现红色条(这很明显,因为麦克风处于活动状态)。 The problem is that the microphone is active even when OpenEars is suspended . 问题是即使OpenEars被suspended ,麦克风也处于活动状态。 To avoid unnecessary questions I cannot stop OpenEars as it ends up with mixing audioSession with my other sources. 为了避免不必要的问题,我无法stop OpenEars,因为它最终将audioSession与我的其他来源混合在一起。

The "red bar" will never disappear, even when the microphone is not in use by your application unless you explicitly stop the audio session. 除非您明确停止音频会话,否则即使应用程序未使用麦克风,“红色条”也不会消失。 This is a security measure Apple has put in place to alert users of your application that it is listening to their microphone, even if you aren't doing anything with the microphone data at that exact moment. 这是Apple已采取的一项安全措施,旨在提醒您的应用程序用户正在收听其麦克风,即使您在该时刻没有对麦克风数据进行任何操作。

If you are using AUAudioUnit , you may have some luck setting isInputEnabled to false . 如果你正在使用AUAudioUnit ,你可能有一些运气设置isInputEnabledfalse

I'm not sure if it falls into stopping OpenEars case per se, but have you tried switching AudioSessionCategory when your app goes into background/suspended mode? 我不确定它是否属于停止OpenEars案例本身,但是当你的应用程序进入后台/暂停模式时你是否尝试过切换AudioSessionCategory? If you switch to a category that doesn't allow microphone input, my guess is it would stop the microphone. 如果切换到不允许麦克风输入的类别,我猜是它会停止麦克风。 Then you could reset to the correct category when your app resumes. 然后,您可以在应用恢复时重置为正确的类别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM