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

4

5

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?

Litharge answered 18/3, 2012 at 14:5 Comment(0)
B
6

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.

Brighton answered 18/3, 2012 at 14:28 Comment(7)
OK - so would it be possible to circumvent this by using the native audio API?Litharge
I dont think so. because it may cause in failure of audio package or device.Brighton
Wait - I don't get it... do you mean the java 'synchronized' keyword? I am talking about two different applications. I think the exclusiveness is due to something else.Litharge
two different applications, but they both use same resource at a time. I am saying that the native recording method is synchronized. so two different application or one application's two object can not use audio recording at sametime.Brighton
OK - so sharing is impossible. My follow-up is therefore: Is it possible to open the audio input device in a manner that would make it forfeit or yield the resource if another application requests it?Litharge
Is there any work-around or listener to hand-over the resource to any app that requests AudioRecord?Sevenfold
It is very unfortunate this is not possible on Android. iOS apps can share the microphone without any problems, even at different sampling rates.Anticlastic
F
1

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.

Facilitate answered 3/10, 2014 at 21:17 Comment(0)
D
0

Recording audio/video, while other applications are running , is possible. I've done it in Sony Xperia Z1, continuously recorded videos and calls with a downloaded screen recorder. However, I do believe that this was a glitch of some sort, as it stopped being able to record after some time (about 2 months)and started showing an error which says that the microphone is being used by another application...

Disheveled answered 6/7, 2017 at 18:54 Comment(0)
H
0

Yes, with Android 10 you can.

Before Android 10 the input audio stream could only be captured by one app at a time

Haversack answered 23/11, 2019 at 16:10 Comment(1)
that misleading, you still can't though. Only with assistant UI over app you can.Insane

© 2022 - 2024 — McMap. All rights reserved.