Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取错误“;仅支持bitsPerSample 8或16“;_Java_Android_Wav - Fatal编程技术网

Java 获取错误“;仅支持bitsPerSample 8或16“;

Java 获取错误“;仅支持bitsPerSample 8或16“;,java,android,wav,Java,Android,Wav,我想比较两个音频文件,所以为此我使用了库。但我得到一个错误“WaveHeader:仅支持bitsPerSample 8或16” 代码: String root = getExternalFilesDir(null).toString(); Log.i(TAG, root); String bell1 = "bell1.wav"; String bell2 = "DOORBELL-3_SPLITTED.wav"; String fullPath1 = root + File.separator

我想比较两个音频文件,所以为此我使用了库。但我得到一个错误“WaveHeader:仅支持bitsPerSample 8或16”

代码:

String root = getExternalFilesDir(null).toString();
Log.i(TAG, root);

String bell1 = "bell1.wav";
String bell2 = "DOORBELL-3_SPLITTED.wav";
String fullPath1 = root + File.separator + bell1;               
String fullPath2 = root + File.separator + bell2;               

Log.i(TAG, "Full Path 1: " + fullPath1);
Log.i(TAG, "Full Path 2: " + fullPath2);

File f = new File(fullPath2);
Log.i(TAG, "" + f.canRead());

Wave b1 = new Wave(fullPath1);
Wave b2 = new Wave(fullPath2);
我得到了以下错误

堆栈跟踪:

11-25 00:17:08.597: I/MainActivity(26472): /storage/sdcard0/Android/data/com.musicg.demo.android/files
11-25 00:17:08.597: I/MainActivity(26472): Full Path 1: /storage/sdcard0/Android/data/com.musicg.demo.android/files/bell1.wav
11-25 00:17:08.597: I/MainActivity(26472): Full Path 2: /storage/sdcard0/Android/data/com.musicg.demo.android/files/DOORBELL-3_SPLITTED.wav
11-25 00:17:08.597: I/MainActivity(26472): true
11-25 00:17:08.602: W/System.err(26472): WaveHeader: only supports bitsPerSample 8 or 16
11-25 00:17:08.602: W/System.err(26472): Invalid Wave Header
11-25 00:17:08.602: I/MainActivity(26472): Length : 0.25
11-25 00:17:08.602: I/MainActivity(26472): Size : 48001
11-25 00:17:08.602: I/MainActivity(26472): Length : NaN
11-25 00:17:08.602: D/AndroidRuntime(26472): Shutting down VM
11-25 00:17:08.602: W/dalvikvm(26472): threadid=1: thread exiting with uncaught exception (group=0x41e542a0)
11-25 00:17:08.612: E/AndroidRuntime(26472): FATAL EXCEPTION: main
11-25 00:17:08.612: E/AndroidRuntime(26472): java.lang.NullPointerException
11-25 00:17:08.612: E/AndroidRuntime(26472):    at com.musicg.wave.Wave.size(Wave.java:255)
11-25 00:17:08.612: E/AndroidRuntime(26472):    at com.musicg.demo.android.MainActivity$ClickEvent.onClick(MainActivity.java:139)
11-25 00:17:08.612: E/AndroidRuntime(26472):    at android.view.View.performClick(View.java:4261)
11-25 00:17:08.612: E/AndroidRuntime(26472):    at android.view.View$PerformClick.run(View.java:17356)
11-25 00:17:08.612: E/AndroidRuntime(26472):    at android.os.Handler.handleCallback(Handler.java:615)
11-25 00:17:08.612: E/AndroidRuntime(26472):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-25 00:17:08.612: E/AndroidRuntime(26472):    at android.os.Looper.loop(Looper.java:137)
11-25 00:17:08.612: E/AndroidRuntime(26472):    at android.app.ActivityThread.main(ActivityThread.java:4921)
11-25 00:17:08.612: E/AndroidRuntime(26472):    at java.lang.reflect.Method.invokeNative(Native Method)
11-25 00:17:08.612: E/AndroidRuntime(26472):    at java.lang.reflect.Method.invoke(Method.java:511)
11-25 00:17:08.612: E/AndroidRuntime(26472):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
11-25 00:17:08.612: E/AndroidRuntime(26472):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
11-25 00:17:08.612: E/AndroidRuntime(26472):    at dalvik.system.NativeStart.main(Native Method)

Wave.java:255和MainActivity.java:139上有什么?我还没有看过musicg的源代码,所以我不能确定。但我认为现在的情况是,musicg只支持8或16位的每个样本大小。因此,当它读取wave文件时,它解析头文件,如果bitsPerSample不是8或16,则抛出一个错误。可能值得尝试另一个具有以下示例大小之一的音频文件。还有其他库可能支持不同的bitsPerSample或至少解析文件,并允许您阅读此信息以确保此推测是真实的(例如libsndfile)。@Sun您能推荐一个好的java脱机音频检测库吗。@Arsalan可能值得阅读此文章。链接到此库的答案之一:。我还没有真正使用过任何java库来实现这类功能,所以我无法评论它们有多好,但是WavFile类似乎支持24,26,8位分辨率。@Arsalan您解决了问题吗?我吃的和你的一样。