2

私のプロジェクトは、オーディオ ファイルの特徴抽出と分類を実行できる Android アプリを作成することです。最初に、テスト実行として Java アプリケーションを作成します。

jAudio の機能抽出パッケージを使用して、オーディオ ファイルからオーディオ機能を抽出しようとしています。

手始めに、.wav ファイルを入力し、そのファイルに対して特徴抽出操作を実行し、結果を .ARFF ファイルとして保存します。

ただし、プロジェクト内のパッケージから以下の NullPointer Exception エラーが発生しています。

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)

最初はファイル許可の問題だと思っていました (つまり、プログラムは許可がないためにファイルへの書き込みが許可されていませんでした) が、Eclipse 4.2.2 にあらゆる種類の許可を付与した後でも (私は Windows 7 を実行しています。 64 ビット バージョン)、まだ NullException バグが発生しています。

問題の例外が発生するパッケージ コードを以下に示します。

/**
     * 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);
        }
    }

主なアプリケーション コードは次のとおりです。

 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.

       }
     }

ここまでのプロジェクト全体をダウンロードできます。

4

1 に答える 1

0

これは少し遅れているかもしれませんが、私は同じ問題を抱えていて、DataModel に設定されていない featureKey と featureValue まで追跡しました。これらの set メソッドはありませんが、パブリック フィールドです。これが私のコードです:

    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();
        }
    }

}

GUI を使用して settings.xml ファイルを作成し、jar ファイルを保存したディレクトリから features.xml ファイルをコピーしました。

お役に立てれば

于 2016-03-16T10:04:05.760 に答える