1

我正在使用 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)   [...]
4

1 回答 1

1

PipeDecoder确实是特定于平台的。它仅适用于avconv存在可执行文件的机器(UNIX、Windows)。它通过调用这个可执行文件来工作,例如一个以 44.1kHz 采样的 MP3,它通过管道以请求的采样率返回解码的 PCM 样本。'avconv' 可以被任何可以通过管道解码、重新采样和流式传输音频的可执行文件替换(例如 ffmpeg 和 SoX)。

由于Android本质上是Unix,因此原则上可以在Android上运行,但实际上(据我所知)很难在Android上安装avconv。解决方案是寻找平台特定的音频解码器或提供此功能的 Java 库(例如 jlayer)。

一旦有了 pcm 样本,这些样本就可以轻松进入 TarsosDSP 音频管道。

于 2015-03-03T13:51:01.143 回答