Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android > 4.0 : Ideas how to record/capture internal audio (e.g. STREAM_MUSIC)?

Some months ago, with Android ICS (4.0), I developed an android kernel module which intercepted the "pcmC0D0p"-module to fetch all system audio.

My target is to stream ALL audio (or at least the played music) to a remote speaker via AirPlay.

The kernel module worked, but there where several problems (kernel-versions, root-privileges etc.) so I stopped working on this.

Now, we have Android 4.1 and 4.2 and I have new hope!

Who has an idea how to capture the audio in Android?

I had following ideas:

  1. Connect via bluetooth to the same phone, set routing to BT and grab the audio on the "other end": this shouldn't work

  2. Intercept the audio with a kernel module like done before: hardcore, get it worked but not applicable

  3. JACK Audio Connection Kit: sadly Android uses "tinyALSA" and not "ALSA". TinyALSA does NOT support any filters like JACK (but this brought the idea with the kernel module)

  4. Use PulseAudio as a replacement for AudioFlinger, but this is also not applicable


EDIT (forgot them):

  1. I compiled "tinymix" (baby-version of ALSA-mixer) from tinyALSA (the ALSA on Android) and tried to route the audio-out to mic-in - but with no success (not understandable for me). And this also needs rooting: not applicable

  2. I tested OpenSL ES, but I'm not a C-crack and it ended in "I can record microphone, but no more" (maybe I was wrong?)


I just found ROUTE_TYPE_LIVE_AUDIO:

A device that supports live audio routing will allow the media audio stream to be routed to supported destinations. This can include internal speakers or audio jacks on the device itself, A2DP devices, and more.

Once initiated this routing is transparent to the application. All audio played on the media stream will be routed to the selected destination.

Maybe this helps in any way?

I'm running out of ideas but want to "crack this nut", maybe someone can help me?

EDIT:

I'm really new in C & kernel-coding (but I successfully created a cross-compiled audio-interception-module) - but isn't it in any way possible to listen at the point the PCM-data goes from userspace (JAVA, C-layer?) to the kernel-space (tinyALSA, kernel-module), without hacking & rooting?

like image 469
Martin L. Avatar asked Dec 27 '12 13:12

Martin L.


People also ask

How to Record just internal audio on Android?

Swipe down from the top of your screen to see the quick settings tiles and tap the screen recorder button. A floating bubble will appear with a record and microphone button. If the latter is crossed out, you're recording internal audio, and if it's not, you get sound straight from your phone's mic.

How do I record internal and external audio on Android?

Go to Audio source and select Internal audio. You can use a third-party screen recorder app from the Google Play Store if your phone doesn't have one built-in. Using the AZ Screen Recorder as an example, go to the app settings, enable Record audio, tap on Audio source, and select Internal audio.

Why Android can t Record internal audio?

Since Android 7.0 Nougat, Google disabled the ability for apps to record your internal audio, which means there's no base level method to record the sounds from your apps and games as you record the screen.

Can I screen Record with internal audio?

ADV Screen Recorder is another Android screen recorder with internal audio. With this app, you can easily capture the sound coming from your smartphone without requiring root. Moreover, this internal audio app lets you record screen, system sound, microphone, or both at the same time with high quality.


1 Answers

You must pass audio traffic through your local socket server:

  1. Create local socket server

  2. Modify audio http stream address to path is thru your local socket server, for example for address

    http://example.com/stream.mp3  ->  http://127.0.0.1:8888/http://example.com/stream.mp3 

    where 8888 is your socket port.

  3. Play

    http://127.0.0.1:8888/http://example.com/stream.mp3  

    with default media player

  4. Read all incoming requests to port 8888 in your local socket server, analyze it and pass to example.com server.

  5. Read response from example.com and pass it to local client (media player). HERE you can capture audio stream!

like image 106
Nik Avatar answered Sep 21 '22 10:09

Nik