2

I want to compare two audio file, so for this I'm using library musicg. but i'm getting an error "WaveHeader: only supports bitsPerSample 8 or 16"

Code :

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

and i'm getting following error.

StackTrace :

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)
Arsalan
  • 493
  • 7
  • 22
  • What is there on line Wave.java:255 and MainActivity.java:139? – Joel Fernandes Nov 24 '13 at 19:46
  • I haven't looked at musicg source so I cannot be sure. But what I think is happening, is that musicg only supports bits per Sample size of 8 or 16. So when it reads the wave file, it parses the header and throws an error if the bitsPerSample is not 8 or 16. Might be worth trying another audio file which has one of these sample sizes. There's other libraries out there that may support different bitsPerSample or atleast parse the file and allow you to read this info to make sure this speculation is true (like for example libsndfile). – Sun Nov 24 '13 at 19:55
  • @Sun can you suggest a good library for offline audio sound detection in java. – Arsalan Nov 25 '13 at 15:15
  • @Arsalan might be worth reading this post http://stackoverflow.com/questions/3297749/java-reading-manipulating-and-writing-wav-files . One of the answers linked to this library: http://www.labbookpages.co.uk/audio/javaWavFiles.html#reading . I havn't really used any java libraries for this sort of thing so I cannot comment on how good they are, but the WavFile file class seems to support 24,26,8 bit resolutions. – Sun Nov 26 '13 at 12:07
  • @Arsalan have you fixed your problem? I'm having the same as yours. – fsi Mar 20 '14 at 16:33
  • @fsi Nope, I failed to fix the problem...! – Arsalan Mar 21 '14 at 09:14
  • From @Sun that give the link `javaWavFiles`, I tested and the converted file isn't a wav file! even though it says 16bits per sample or 2 bytes. – fsi Mar 21 '14 at 12:20
  • I'm here with the same issue in 2019 :( – Asif Sb Mar 21 '19 at 10:57

0 Answers0