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.

Java – reading, manipulating and writing WAV files

I read WAV files via an AudioInputStream. The following snippet from the Java Sound Tutorials works well. int totalFramesRead = 0; File fileIn = new File(somePathName); // somePathName is a pre-existing string whose value was // based on a user selection. try { AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(fileIn); int bytesPerFrame = audioInputStream.getFormat().getFrameSize(); if (bytesPerFrame == AudioSystem.NOT_SPECIFIED) … Read more

How to encode a WAV to a mp3 on a Android device

Pure Java Look into Tritonus’s clean room implementation of javasound which offers an MP3 encoder plugin here: http://www.tritonus.org/plugins.html Secondly, I would suggest looking into jzoom’s libraries JLayer or JLayerME: http://www.javazoom.net/javalayer/javalayer.html (this may only be decode, not sure) If those doesn’t suit your need you can look at this article from 2000 about adding MP3 capabilities … Read more

How to join two wav files using python?

Python ships with the wave module that will do what you need. The example below works when the details of the files (mono or stereo, frame rates, etc) are the same: import wave infiles = [“sound_1.wav”, “sound_2.wav”] outfile = “sounds.wav” data= [] for infile in infiles: w = wave.open(infile, ‘rb’) data.append( [w.getparams(), w.readframes(w.getnframes())] ) w.close() … Read more

Detect & Record Audio in Python

As a follow up to Nick Fortescue’s answer, here’s a more complete example of how to record from the microphone and process the resulting data: from sys import byteorder from array import array from struct import pack import pyaudio import wave THRESHOLD = 500 CHUNK_SIZE = 1024 FORMAT = pyaudio.paInt16 RATE = 44100 def is_silent(snd_data): … Read more

Reading *.wav files in Python

Per the documentation, scipy.io.wavfile.read(somefile) returns a tuple of two items: the first is the sampling rate in samples per second, the second is a numpy array with all the data read from the file: from scipy.io import wavfile samplerate, data = wavfile.read(‘./output/audio.wav’)

How to play .wav files with java

Finally I managed to do the following and it works fine import java.io.File; import java.io.IOException; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; public class MakeSound { private final int BUFFER_SIZE = 128000; private File soundFile; private AudioInputStream audioStream; private AudioFormat audioFormat; private SourceDataLine sourceLine; /** * @param filename the name … Read more

Playing .mp3 and .wav in Java?

Java FX has Media and MediaPlayer classes which will play mp3 files. Example code: String bip = “bip.mp3”; Media hit = new Media(new File(bip).toURI().toString()); MediaPlayer mediaPlayer = new MediaPlayer(hit); mediaPlayer.play(); You will need the following import statements: import java.io.File; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer;