Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get bit rate , sampling rate and no. of channels of a audio file in android

I need your help for the below query:

Query: Is there any way of getting following info of an audio file. Sample rate, Channel, Bitrate of an audio file.

For extracting bitrate, "MediaMetadataRetriever" API is available (METADATA_KEY_BITRATE).

Please suggest if it can be done using any android API.

Found this below API, But its use is actually in different. http://developer.android.com/reference/android/medi/AudioTrack.html

I want to extract these using Android API programmactically : Sampling rate, Quantization, Channel of an input audio file.

Please help on this.

Thanks in advance.

like image 241
user1850671 Avatar asked Feb 07 '13 10:02

user1850671


People also ask

How do you find the bit rate from a sample rate?

1) First, calculate the bit rate using the formula sampling frequency * bit depth * No. of channels. 2) Using the bit rate calculated, we multiply it by the length of the recording in seconds. Audio recorded in 192kHz/24-bit will take up 6.5x more file space than one sampled at 44.1kHz/16-bit.

How many bits is an audio sample?

The most common audio bit depths are 16-bit, 24-bit, and 32-bit. Each is a binary term, representing a number of possible values. Systems of higher audio bit depths are able to express more possible values: 16-bit: 65,536 values.


2 Answers

Use MediaPlayer.getTrackInfo() during playback (after METADATE_UPDATE event come to onInfo callback) to obtain MediaFormat object by invoke getFormat for audio stream track. And then from MediaFormat you can get:

BIT_RATE

CHANNEL_COUNT

SAMPLE_RATE

like image 54
dasar Avatar answered Nov 14 '22 23:11

dasar


This can be done using MeiaExtractor like this:

MediaExtractor mex = new MediaExtractor();
    try {
        mex.setDataSource(path);// the adresss location of the sound on sdcard.
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    MediaFormat mf = mex.getTrackFormat(0);

    int bitRate = mf.getInteger(MediaFormat.KEY_BIT_RATE);
    int sampleRate = mf.getInteger(MediaFormat.KEY_SAMPLE_RATE);
    int channelCount = mf.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
like image 24
kc ochibili Avatar answered Nov 14 '22 22:11

kc ochibili