jAudio特征提取器:空异常 [英] jAudio Feature Extractor : Null Exception

查看:285
本文介绍了jAudio特征提取器:空异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目是创建一个可以执行音频文件特征提取和分类的Android应用程序。首先,我正在创建一个Java应用程序作为测试运行。



我正在尝试使用jAudio的功能提取程序包从音频文件中提取音频功能。 / p>

作为起动器,我想输入一个.wav文件,并在该文件上运行特征提取操作,然后将结果存储为.ARFF文件。



但是,我从项目中的包中得到以下NullPointer异常错误:

 线程中的异常mainjava.lang.NullPointerException 
在java.io.DataOutputStream.writeBytes(未知来源)
在jAudioFeatureExtractor.jAudioTools.FeatureProcessor.writeValuesARFFHeader(FeatureProcessor.java :853)
at jAudioFeatureExtractor.jAudioTools.FeatureProcessor。< init>(FeatureProcessor.java:258)
在jAudioFeatureExtractor.DataModel.extract(DataModel.java:308)
在Mfccarffwriter.main (Mfccarffwriter.java:70)

最初我以为这是一个文件权限问题(即程序由于缺少权限,不允许写入文件),但即使在向Eclipse 4.2.2(我运行的是Windows 7,64位版本)授予各种权限之后,我仍然收到NullException错误。



包含代码的违规异常o以下给出了以下内容:

  / ** 
*为ARFF文件写入头文件。如果保存整体功能,则必须
*推迟才能计算出整体功能。如果这是一个
* perWindow arff文件,那么所有的功能头可以现在提取
*,不需要黑客。
*< p>
*< b>注意< / b>:如果要保存的功能具有
*可变数量的维度,则此过程将中断
*
* @throws异常
* /
private void writeValuesARFFHeader()throws Exception {
String sep = System.getProperty(line.separator);
String feature_value_header =@relation jAudio+ sep;
values_writer.writeBytes(feature_value_header); // exception here
if(save_features_for_each_window&!save_overall_recording_features){
for(int i = 0; i< feature_extractors.length; ++ i){
if(features_to_save [ i]){
String name = feature_extractors [i] .getFeatureDefinition()。name;
int dimension = feature_extractors [i]
.getFeatureDefinition()。dimensions; $ int $ {
$ _ + sep);
}
}
}
values_writer.writeBytes(sep);
values_writer.writeBytes(@ DATA+ sep);
}
}

这是主要的应用程序代码:

  import java.io. *; 
import java.util.Arrays;

import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil.ToStringAdapter;

import jAudioFeatureExtractor.Cancel;
import jAudioFeatureExtractor.DataModel;
import jAudioFeatureExtractor.Updater;
import jAudioFeatureExtractor.Aggregators.AggregatorContainer;
import jAudioFeatureExtractor.AudioFeatures.FeatureExtractor;
import jAudioFeatureExtractor.AudioFeatures.MFCC;
import jAudioFeatureExtractor.DataTypes.RecordingInfo;
import jAudioFeatureExtractor.jAudioTools。*;


public static void main(String [] args)throws异常{

//显示有关wav文件的信息
文件extractFiletoTest = new File ( ./microwave1.wav);

String randomID = Integer.toString((int)Math.random());

String file_path =E:/Weka-3-6/tmp/microwave1.wav;
AudioSamples sampledExampleFile = new AudioSamples(extractedFiletoTest,randomID,false);

RecordingInfo [] samplefileInfo = new RecordingInfo [5];
samplefileInfo [1] = new RecordingInfo(randomID,file_path,sampledExampleFile,true);

double samplingrate = sampledExampleFile.getSamplingRateAsDouble();
int windowsize = 4096;
boolean normalize = false;

OutputStream valsavepath = new FileOutputStream(。\\\values);
OutputStream defsavepath = new FileOutputStream(。\\\definitions);

boolean [] featurestosaveamongall = new boolean [10];
Arrays.fill(featurestosaveamongall,Boolean.TRUE);

double windowoverlap = 0.0;

DataModel mfccDM = new DataModel(features.xml,null);

mfccDM.extract(windowsize,0.5,samplingrate,true,true,false,samplefileInfo,1); ///调用writeValuesARFFHeader函数。

}
}

您可以下载整个项目到目前为止)此处

解决方案

这可能有点迟了,但是我遇到了同样的问题,并将其跟踪到FeatureMey和featureValue从未在DataModel中设置。没有一种方法,但它们是公共场。这是我的代码:

 包声音; 

import jAudioFeatureExtractor.ACE.DataTypes.Batch;
import jAudioFeatureExtractor.DataModel;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

public class Analysis {

private static String musicFile =/home/chris/IdeaProjects/AnotherProj/res/SheMovesInHerOwnWay15s.wav;
private static String featureFile =/home/chris/IdeaProjects/AnotherProj/res/features.xml;
private static String settingsFile =/home/chris/IdeaProjects/AnotherProj/res/settings.xml;
private static String FKOuputFile =/home/chris/IdeaProjects/AnotherProj/res/fk.xml;
private static String FVOuputFile =/home/chris/IdeaProjects/AnotherProj/res/fv.xml;

public static void main(String [] args){
批量批次= new Batch(featureFile,null);
try {
batch.setRecordings(new File [] {new File(musicFile)});
batch.getAggregator();
batch.setSettings(settingsFile);

DataModel dm = batch.getDataModel();
OutputStream valsavepath = new FileOutputStream(FVOuputFile);
OutputStream defsavepath = new FileOutputStream(FKOuputFile);
dm.featureKey = defsavepath;
dm.featureValue = valsavepath;
batch.setDataModel(dm);

batch.execute();
}
catch(异常e){
e.printStackTrace();
}
}

}

我创建settings.xml文件使用GUI,并从您保存jar的目录中复制了features.xml文件。



希望这有助于


My project is to create an Android app that can perform feature extraction and classification of audio files. So first, I'm creating a Java application as a test run.

I'm attempting to use jAudio's feature extractor package to extract audio features from an audio file.

As a starter, I want to input a .wav file and run the feature extraction operation upon that file, and then store the results as an .ARFF file.

However, I'm getting the below NullPointer Exception error from a package within the project:

Exception in thread "main" java.lang.NullPointerException
    at java.io.DataOutputStream.writeBytes(Unknown Source)
    at jAudioFeatureExtractor.jAudioTools.FeatureProcessor.writeValuesARFFHeader(FeatureProcessor.java:853)
    at jAudioFeatureExtractor.jAudioTools.FeatureProcessor.<init>(FeatureProcessor.java:258)
    at jAudioFeatureExtractor.DataModel.extract(DataModel.java:308)
    at Mfccarffwriter.main(Mfccarffwriter.java:70)

Initially I thought it was a file permission issue(i.e, the program was not being allowed to write a file because of lack of permissions), but even after granting every kind of permission to Eclipse 4.2.2(I'm running Windows 7, 64 bit version), I'm still getting the NullException bug.

The package code where the offending exception originates from is given below:

/**
     * Write headers for an ARFF file. If saving for overall features, this must
     * be postponed until the overall features have been calculated. If this a
     * perWindow arff file, then all the feature headers can be extracted now
     * and no hacks are needed.
     * <p>
     * <b>NOTE</b>: This procedure breaks if a feature to be saved has a
     * variable number of dimensions
     * 
     * @throws Exception
     */
    private void writeValuesARFFHeader() throws Exception {
        String sep = System.getProperty("line.separator");
        String feature_value_header = "@relation jAudio" + sep;
        values_writer.writeBytes(feature_value_header);   // exception here
        if (save_features_for_each_window && !save_overall_recording_features) {
            for (int i = 0; i < feature_extractors.length; ++i) {
                if (features_to_save[i]) {
                    String name = feature_extractors[i].getFeatureDefinition().name;
                    int dimension = feature_extractors[i]
                            .getFeatureDefinition().dimensions;
                    for (int j = 0; j < dimension; ++j) {
                        values_writer.writeBytes("@ATTRIBUTE \"" + name + j
                                + "\" NUMERIC" + sep);
                    }
                }
            }
            values_writer.writeBytes(sep);
            values_writer.writeBytes("@DATA" + sep);
        }
    }

Here's the main application code:

 import java.io.*;
import java.util.Arrays;

import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil.ToStringAdapter;

import jAudioFeatureExtractor.Cancel;
import jAudioFeatureExtractor.DataModel;
import jAudioFeatureExtractor.Updater;
import jAudioFeatureExtractor.Aggregators.AggregatorContainer;
import jAudioFeatureExtractor.AudioFeatures.FeatureExtractor;
import jAudioFeatureExtractor.AudioFeatures.MFCC;
import jAudioFeatureExtractor.DataTypes.RecordingInfo;
import jAudioFeatureExtractor.jAudioTools.*;


     public static void main(String[] args) throws Exception {

         // Display information about the wav file
         File extractedFiletoTest = new File("./microwave1.wav");

         String randomID = Integer.toString((int) Math.random());

         String file_path = "E:/Weka-3-6/tmp/microwave1.wav";
         AudioSamples sampledExampleFile = new AudioSamples(extractedFiletoTest,randomID,false);

         RecordingInfo[] samplefileInfo = new RecordingInfo[5];
         samplefileInfo[1] = new RecordingInfo(randomID, file_path, sampledExampleFile, true);

         double samplingrate= sampledExampleFile.getSamplingRateAsDouble();
         int windowsize= 4096;
         boolean normalize = false;

        OutputStream valsavepath = new FileOutputStream(".\\values");
         OutputStream defsavepath = new FileOutputStream(".\\definitions");

         boolean[] featurestosaveamongall = new boolean[10];
         Arrays.fill(featurestosaveamongall, Boolean.TRUE);

         double windowoverlap = 0.0;

        DataModel mfccDM = new DataModel("features.xml",null);

         mfccDM.extract(windowsize, 0.5, samplingrate, true, true, false, samplefileInfo, 1); /// invokes the writeValuesARFFHeader function.

       }
     }

You can download the whole project (done so far)here.

解决方案

This may be a bit late but I had the same issue and I tracked it down to the featureKey and featureValue never being set in the DataModel. There is not a set method for these but they are public field. Here is my code:

    package Sound;

import jAudioFeatureExtractor.ACE.DataTypes.Batch;
import jAudioFeatureExtractor.DataModel;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

public class Analysis {

    private static String musicFile = "/home/chris/IdeaProjects/AnotherProj/res/SheMovesInHerOwnWay15s.wav";
    private static String featureFile = "/home/chris/IdeaProjects/AnotherProj/res/features.xml";
    private static String settingsFile = "/home/chris/IdeaProjects/AnotherProj/res/settings.xml";
    private static String FKOuputFile = "/home/chris/IdeaProjects/AnotherProj/res/fk.xml";
    private static String FVOuputFile = "/home/chris/IdeaProjects/AnotherProj/res/fv.xml";

    public static void main(String[] args){
        Batch batch = new Batch(featureFile, null);
        try{
            batch.setRecordings(new File[]{new File(musicFile)});
            batch.getAggregator();
            batch.setSettings(settingsFile);

            DataModel dm = batch.getDataModel();
            OutputStream valsavepath = new FileOutputStream(FVOuputFile);
            OutputStream defsavepath = new FileOutputStream(FKOuputFile);
            dm.featureKey = defsavepath;
            dm.featureValue = valsavepath;
            batch.setDataModel(dm);

            batch.execute();
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

}

I created the settings.xml file using the GUI and just copied the features.xml file from the directory where you saved the jar.

Hope this helps

这篇关于jAudio特征提取器:空异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆