从mp3流中提取音量和/或频率数据的Android应用程序

4
作为一名初学者的Java开发人员,我需要构建一个Android应用程序,实现以下功能:
1.从提供的URL中流式传输单个mp3文件;
2.从mp3流中提取音量和/或声音频率数据;
3.通过#2中的数据驱动灯光展示。
我已经有了可能解决#1问题的方案,并正在努力解决#2问题。请问有哪些SDK特定类可以帮助我完成这个任务?
另外,是否有任何现有的Android项目(例如在github上)可以从流媒体mp3文件中提取频率和/或音量数据,供我参考和学习?

对于 mp3 的频率,您可以查看此 Stack Overflow 答案:https://dev59.com/vG435IYBdhLWcg3w6EmF#5189581 - Chintan Soni
这个问题需要澄清其“频率”的含义。OP是指编码比特率还是声音频率? - Stan
我认为根据第三个要求,他们指的是音频波形频率,但我敢打赌他们实际想要的是FFT分析。 - user1888249
你可以看一下下面的链接,它可能会对你有帮助。https://dev59.com/gW445IYBdhLWcg3wws4u - venkat530
希望这可以帮到你 - BeatDetectorByFrequency.java - vijaykumarg
3个回答

0

您需要公开读取底层缓冲区,以便获取派生音量级别...这可能意味着使用一些不同于“MediaPlayer”的API,该API可能不会公开音量的RMS级别。

每次在MP3上进行缓冲读取时,您可以使用以下方法从音量生成x轴、y轴数据:

while (mIsPlaying) {
    double sum = 0;
    int readSize = mRecorder.read(mBuffer, 0, mBuffer.length);
    for (int i = 0; i < readSize; i++) {
        output.writeShort(mBuffer[i]);
        sum += mBuffer[i] * mBuffer[i];
    }
// PrBar needs RMS as int
//log base2 for the rms expression on the Volume from the mic
    if (readSize > 0) {
        mProgressBar.setProgress((int)Math.sqrt( sum / readSize ));
        handleRMS((Math.log(Math.sqrt( sum / readSize ))/Math.log(2))); 


    }
}

...

private void handleRMS(double rms){

    rmscnt++;
    rmssum += rms;
    if(rms > rmsmax)rmsmax=rms;
    if(rms< rmsmin)rmsmin=rms;
    double myamt=(rmsmax - rmsmin) / 10 +rmsmin;
    if (rms < myamt) decile++; 
    if(rmscnt % 5 ==0){
        if (rmssum / 5 < myamt) {                                       
        if( Long.valueOf(System.currentTimeMillis())
          - tslist.get(tslist.size()-1) - segmenttime > 0 ){
            tslist.add(Long.valueOf(System.currentTimeMillis()));
        };
    };
    rmssum = 0;
}
}
   * feature - select the TS corresponding to a 'pause' in the speech stream       *   arriving from microphone        * ''pause' in algorythm and

the normal RMS volume level on a sine-wave pattern * observe the last reading for RMS in light of the sine-wave * min & max are 'y-axis' vals on the wave * 'myamt' field is a threshold cap that is currently 10 percent of delta ( max - min ) * in practice, a pause has to have a series of adjacent RMS values with an AVG LESS than * some config-value. * Once the TS for a pause has been accepted, there is another min value of time that should * pass before looking for another pause in the speech. * Helpful hint - 5 to 10% of the RMS vals should increment 'decile'. * Otherwise, there are not enough lo-volume events on the radar to ID pauses in speech.

为了暴露缓冲区,您可能需要使用类似于'AudioTrack'的东西来处理您的mp3,而不是使用'MediaPlayer' api。关于示例,我认为您可以访问git上的这个项目。
有关RMS和处理程序的解释,请参见here

0

0
Echo Nest(http://developer.echonest.com/)是一个非常好的工具,用于分析MP3文件并提供音量、频率、节拍和其他数据。
还有一个适用于Android的Java库。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接