"Encoded PCM 16/8-bit" what does it mean?? lets say i have a mp3 music and i want to convert this to a encoded PCM so i could directly feed this to write() of AudioTrack object.
any tools by which i can convert??
and after conversion to PCM will it be playable in android.
(considering i am don't bother about quality)
Thank You!
PCM (pulse-code modulation) is a standard encoding scheme used in the WAV file format. It consists of 8- or 16-bit samples; there are a number of these per second of audio - that number is called the sample rate. AudioTrack is used to play back PCM data; this can be done in real-time while you write to its internal buffer (i.e. MODE_STREAM), or you can fill the buffer and then play back (MODE_STATIC). If you go with the streaming mode, it's important to continuously call write() to keep filling the buffer during playback, otherwise the AudioTrack will stop playing until it receives more data.
As for tools, a simple one is iTunes. Go to Preferences->General->Import Settings and choose "WAV encoder" from the drop-down menu. Now right-click a file you want to convert and select "Create WAV version". As you mentioned, you will lose a bit of quality, which is inevitable in conversion.
Alternatively to this method, consider using the MediaPlayer API, which will play MP3s natively.
Related
I need to record an audio on android that I later want to encrypt. So I'm working with the AudioRecord class, since it works the audio at a low level using the bytes directly.
I found a piece of code that works with short and then converts it in to bytes, which is what I want. But once I have created the audio, I can not play it with any audio player in the phone.
What should I have to do in order for the phone to recognize it as a valid audio file?
Please forgive me because I really don't remember all in detail, but I had this issue before and I do remember that the audio recorded by AudioRecord has no format, so in order to make it playable you first need to set a format to it, where you have to specify all of the characteristics that you've set up when initializing your AudioRecord instance (such as sample rate, number of channels, etc). I found an example of how to record an audio using AudioRecord and later setting up wav format: https://selvaline.blogspot.com/2016/04/record-audio-wav-format-android-how-to.html I hope it helps.
I have an app calling using WebRTC. But during a call, I need to record microphone. WebRTC has an object WebRTCAudioRecord to record audio but the audio file is so large (PCM_16bit). I want to record but to a smaller size.
I've tried MediaRecorder but it doesn't work because WebRTC is recorded and MediaRecorder does not have permission to record while calling.
Has anyone done this, or have any idea that could help me?
Webrtc is considered as comparatively much better pre-processing tool for Audio and Video.
Webrtc native development includes fully optimized native C and C++ classes, In order to maintain wonderful Speech Quality and Intelligibility of audio and video which is quite interesting.
Visit Reference Link: https://github.com/jitsi/webrtc/tree/master/examples regularly.
As Problem states;
I want to record but smaller size. I've tried MediaRecorder and it doesn't work because WebRtc is recorded and MediaRecorder has not permission to record while calling.
First of all, to reduce or minimize the size of your recorded data (audio bytes), you should look at different types of speech codecs which basically reduce the size of recorded data by maintaining sound quality at a level. To see different voice codecs, here are well-known speech codecs as follows:
OPUS
SPEEX
G7.11 (G-Series Speech Codecs)
As far as size of the audio data is concerned, it basically depends upon the Sample Rate and Time for which you record a chunk or audio packet.
Supppose time = 40ms ---then---> Reocrded Data = 640 bytes (or 320 short)
Size of recorded data is **directly proportional** to both Time and Sample rate.
Sample Rate = 8000 or 16000 etc. (greater the sample rate, greater would be the size)
To see in more detail visit: fundamentals of audio data representation. But Webrtc mainly process 10ms audio data for pre-processing in which packet size is reduced up to 160 bytes.
Secondly, If you want to use multiple AudioRecorder instances at a time, then it is practically impossible. As WebRtc is already recording from microphone then practically MediaRecorder instance would not perform any function as this answer depicts audio-record-multiple-audio-at-a-time. Webrtc has following methods to manage audio bytes such as;
1. Push input PCM data into `ProcessCaptureStream` to process in place.
2. Get the processed PCM data from `ProcessCaptureStream` and send to far-end.
3. The far end pushed the received data into `ProcessRenderStream`.
I have maintained a complete tutorial related to audio processing using Webrtc, you can visit to see more details; Android-Audio-Processing-Using-Webrtc.
There are two parts for the solution:
Get the raw PCM audio frames from webrtc
Save them to a local file in compressed size so that it can be played out later
For the first part you have to attach the SamplesReadyCallback while creating audioDeviceManager by calling the setSamplesReadyCallback method of JavaAudioDeviceModule. This callback will give you the raw audio frames captured by webrtc's AudioRecord from the mic.
For the second part you have to encode the raw frames and write into a file. Check out this sample from google on how to do it - https://android.googlesource.com/platform/frameworks/base/+/master/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenInternalAudioRecorder.java#234
Is it possible to record the internal sound generated by the app?
My app allows you to create and play back musical sequences.
soundPool.play(soundIds[i], 1f, 1f, 1, 0, Constants.TIME_RATE);
I'd like to be able to record the sequence and export to mp3.
I've looked into Audio Capture but setAudioSource (int audio_source) only seems to accept MIC recording.
Thanks
No, there's no API for getting the audio output, even for your own app (actually that's not entirely true, because you can get it through the Visualizer API, but it would be of such low quality that I doubt it would be of any use for you).
If you want that kind of functionality you'll have to implement it yourself. That is; as you start playback of sounds, mix them and write the result to a file as well. If the sounds are compressed you'll also have to take case of decoding them yourself.
Note that there's no MP3 encoder included with Android, so you'd have to supply your own MP3 encoder anyway if that's the format you want to export in.
As the michael said , u need to implement your own encoder and decoder for that . Visualizer is providing very low quality of data becaz we can use it to show on custom views and effects which are synchronized with equalizer.
This is the link where u will find simple decoder and encoder for MP3 file. Where they are reading data from MP3 file and putting it into new MP3 file. They had created support for some other extension too.
http://code.google.com/p/ringdroid/source/browse/#svn%2Fbranches%2Fgingerbread%2Fsrc%2Fcom%2Fringdroid
According to http://xzpeter.org/?p=254 it's possible to capture internal sound playback if you modify Android sources. Particularly the write function of the AudioFlinger::MixerThread class. (Note that the article is a little bit old - on the latest Android versions AudioFlinger was reorganized and write code can be now found in the threadLoop_write() function).
Quoting original solution author:
AudioFlinger is implemented under dir
frameworks/base/services/audioflinger/. What we are going to
do is to find the mixer output. In the file AudioFlinger.cpp, we can
see AudioFlinger::MixerThread::threadLoop(), which is the working
thread of the mixer, and this MixerThread is inherited from
AudioFlinger::BaseThread. Then, just search the keyword mOutput->write
with your best editor (vim, emacs, gedit, whatever), and we will find
something like this under the threadLoop() function:
mLastWriteTime = systemTime();
mInWrite = true;
mBytesWritten += mixBufferSize;
int bytesWritten = (int)mOutput->write(mMixBuffer, mixBufferSize);
if (bytesWritten < 0) mBytesWritten -= mixBufferSize;
mNumWrites++;
mInWrite = false;
That is the very point that mixer output buffer is transferred to hardware related codes I think, and the audio clip is in mMixbuffer, with size mixBufferSize. In this buffer, there are PCM raw audio data with 44100Hz sampling rate, 2 channels and 16 bits little endian as its param.
If you write this buffer out to a file, like /data/wav.raw, you can just use adb pull to retrieve the data file to your host machine and play it with aplay:
aplay -t raw -c 2 -f S16_LE -r 44100 wav.raw
Anyway, in order to convert it to mp3 you will have to use external encoder as stated by Michael.
I'm developing an audio processing application where I need to record audio, and then process it to obtain features of that recording. However, I want the audio in a playable format to play it after with MediaPlayer.
I've seen that to record audio to process it it's better to use AudioRecord, because I can get the raw audio from there. But then I can't write the data to a file in a playable format (is there any library to do this in android?).
I used this method to record raw data and then write it into a file:
http://andrewbrobinson.com/2011/11/27/capturing-raw-audio-data-in-android/
But when i try to play this file on the device, it is not playable.
Then if I use MediaRecorder I don't know how to decode the data to extract the features. I've been looking at MediaExtractor, but it seams that MediaExtractor doesn't decode the frames.
So.. what's the best way to do this? I imagine that's common in any audio processing application, but I wasn't able to find the way to manage this.
Thanks to your replies.
Using AudioRecord is the right way to go if you need to do any kind of processing. To play it back, you have a couple options. If you're only going to be playing it back in your app, you can use AudioTrack instead of MediaPlayer to play raw PCM streams.
If you want it to be playable with other applications, you'll need to convert it to something else first. WAV is normally the simplest, since you just need to add the header. You can also find libraries for converting to other formats, like JOrbis for OGG, or JLayer for MP3, etc.
For best quality result you have to use AudioRecord class instead of MediaRecorder.
Please have a look to below link:
Need a simple example for audio recording
Also have a look to this link: http://i-liger.com/article/android-wav-audio-recording
If you use AudioRecord object to get the raw audio signal, the next step to save it save as a playable file is not so difficult, you just need to add a WAV Head before the audio data you capture, then you get a .WAV file which you can play it on most mobile phones.
A .WAV file is a file under the RIFF format. the RIFF header for WAV file is 44 byte long and contains the sample rate, sample width and channel counts information. you can get the detail information from here
I did the sample function on Android phones and it worked.
I can receive a byte array from a Socket. I need to play audio from this byte array - the audio is encoded with AMR 8000Hz.
I found that I can play AMR audio with MediaPlayer. However, MediaPlayer can't play music from byte array, and I don't want to write them to file.
Is there a way to play AMR sound from byte array on android?
The Android framework allows you to play back audio data directly from memory using the AudioTrack class; the drawback is that the audio must already be decoded into PCM data. If you are lucky enough to target Android 4.1, there are new APIs that allow you to decode the data separately so it can be passed to AudioTrack (see MediaExtractor and MediaCodec). However, prior to that there were no exposed APIs for encoding/decoding beyond MediaRecorder and MediaPlayer.
If targeting a version of Android prior to 4.1 (which I imagine you probably are) you have two options:
Find a 3rd party decoder for the AMR data so you can pass it on to AudioTrack
Save your data to a file (even temporarily) so it can be handed to MediaPlayer
HTH