Audio input via headphone jack in Android?

I am trying to get audio input through the headphone jack for my final project. It would be very helpful if someone could share some code on how to capture data. I tried, but since I'm pretty new to android, I could not find the headphone jack API in MediaRecorder.AudioSource ... Only these sources are available: http://developer.android.com/reference/android/media/MediaRecorder. AudioSource.html

+6
source share
1 answer

If you choose, for example, DEFAULT or MIC from MediaRecorder.AudioSource as the input signal, then instead of the internal microphone, the TRRS plug connected to your phone will be used.

But you have two questions:

1) Number of channels

The TRRS plug has two lines for the left and right channels of the headphones, but only one line for an external microphone (see, for example, this description of the plug ). Thus, you can make monaural recordings (the only exception for the smartphone at the moment: the Sony Z2 has a new TRRRS connector). You can build the adapter yourself (see, for example, the pictures here ).

2) Level

You cannot connect a line output, for example. CD player directly to the input. You should use, for example. resistive voltage divider to reduce the output level, to avoid overload.

3) Signal processing

Typically, firmware such as automatic gain control (AGC), and / or equalization, noise reduction, echo cancellation, uses firmware that is specific to the manufacturer. You cannot turn it off, so you will not get a perfect copy of your input signal.

+6
source

Source: https://habr.com/ru/post/972292/


All Articles