Domanda

How to calculate the elapsed time from AudioRecord in Android?

What I am trying to do is similar to this: figure 5(Second graph). To further explain myself I'm recording sound in real time then graphing out the pitch and calculating the buffered data within a certain time.

È stato utile?

Soluzione

Just calculate it, you know the size of your recorded data and you also should know sample rate, and number of channels. So the comment posted by Michael is correct.

Altri suggerimenti

I followed Michael's comment and succesfully calculated the audio length in seconds after recording it.

    int SAMPLE_RATE_IN_HZ = 44100;
    int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT; // Guaranteed to be supported by devices
    int CHANNEL_CONFIG = AudioFormat.CHANNEL_IN_MONO; // Is guaranteed to work on all devices

    File audioFile = yourRecordingLogicHere();
    long audioLengthInSeconds = audioFile.length() / (2 * SAMPLE_RATE_IN_HZ);

I record in mono that's why there is one *2 multiplication less than in Michael's comment.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top