我正在使用 Tarsos Dsp for android 从音频文件中检索频谱峰值。从版本 2 开始,TarsosDSP 不再使用 javax,这应该会让一切变得更容易。
困扰我的是我的代码运行良好,但 android 正在努力解码音频文件:这似乎是用 avconv 制作的。
PipedAudioStream localPipedAudioStream = new PipedAudioStream(fileName);
TarsosDSPAudioInputStream localTarsosDSPAudioInputStream1 = localPipedAudioStream.getMonoStream(this.sampleRate);
解码器是如何创建的:
public PipeDecoder(){
//Use sensible defaults depending on the platform
if(System.getProperty("os.name").indexOf("indows") > 0 ){
pipeEnvironment = "cmd.exe";
pipeArgument = "/C";
}else{
pipeEnvironment = "/bin/bash";
pipeArgument = "-c";
}
pipeCommand = "avconv -i \"%resource%\" -vn -ar %sample_rate% -ac %channels% -sample_fmt s16 -f s16le pipe:1";
//pipeLogFile = new File("decoder_log.txt");
pipeBuffer = 10000;
}
是缺少 avconv 库,还是 android 无法处理这些命令?
这是错误输出:
4651/com.example.giuseppe.tsptest I/PipeDecoder﹕ Starting piped decoding process for /sdcard/sample.wav
4651/com.example.giuseppe.tsptest W/PipeDecoder﹕ IO exception while decoding audio via sub process.Error running exec(). Command: [/bin/bash, -c, avconv -i "/sdcard/sample.wav" -vn -ar 44100 -ac 1 -sample_fmt s16 -f s16le pipe:1] Working Directory: null Environment: [ANDROID_ROOT=/system, EMULATED_STORAGE_SOURCE=/mnt/shell/emulated, LOOP_MOUNTPOINT=/mnt/obb, LD_PRELOAD=libsigchain.so, ANDROID_BOOTLOGO=1, EMULATED_STORAGE_TARGET=/storage/emulated, EXTERNAL_STORAGE=/storage/emulated/legacy, SYSTEMSERVERCLASSPATH=/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar, ANDROID_SOCKET_zygote=10, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ANDROID_DATA=/data, ANDROID_ASSETS=/system/app, ASEC_MOUNTPOINT=/mnt/asec, BOOTCLASSPATH=/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/apache-xml.jar, ANDROID_PROPERTY_WORKSPACE=9,0, ANDROID_STORAGE=/storage]
02-20 17:53:54.020 4651-4651/com.example.giuseppe.tsptest W/System.err﹕ java.io.IOException: Error running exec(). Command: [/bin/bash, -c, avconv -i "/sdcard/sample.wav" -vn -ar 44100 -ac 1 -sample_fmt s16 -f s16le pipe:1] Working Directory: null Environment: [ANDROID_ROOT=/system, EMULATED_STORAGE_SOURCE=/mnt/shell/emulated, LOOP_MOUNTPOINT=/mnt/obb, LD_PRELOAD=libsigchain.so, ANDROID_BOOTLOGO=1, EMULATED_STORAGE_TARGET=/storage/emulated, EXTERNAL_STORAGE=/storage/emulated/legacy, SYSTEMSERVERCLASSPATH=/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar, ANDROID_SOCKET_zygote=10, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ANDROID_DATA=/data, ANDROID_ASSETS=/system/app, ASEC_MOUNTPOINT=/mnt/asec, BOOTCLASSPATH=/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/apache-xml.jar, ANDROID_PROPERTY_WORKSPACE=9,0, ANDROID_STORAGE=/storage]
[...]
--------- beginning of crash
02-20 17:53:54.033 4651-4651/com.example.giuseppe.tsptest E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.giuseppe.tsptest, PID: 4651
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.InputStream.read(byte[], int, int)' on a null object reference
at be.tarsos.dsp.io.UniversalAudioInputStream.read(Unknown Source)
at be.tarsos.dsp.AudioDispatcher.processFirstBuffer(Unknown Source)
at be.tarsos.dsp.AudioDispatcher.runSourcedDispatcher(Unknown Source)
at be.tarsos.dsp.AudioDispatcher.run(Unknown Source) [...]