Record Android Audio Output - android

Many people are asking for this, no one seems to have an answer so I do neither.
How is it possible that some apps serve the function to record the audio output of the android system? Everything I am finding is the very same tutorial on 1432 different sites where you can record MIC input. I don't care about mic input, I want the audio output and just can't imagine how to access it.
If everyone can get me on the right way, I would be so happy.

Seems to be currently there is no way to achieve this.
This is another question related to this : android get device overall audio output in pcm

The closest API available to you for these purposes is Visualizer. Which only captures "partial and low quality audio content".
I imagine direct audio capture functionality is omitted to prevent pro-piracy apps. It may be worth noting that there is a CAPTURE_AUDIO_OUTPUT permission, but it is "Not for use by third-party applications". So if you really do have legitimate apps that are capable of this, as you claim, they are likely system apps. Even if you wrote an app that generated its own musical sequences, for example, you would still have to write your own encoder/decoder to achieve anything close to what you're asking for (and that wouldn't even be considered audio capture at that point.)
To put it bluntly, it's currently impossible without breaking any ToS with Google or your phone provider, and will probably remain so indefinitely.

In Android 10, they have introduced Audio Playback Capture API using which we can capture the Audio being played by other applications. But it's not available in previous android versions.
An app X can also prevent any other app from listening, if that app hasn't added any constraint then this API can be used.

Just Use a bidirectional AUX Cable and hook it in your phone Headphone Port and hook it's another end to your Audio Interface "Line In" Channel (Or Whatever Input You have on your Audio Interface ) and then record that input by audacity or any good Audio Recorder.

TL;DR : use the SCR Screen Recorder app to capture video + internal audio (not microphone) [require root]
Long answer
Original answer: Record tablet's screen AND audio
Jeff's answer seems to be the only way you can use through adb. But that force you to do some work (merge video + audio).
I could do it this way :
- connect the Android device to computer with a jack cable (headphone output to microphone input);
- record video with adb shell;
- record audio with Audacity (or anything else)
- then merge video and audio with a video editor (pitivi, openshot, avconv...)
Another way is to directly use an android app:
SCR Screen Recorder - official website - XDA - short review
Mobizen for SAMSUNG - google play
RecMe - google play
SCR Screen Recorder:
pros :
the only app that truly works for recording video + internal audio with all devices
cons:
banned from google play because of SELinux policy (see XDA - Google Play ban and "Dangerous app" warning)
require root for recording internal audio
Mobizen for SAMSUNG:
pros
on google play store
cons
only the samsung version works for recording internal audio, the general or LG, XIAOMI version can't record internal audio
still a beta feature
require root for recording internal audio
RecMe:
pros
on google play store
cons
internal audio recording doesn't works on most devices
require root for recording internal audio
Personally I tried a lot of apps and the only working for me is SCR Screen Recorder.
PS : all these apps works without root if not using internal audio.

Related

Android capture internal (application) audio

I want to capture internal audio, programmatically. For instance, I want to play an audio file (on my device) and then capture the audio output - not using the microphone with the volume turned up.
Example use case: I want to make a library that other developers can use in their games, allowing users to record in-game audio.
Android says there is Playback Capture functionality, however, I just cannot find an example. I've googled for hours. Whenever I google 'android capture app sounds' or 'android record audio', I either get links to voice recording apps or some code recording from the microphone (usually nearly 10 years old)... e.g
Does anyone have a link to a working example?
You can reference MediareCorder with https://developer.android.com/guide/topics/media/mediarecorder

Sharing audio(Mic) input to multiple apps in Android

As per official documentation
Android 10 (API level 29) and higher imposes a priority scheme that can switch the input audio stream between apps while they are running. In most cases, if a new app acquires the audio input, the previously capturing app continues to run but receives silence. In some cases, the system can continue to deliver audio to both apps. The various sharing scenarios are explained below.
Other than some special cases, audio is not shared between apps.
But I have seen many apps sharing the audio input without being in the above special cases.
For eg. Zoom, when I'm on a call in zoom and start an audio recorder then both the apps are getting audio though zoom audio decreases in intensity.
Similarly, Omlet arcade is able to record mic audio even when mic access is given to other apps.
How is it possible? And as per the documentation, this shouldn't be allowed.
Update:
Was able to achieve it with the usage of Oboe. But it is not consistent on all devices. This also causes a sync issue in my live streaming app. Audio is audible with a delay
This is not possible in Android 5+ . You need a rooted phone to perform this action. In Omlet Arcade Whenever you play a Game and switch ON in-game mic, Omlet Arcade will stop receiving any audio input. However, Omlet Arcade will still function but you have to restart it in order to get voice input back.
Though, in a recent MIUI bug, People were able to listen to calls on Zoom and in-game mic apps. In your case, it might be not official Android and Edited Android like MIUI and OxygenOS

Can I get the audioStream of other apps

I want to analyse the audio spectrum of my music player app for my bluetooth-Led project.
But as far as I understood this article:
https://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html#REMOTE_SUBMIX
There is no way for third party apps to capture the audiostream of other apps.
Does anybody know a solution?
As of Android Q, this is possible (in apps that allow it) with the AudioPlaybackCapture API:
This API gives apps the ability to copy the audio being played by other apps. This feature is the analog of screen capture, but for audio. The primary use case is for streaming apps that want to capture the audio being played by games.
Documentation

Is it possible to get access to the speaker signal on Android?

Sending audio to the speaker for playback on Android is easy, but is it possible to get a copy of the actual final digital signal? Let's say I have 2 apps running "MyApp" and "SomeOtherApp". My app sends audio to the speaker, but so does "SomeOtherApp". "SomeOtherApp" is not my app - it's a 3rd party app. Is it possible to get a copy of the mixed audio signal which is played to the speaker by the OS? That is, the audio signal which is a mixture of the speaker signal from my app and the speaker signal from "SomeOtherApp".
To summarize: I am looking for a way to hook into the low-level audio path (HAL audio stream out - after mixing!) so I can get a copy of the "final" speaker signal (in real-time). Optimally, I would also like to hook into the low-level microphone path, but that's less of a concern right now.
Looks like the short answer is no.
Longer one is kinda. And sorta. But not really, as far as I know. Option 1: it might be a problem with respects to privacy. (not really a good option) Option 2: nobody thought it was needed, so did not build it into the system. Option 3: the amount of trouble shooting when programmers use the wrong source is just not worth it.
edit - You can, of course, record the input.
Checkthis one google example
Usage :
App will capture audio from android devices and playback on the same
device; the playback on speaker will be captured immediately
*

Why it is not possible to play an audio file on a voice call in android

This question might seem to be a repetition of the questions such as following:
How to play an audio file on a voice call in android
Background Audio for a Call in Progress - Possible?
The answers of these questions suggests that it is not possible to play a pre-recorded audio on a voice call in android. I want to know why it is not possible? What is the limitation (hardware/software)? Is it really a limitation or done purposely? Can we alter the source code of android to make it possible?
I think this is a limitation, imposed for security reasons and restricted at the OS level.
Let's analyze the security threat, first of all. If you were able to play custom audio files to the callee, a whole world of cons opens up: you could trick customer supports, you could pretend to be someone else, you could give unauthorized purchase confirmations, and so on. For this reason, neither Android nor iOS allows this functionality.
On Android, you won't be able to do so in a programmatic way, simply because the current APIs won't allow you to do so. It is stated in the official documentation as well, as pointed out here. If you dig into the source code, you can probably enable this feature by accessing the microphone output during a phone call, but that would require running your custom version of Android. A good starting point would be the AudioTrack source, available here.
EDIT: a good example of an audio mod involves enabling the Nexus 5 earpiece as a second loudspeaker (requires root). Can be found here.
After a thorough research, what I have come to know is that there are more than one limitations/hurdles to make it possible. These limitations/hurdles are at three different levels.
First limitation is at API level, because there is no high-level API to play sound files in the conversation audio during a call as mentioned in Android official documentation.
Second limitation is at Radio Interface Layer (RIL). RIL passes on complete control of the call to Radio Daemon (rild) of the Linux library which then further passes the control to the vendor RIL. That means we cannot manipulate voice call in android source code.
Even if we are able to remove these two limitations, we may still not be able to play audio file to an ongoing voice call. Because there is a third limitation. Every vendor has their own library of RIL that communicates with Radio Daemon (rild). This requires that vendor RIL to be open source which is not actually. Hardware vendors do not usually make their device drivers code available.
Detail discussion on this topic is present at this link.
This is software related due to the prioritization of audio routing in Android.
Take a look into the CallManager where you can dig into the method setAudioMode(). After the audio mode was set to MODE_IN_COMMUNICATION the following code is called
audioManager.requestAudioFocusForCall(AudioManager.STREAM_VOICE_CALL,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
From this point on the telephony service has the highest priority and won't let any other audio play in parallel.
Note: You can play back the audio data only to the standard output device. Currently, that is the mobile device speaker or a Bluetooth headset. You cannot play sound files in the conversation audio during a call.
See official link
http://developer.android.com/guide/topics/media/mediaplayer.html
By implementing the AudioManager.OnAudioFocusChangeListener you can get the state of the audiomanager. so by this if any music is playing in the background you can get the AudioManager states(playing and pausing is completely in developer hands) similarly......
Some of the native music players in android device where handling this, they restrict the music when call is in TelephonyManager.EXTRA_STATE_OFFHOOK.so this scenario is also completely in developer hand (whether to handle or not) if he is not handling both will play parallel y

Categories

Resources