Android Studio提取MP3音频信号至Float数组的问题求助
Android平台提取音频信号为Float数组(TarsosDSP库FFmpeg依赖问题)
需求
项目需要处理音频文件,提取其中的音频信号并与其他文件对比。核心目标是将用户选择的MP3等音频文件的音频信号提取为Float数组,理想状态下数组第n位对应t=n*dt时刻的麦克风采集压力值(dt为预设采样时间)。
当前开发环境与尝试
- 开发工具:Android Studio + Java
- 尝试库:TarsosDSP,已将
TarsosDSP-Android-latest.jar放入/libs目录并添加项目依赖
文件选择代码
public void requestFileSeeking(View view){ Snackbar.make(view,"Requested file choosing", Snackbar.LENGTH_SHORT).show(); myFileIntent=new Intent(Intent.ACTION_GET_CONTENT); myFileIntent.setType("*/*"); startActivityForResult(myFileIntent, 10); }
注:
startActivityForResult()已过时,可使用registerForActivityResult替代,但这并非当前核心问题。
核心错误代码
在文件选择后的处理逻辑中,以下代码触发致命错误:
@Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PICK_SONG_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) { Uri uri = data.getData(); // 该行代码在选择文件时触发错误 AudioDispatcher dispatcher = AudioDispatcherFactory.fromPipe(uri.getPath(), 44100, 4096, 0); Toast.makeText(this, uri.getPath(), Toast.LENGTH_SHORT).show(); dispatcher.addAudioProcessor(new AudioProcessor() { @Override public boolean process(AudioEvent audioEvent) { // 处理音频数据 float[] audioBuffer = audioEvent.getFloatBuffer().clone(); return true; } @Override public void processingFinished() { // 收尾处理 } }); dispatcher.run(); } }
错误日志
选择文件后模拟器抛出致命错误,日志如下:
E/PipeDecoder: Could not find an ffmpeg binary for your Android system. Did you forget calling: 'new AndroidFFMPEGLocator(this);' ? E/PipeDecoder: Tried to unpack a statically compiled ffmpeg binary for your architecture to: /data/user/0/com.example.youknowthatsong/cache/ffmpeg D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.youknowthatsong, PID: 32739 java.lang.Error: Decoding via a pipe will not work: Could not find an ffmpeg binary for your system at be.tarsos.dsp.io.PipeDecoder.<init>(Unknown Source:350) at be.tarsos.dsp.io.PipedAudioStream.<clinit>(Unknown Source:2) at be.tarsos.dsp.io.android.AudioDispatcherFactory.fromPipe(Unknown Source:0) at com.example.youknowthatsong.MainActivity.onActivityResult(MainActivity.java:198) at android.app.Activity.dispatchActivityResult(Activity.java:8939) at android.app.ActivityThread.deliverResults(ActivityThread.java:5474) at android.app.ActivityThread.handleSendResult(ActivityThread.java:5520) at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2401) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:294) at android.app.ActivityThread.main(ActivityThread.java:8128) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:946)
求助点
团队尝试解决FFmpeg二进制文件缺失问题但未成功,寻求相关经验者指导如何解决该问题,或提供其他可行的Android平台提取音频信号为Float数组的方案。
内容的提问来源于stack exchange,提问作者Adrien S.
相关产品推荐
相关产品推荐

