I had building a recording app, it support recording by mobile mic.
but even I had conncect to headset,it still recording from mobile mic, not headset.
In AudioRecord, seems doesn't has parameter to setting to headset.
does it possible to set recording source to headset?
Related
Currently using AudioTrack and AudioRecord to record and play simultaneously, it's working great on the same device (either headset mic + headset speakers or phone mic + phone speakers). However, what I'd like to do is record from a device and play from another, for instance recording from my bluetooth headset microphone and then having the output on the device built-in speakers (or another pair of headset/headphones).
I have been trying for a few days but I could not find anything. Hence I am asking, is it even possible?
In my app i'm recording audio via Bluetooth and playback the audio to wire headset at the same time. My app works on older OS but not the latest OS.
I've been searching and reading old postings and could not figure a way to force audio play back to headset or ear piece using AudioTracker on newer Android OS 9+ while connected to Bluetooth audio.
I read this link but it does not work on AndroidOS 9+
Route default audio to ear piece
Set Audio manager
manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
manager.setMode(MODE_IN_COMMUNICATION);
Playback using AudioTrack
player = new AudioTrack(MODE_IN_COMMUNICATION, sample_rate, AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT, minBuffer, AudioTrack.MODE_STREAM);
With the above the playback is output to the Bluetooth device.
I have tried the Reflection code above and it does not work.
Is it possible to reroute playback audio when connected to Bluetooth device?
I am currently recognizing Hot word(like "ok google") using pocketsphinx library.
The app works fine except that it always uses only the phone's mic to recognize the speech.
My use case is something like this:
I listen for a hot word and use the MediaPlayer to play some music.
Keep listening for next commands while keeping the music being played and react accordingly.
The app works fine and the music is played via the bluetooth headset and the voice is also simultaneously recognized, but it always uses the phone's mic. Even though the bluetooth headset is connected or not connected, it still uses the phone's mic.
I tried using:
AudioManager mAudioManager =
(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.startBluetoothSco();
I tried using:
AudioManager mAudioManager =
(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.startBluetoothSco();
In both the approaches, it cuts off the music and listens in bluetooth mic.
I need an approach where the Music player is not cut from bluetooth headset but still I am able to speech recognize from bluetooth headset.
For example:
I was listening to music via bluetooth headset.
I opened voice recording app(https://play.google.com/store/apps/details?id=com.andrwq.recorder)
I am able to record the audio through bluetooth headset even while listening to music.
This makes me feel that it is possible but I don't know how.
Please help me out. Thanks in advance.
It is correct to start SCO mode, after that pocketsphinx will listen for bluetooth headset.
To disable phone microphone while in sco mode use am.setMicrophoneMute(true);
To play audio through SCO you need the player to play through STREAM_VOICE_CALL. Maybe player must be restarted after SCO switch.
I have an app which uses voice recognition and tts. I want to use this app through bluetooth headset. I used code from this question: Using the Android RecognizerIntent with a bluetooth headset
Unfotunately, it did not work for me neither recording nor playing. I added in startBluetooth11 method:
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
This make recording working. But still can't get microphone to work.
If I set AudioManager mode to MODE_IN_COMMUNICATION, and set the Media Player stream to STREAM_VOICE_CALL, I can route the audio to the speakerphone or the internal handset speaker just fine. And if it's routed to the internal speaker, and a wired headset is plugged int, it automatically routes to it. However, I can't figure out a way to route the audio to an A2DP headset (without changing the audio mode to MODE_NORMAL, or the stream to STREAM_MUSIC). My problem is that using MODE_NORMAL and STREAM_VOICE_CALL causes problems on some devices, and using STREAM_MUSIC is a problem if there is already music playing in the background, then my app "mixes" with that background music.
So, I was hoping that there was a way to force the audio to the A2DP headset using the MODE_IN_COMMUNICATION and STREAM_VOICE_CALL combination. Is that possible?
Perhaps it works on some devices, but if you care about compatibility across the majority of devices then the answer is "No".
When the phone state is MODE_IN_CALL or MODE_IN_COMMUNICATION all streams will typically follow the PHONE routing strategy. This means that routing to A2DP will not be allowed since:
1) A2DP doesn't support two-way voice anyway.
2) If your BT accessory supports the Hands-free profile it will use a SCO link for the voice audio, and the ACL channel used for A2DP should be closed to avoid interference between the two.