Detect other apps using the microphone android - android

I have an Accessibility service that processes the surrounding sound with a microphone, and a process runs every time the user says Hey.
The problem is that when I listen to the microphone in the background service, no other software can use the microphone.
One way is to listen to access events whenever an event is received from the software with a premium microphone and disable my application process for a short time. But this is a bit non-standard and does not work to some extent ... Is there a way to access the microphone in such a way that any other program can access the microphone at any time and my program will automatically receive sound ?? Something like channels in audio playback !!
Or the way I can hear that a program needs a microphone !!
Thanks ❤️

Related

Takes control of system wide(for all apps) usage of Microphone

For Microphone disabling, I came across a way to mute the Microphone. But I am not sure if this would work even if my app is not running. I mean if I could write, or rather over-write some system settings to "BLOCK" the Microphone. Please let me know if this is possible.
Ultimately, I want to control the Microphone of the device from my App. Having the Microphone Disabled from my App, no application should be able to use it. I came across numerous applications on play store that can do this, but could not find a stepping stone to this task.
I guess folks around might have some inputs or directions for me on this task.
Thanks!
There are 2 methods to control/disable the mic
setMicrophoneMute(true)
Continuously record the mic stream in service :) Like THIS APP is doing
this.b = new MediaRecorder();
this.b.setAudioSource(5);
this.b.setOutputFormat(1);
this.b.setAudioEncoder(1);
this.b.setAudioSamplingRate(8000);
this.b.setOutputFile("/dev/null");

Pause/Stop/Mute music at service interupts

I basically have an audio application that will be playing some music. I want to be able to pause/stop/mute the music when there is an interrupt.
These interrupts include: GPS directions, Phone Call, GPS, etc. (if there are more audio interupts, please let me know)
I already implemented the phone call interrupt, stops the music when phone call received and plays after phone call ends.
How would I do the other interrupts?
EDIT:
I noticed that Android's Play Music application does this. But I am unable to find the source code of that, not sure if that would be helpful.
Make sure you correctly ask for and release Audio Focus as described here:
http://developer.android.com/training/managing-audio/audio-focus.html
With multiple apps potentially playing audio it's important to think about how they should interact. To avoid every music app playing at the same time, Android uses audio focus to moderate audio playback—only apps that hold the audio focus should play audio.
Basically this allows the framework to handle interrupts properly as you cannot specifically code for every situation.

Android detecting AudioRecord/ways to record audio without blocking other apps

Right now my application lets the user start recording audio and puts an ongoing notification that can pause/restart recording on press using android.media.AudioRecord. All was fine and dandy until I realized that this blocks any other App from using an AudioRecorder (ie google voice search).
Is there a way I can set up a broadcast reciever to detect a call for an AudioRecorder from another app and pause my recording. Alternatively, is there another way to record audio that wont interfere with other Apps that use audio?
Cheers!
I have been looking into this very question for a while now. It seems that there is no clean way of achieving this as there is no broadcast that alerts when another app would like access to the mic.
The way that we have solved it (albeit not cleanly) is we poll what app is in the foreground and get its permissions; if that app has permission to use the mic, we terminate recording until there isn't an app in the foreground with the mic permission.
Although polling is a solution, I would be very interested if anyone has better!

Android: How to detect when a user stops talking into the microphone

I have an Android application that begins recording from the microphone when the application starts. In my current version, the user must press a STOP button to stop recording.
How do I detect that the user has stopped talking and use that to trigger the recorder to stop?
Similar to what is implemented in the Speech Recognition functionality in Android. The user stops talking and then the speech is translated. I have seen other apps that do it, like Talking Tom type apps.
As a side note I would also love to show some type of visual indicating that the microphone is receiving sound. Something to show the sound level coming in.
Any help appreciated.
An approach is to use threads on recording and the speech power analyzing process on the recorded bytes,
there's a sample code for your reference: http://musicg.googlecode.com/files/musicg_android_demo.zip
What are you using to record audio? This may provide some clues:
android.media.MediaRecorder:
the constant MEDIA_RECORDER_INFO_MAX_DURATION_REACHED can be used with an onInfoListener.
android.speech.SpeechRecognizer:
attach a RecognitionListener and call onEndofSpeech().

Block "play" headset button in an Android app

I am writing an Android app that reads external hardware through the microphone input. My problem is that sometimes the phone thinks that the signals that are coming through the mic are "play" button presses and starts playing music. (the play button shorts microphone to ground, and some of the signals I'm reading are close enough to that)
I have seen apps that block the play button from a headset. I wonder how I can add this functionality to my own app.
Just a guess: Set up a broadcast receiver for the ACTION_MEDIA_BUTTON intent and handle it so it doesn't get passed on the music app.
Perhaps you should AC couple your input signal with a series capacitor? This will give a limit on the low frequency response, but you probably shouldn't depend on that anyway.

Categories

Resources