Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to share audio input (Microphone) stream in Android?

I am writing an application that runs as a background service recording and analyzing audio recorded from the microphone. When my app is running I can't use other apps that use the microphone (e.g. phone, voice recording, etc...).

My question is - Is there a way to share the microphone stream in Android? Maybe by using the NDK? If not, is it possible to receive an indication (e.g. a BroadcastIntent) that another app is requiring the microphone?

like image 564
smichak Avatar asked Mar 18 '12 14:03

smichak


People also ask

How do you share audio on Android?

Android users need to go to Bluetooth Settings and pair either Bluetooth headphones or speakers one by one. Once connected, tap the three-dot icon on the right and click on Advanced Settings. Toggle on the 'dual audio' option if not already turned on. This should enable users to connect to two devices at once.

Can two apps use mic at the same time Android?

When two apps are capturing concurrently, only one app receives audio and the other gets silence. Android shares the input audio according to these rules: If neither app is privacy-sensitive, the app with a UI on top receives audio. If neither app has a UI, the one that started capture the most recently receives audio.

How do I send an audio mic?

In addition, you can play audio through mic by changing your default microphone to your system sounds. You can do this by going to Control Panel and clicking Hardware & Sound. Next is you should click Manage Audio Devices and choose Recording. Then allow Stereo Mix and set it to the default mic.

Can two apps use the same mic?

Can two apps on Android use the microphone at the same time? Generally, two applications can't use a mic simultaneously until they are using the same sound card. When two applications are capturing audio concurrently, only one of these applications will receive audio, while the other will get the silence only.


2 Answers

Simple Answer would be "NO" , This is just because Audio Recording Method is synchronized. So Two or more resources can not attempt it simantenously. Doing so might sometime force close the applicatio.

like image 155
Lucifer Avatar answered Sep 17 '22 01:09

Lucifer


I know this is old, but you may be able to kill/reactivate the microphone connection every few minutes to simulate a shared microphone resource. This is an untested hack...

Essentially:

  1. Set a timer to disconnect from the mic every few minutes
      Hopefully, if another app is trying to collect mic data, it can
      while blocking other apps from collecting at the same time
  2. Attempt to reconnect and test for data
      if the other app has the mic and is blocking data then you can
      try to reconnect at some time in the future.

I haven't tested this but I need a solution too so I'll post code if it works.

like image 45
Patrick Pease Avatar answered Sep 21 '22 01:09

Patrick Pease