适用于Android的TARSOS DSP:检索SpectralPeaks

时间:2015-02-20 17:03:51

标签: android audio signal-processing avconv tarsosdsp

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

1 个答案:

答案 0 :(得分:1)

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

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

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