Reading wav file in Java
The official Java Sound Programmer Guide walks through reading and writing audio files.
This article by A Greensted: Reading and Writing Wav Files in java should be helpful. The WavFile class is very useful and it can be tweaked to return the entire data array instead of buffered fragments.
reading a wav file in java
You need to download the java files from HERE and add them to the same package as your code.
then change this line:
WavFile wavFile = WavFile.openWavFile(new File(args[0]));
to:
WavFile wavFile = WavFile.openWavFile(new File("D:/p.wav"));
reading wav/wave file into short[] array
Bring it in via an AudioInputStream as one normally does for sound.
With each buffer load you grab from the stream, iterate through it, two bytes at a time (if it is 16-bit encoding) and use your favorite algorithm to convert the two bytes to a single short int. (Depends if file is Big-Endian or Little-Endian.)
Then, save the results by appending to your preferred form of short array, instead of posting to a SourceDataLine like is done in the more usual playback situations.
Quote from Java Tutorials:
Because the Java Sound API gives you access to the audio data as an
array of bytes, you can alter these bytes in any way you choose.
You might check out the code in this Java sound tutorial: Using Files and Format Converters, the section "Reading Sound Files" and note the comment: "Here, do something useful with the audio data that's now in the audioBytes array..."
For example, that something useful might be:
myShortArray[i] = (short)(( buffer[i*2] & 0xff )|( buffer[i*2 + 1] << 8 ));
buffer = byte buffer receiving the AudioInputStream.
i = index into the arrays.
How to read compressed .wav audio files in Java?
The issue is perhaps you have not used java to downsample audio.
Either
downsample .wav using java and then check its
working.
Good reference for Java-based downsampling and
this
OR
resample .wav using third party libraries and test. Reference for
Re-sample using third-party library
Related Topics
Junit - Run Set Up Method Once
How to Set Base Url for Rest in Spring Boot
Java Gif Animation Not Repainting Correctly
Capturing Browser Logs with Selenium Webdriver Using Java
JSON - Iterate Through JSONarray
Is the in Relation in Cassandra Bad for Queries
What Is the Point of Getters and Setters
Totally Confused with Java.Exe
How to Get a Token from a Lucene Tokenstream
Java Server with Multiclient Communication
Could Not Serialize Object Cause of Hibernateproxy
Method Calls Inside a Java Class Return an "Identifier Expected After This Token" Error
Implementing Custom Methods of Spring Data Repository and Exposing Them Through Rest
Minimum Spring Version Compatible with Java 11
Why Can Array Constants Only Be Used in Initializers