문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top