1.从提供的URL中流式传输单个mp3文件;
2.从mp3流中提取音量和/或声音频率数据;
3.通过#2中的数据驱动灯光展示。
我已经有了可能解决#1问题的方案,并正在努力解决#2问题。请问有哪些SDK特定类可以帮助我完成这个任务?
另外,是否有任何现有的Android项目(例如在github上)可以从流媒体mp3文件中提取频率和/或音量数据,供我参考和学习?
您需要公开读取底层缓冲区,以便获取派生音量级别...这可能意味着使用一些不同于“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;
}
}
为了暴露缓冲区,您可能需要使用类似于'AudioTrack'的东西来处理您的mp3,而不是使用'MediaPlayer' api。关于示例,我认为您可以访问git上的这个项目。* 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.
这是另一个对你的项目有帮助的好资源:http://therandomlab.blogspot.nl/2013/05/fft-audio-frequency-analysis-with.html
祝你好运