Replay audio from in-memory source - android

I have some audio data (raw uncompressed audio waveform, no file format) in memory and want to replay it. Android-internal Mediaplayer seems to support only replaying of files stored somewhere on disk, I could not find a setDataSource()-method that would accept an array of data instead of a path/URL.
So how can I replay waveforms that are not stored on disk?
Thanks!

Use an AudioTrack. See e.g. this page for an example of how to set up an use an AudioTrack (jump to the "Playing the sample with an AudioTrack" section, and just ignore the JNI-stuff).

Related

how to read a smaller chunk of a bigger file as byte array and treat it as a video or audio file in java android

I have one big file (I used a hex editor to simply put a few .mp4 and .mp3 files next to each other and saved them as one big ~500mb raw data file and recorded each file's starting offset/index and their lengths, i.e. file Sizes) now I want to put that big file in android external storage and read one of these videos or audio files from it. I know I can create a temporary file in context.getCacheDir(); and write this smaller(30-50MiB) byte array chunk to it and simply play the file in my videoView, but i want to read this file without creating a temporary file and deleting it each time i get in/out of that activity.
i probably need to define a File and save that byte array to it, and feed that File to my mediaPlayer as the data source without writing it to a cache file. how can i do this? (please answer with a code snippet/example)
You can easily do that if you just switch to a different player.
Use ExoPlayer to play, and create a custom DataSource. In this DataSource you can start reading bytes from wherever and feed it to the ExoPlayer to be played.
However, it should be noted that some video file containers add some meta data at the end of the file, while others add it at the start. And this meta-data is required to play them.

Kotlin audio conversion

I've been struggling to find the information on how to record an audio through a mic, save it as a mp3 or wav file (if possible) and then store it in an array using Kotlin. Does anybody know how to do that?

Recording video with Android

I need to process data that MediaRecorder provides when i recording video and then save into file as *.mp4. I have ParcelFileDescriptor and with that i send Recorder output to pipe which is read in my thread. Problem is that i have no idea how to save mp4 file. Which metadata i need to provide? Can i extract all of them from MediaRecorder. And how much bytes are provided for metadata. Possibly you have better idea how can i store that data as *.mp4 using some external library?
Thanks.

Is there a file container that can store GSM-EFR speech data?

Is there a file container that can store GSM-EFR speech data?
Just now I have such an file that contains a lot of RTP packages, the payload type of RTP package is GSM-EFR. I want to convert this file to a file that store the GSM-EFR data.
And then I need a audio player to decode the file and play the voice.
I have try the .amr file format,but encounter that .amr format can not distinguish the full rate and enhance full rate when they are both 12.2kbps.
I have try the ffmpeg, but this player can not decode GSM-EFR data.
So I need a file format and a audio player.Is there anyone can help me?
Thanks very much!
GSM-EFR is same like AMR mode 7. Try packet your RTP payloads to AMR storage file with amr header mode 7. And be carefully, because in RTP payload can be signature 4 bit (0xC) in beginning, if have, you need delete at beginning 4 bit befor packing to AMR file

Creating a WAV file from raw PCM data using the Android SDK

I'm trying to use the AudioRecord class to record a WAV file. The problem is that it only supplies the raw PCM data, and if I write it to a file, there is no header information, so it will not play in any media player. How can I create a WAV file from this raw data?
Or alternatively, is there any other way to record sound in Android to a WAV file (or, alternatively MP3)?
Oh, and I know that MediaRecorder can'y be used because it doesn't support either WAV or MP3 formats.
OK, I've got this figured out. This post was crucial in helping me:
http://computermusicblog.com/blog/2008/08/29/reading-and-writing-wav-files-in-java
Basically, I used ByteArrayOutputStream to write the raw PCM data from AudioRecord, which then lets me get the byte array and its size when the process is done. I can then use that data in conjunction with the SampleRate, BitRate, and Stereo/Mono settings to create the WAV header as per the link above. The resulting file works perfectly!
Check the MediaRecorder.setOutputFormat(), you can set different container formats for your recording; there is MediaRecorder.OutputFormat.MPEG_4 and MediaRecorder.OutputFormat.THREE_GPP; the only allowed format along RAW is setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
Sorry but MP3 is not avail. You really need mp3 for recording?
WAV on the opposite of MP3 is a container, not a format; WAV can be any kind of encoding format.
You are always free to prepend some WAV RIFF header in front of your raw pcm data (as long as you exactly know the format). Check here for how it has to look like:
http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html
You may want to use mediarecord class

Categories

Resources