Android convert pcm file from AudioRecord to smaller file - android

I tried to record audio in Android. The quality of the sound using the MediaRecorder really sucks.
So I tried writing the sound to a stream using the AudioRecord function. Great quality but pcm-files are too large in size as I want to upload them to a remote server.
Does anybody know how to compress the pcm (like mp3 or else)?
Any help is mostly appreciated.
Tom

As far as I know, there are no built-in audio converters in Android. Your best bet is to use third party library, maybe even a c/c++ one.
Look at this question for more info: How to encode a WAV to a mp3 on a Android device

Related

Can we change or pass bitrate to opus codec during compilation or after compilation for android

I am working on a audio application, for development of this I am using pjsip . I compiled pjsip with opus but now I want encode audio with different bitrate . Is that possible ? please anyone help me .
I'm not familiar with pjsip or opus, but I can say from experience that it is possible to change audio bitrate using Android's MediaCodec. It should just be a matter of decoding the audio stream with one MediaCodec and re-encoding it with another MediaCodec with the newly specified bitrate. If, however, you want to resample the audio, you would have to do a lot of extra work by hand between the decode and encode steps provided by MediaCodec. Again, I can tell you from experience that it is possible though.

get audio from one mp4 and use it in resampled (smaller) mp4 in android

I have found a solution for resampling an .mp4 video taken with the camera on the device to make it smaller (resizing by resolution, bitrate, and framerate). The problem is, it doesn't carry the audio over.
I have looked at several different options for trying to get the audio out of my source (large) mp4 and push it into my smaller mp4 and I can't not seem to get any of these procedures to work correctly.
I've tried the following:
1) extracting the PCM audio from the source using: How do I extractor audio to mp3 from mp4 using java in Android?
2) converting the PCM to M4A and then adding the M4A to the smaller MP4 using: https://github.com/tqnst/MP4ParserMergeAudioVideo/blob/master/Mp4ParserSample-master/src/jp/classmethod/sample/mp4parser/MainActivity.java
that's the method I got closest with but the audio was really slow and didn't match up at all with the video in the smaller mp4.
I also tried a "direct copy" from one mp4 to the other with a variation of this: Concatenate multiple mp4 audio files using android´s MediaMuxer
that made my smaller mp4 actually larger (in file size) than my source mp4 and it didn't actually move the sound over.
The android documentation for MediaMuxer is pretty terrible and I can't make heads or tails of what I need to do to get this to work. It seems like it should be a pretty trivial task....
any suggestions or advice would be greatly appreciated.
TIA
I ended up just using ffmpeg with this solution:
https://github.com/WritingMinds/ffmpeg-android-java

Android AudioRecord and MediaRecorder

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.

Best Way to combine Audio files in Android

I am developing Recording App that includes Pause/Play option.
I tried with both Media Recorder and AudioRecord
In case of AudioRecord , the recorded audio consumes larger size, so if the recording size increases say for eg: if i record 1 min audio it consumes 40 to 50MB an it really paining to combine by converting it to .raw file and send to php server.
So i tried with Media Recorder, it consumes less size,but not able to combine using the previous way handled in Audio Record.
Next step i tried with Android NDK- really paining for even Set up process.
Now my question is that which is the best way to combine recorded audio files
Using Android NDk
Reading the byte data from Audio and combining -If i use this there is problem with Headers of Recording format say amr,wav like that.
Also if i try with this , i am not able to get javax.sound package , So i tried with Plugins but no luck..
Please Suggest best way to do this. Also i tried with all this following links
Audio Link 1
Audio Link 2
Audio Link 3
Audio Link 4
Provide me Good tutorial or samples or links.Thanks.
For something like this your best bet would be to develop native C++ code using the NDK.

Mp3 encoder for android, record audio in mp3 format [duplicate]

I have simplified my question and offered a bounty:
What options are there for compressing raw PCM audio data to a mp3 on a Android device.
My original post:
I'm creating a synthesiser on my Android phone, and I've been generating PCM data to send to the speakers. Now I'm wondering if I can encode this PCM data as a mp3 to save to the sdcard. The MediaRecorder object can encode audio coming from the microphone into various formats, but doesn't allow the encoding from programmatically generated audio data.
So my question is, is there a standard Android API for encoding audio? If not, what pure Java or NDK based solutions are there? And can you recommend any of them?
Failing this I'll just have to save my generated audio as a WAV file, which I can easily do.
Pure Java
Look into Tritonus's clean room implementation of javasound which offers an MP3 encoder plugin here: http://www.tritonus.org/plugins.html
Secondly, I would suggest looking into jzoom's libraries JLayer or JLayerME: http://www.javazoom.net/javalayer/javalayer.html (this may only be decode, not sure)
If those doesn't suit your need you can look at this article from 2000 about adding MP3 capabilities to J2SE (with source): http://www.javaworld.com/javaworld/jw-11-2000/jw-1103-mp3.html
Native route
If you want "native" performance I would look at an FFmpeg or Lame port for Android.
Lame: http://lame.sourceforge.net/
As far as i know you can't do this using only the tools in the SDK. According to the official developer guide there isn't an MP3 encoder in the platform (Android Supported Media Formats), so you have to port an encoder on your own using the NDK, then write some wrapper code to receive the audio samples through JNI.
I'm currently working on porting some audio decoders from the Rockbox project for my own music player, and it can record audio into MP3, so maybe you should try to look into it's source and find the encoder library. Most of the decoders have ARM optimalizations which speeds up things noticable, so i guess some of the encoders have also this addition.
Mp3 encoder is not available in android.you have to compile libav with mp3 lame lib you can find code from
http://libavandroid.wordpress.com

Categories

Resources