我正在使用musicg库来比较两个音频声音。其中一个保存之前,另一个通过记录检测。 musicg库有whistle演示;我编辑它是为了我想要的工作。问题是当我想将检测到的声音[这是一个缓冲区]转换为wav并获得它的fingurprint时,它返回nullpointerexption。
这是在MainAcivity.java中 的 的
的public static Wave w1;
InputStream sw1 = getBaseContext()。getResources()。openRawResource(R.raw.top_of_the_world_rec);
w1 = new Wave(sw1);
的
这是在DetectorThread.java中 的 的
的 InputStream obj = new ByteArrayInputStream(buffer);
Wave woo = new Wave(obj);
if (woo.toString() == null)
Log.i("", "recoded sound is null");
if (MainActivity.w1.toString() == null)
Log.i("", "the detected sound is null");
try {
similarity = woo.getFingerprintSimilarity(MainActivity.w1);/// this couse null pointer exption
Log.i("", "1-" + similarity); // not appear
if (similarity == null) { // not enter this if at all ~!
Log.i("", "lolol" + similarity);
TheSemilarityISnull = true;
}
}
catch (NullPointerException n) {
Log.i("", "first error");
TheSemilarityISnull = true;
}
// EnD of addition
Log.i("", "2-" + similarity); //appear 2-null
// byte[] io = MainActivity.w1.getFingerprint(); // good no problem
// Log.i("", "00-"+io); // apear bk09823 like this
try {
Log.i("", "0-");
byte[] po = woo.getFingerprint(); // ~> this couse null pointer exption
Log.i("", "0-" + po);
if (po == null)
Log.i("", "fingurprint for detected sound is null ");//not appear
byte[] io = MainActivity.w1.getFingerprint();
Log.i("", "00-" + io);
if (io == null)
Log.i("", "fingurprint for recorded sound is null");//not appear
double scoure = new FingerprintSimilarityComputer(po, io).getFingerprintsSimilarity().getSimilarity();
} catch (Exception e) {
Log.i("", "second error ");
}
的
所以;
1 - 如何将Byte []转换为wav?
2 - 我可以在线程中调用class或Mothed吗? 我不知道每当我打电话给其中一个时它都没有发现任何东西!
3-我根本不编辑记录线程>这会是问题吗? 请帮我。
答案 0 :(得分:0)
读缓冲区不包含任何波形标头。这些只是音频字节。 我已经开始实现一个可能有效的类。但它还不是最终的
public class WavApi extends DetectionApi {
Wave waveToMatch;
public WavApi(Wave wave) {
super(wave.getWaveHeader());
this.waveToMatch = wave;
}
public boolean matches(byte[] audioBytes) {
Wave wave = new Wave(waveToMatch.getWaveHeader(), audioBytes);
FingerprintSimilarityComputer fpc = new FingerprintSimilarityComputer(waveToMatch.getFingerprint(), wave.getFingerprint());
FingerprintSimilarity similarity = fpc.getFingerprintsSimilarity();
//--- TODO: find optimal condition to decide whether {audioBytes} matches {waveToMatch} or not
float sim = similarity.getScore() * 100f;
int pos = similarity.getMostSimilarFramePosition();
if (pos >= 0 && sim > 0)
return true;
//----
return false;
}
}