Trouble playing wav in Java

I’m not sure why the second approach you linked to starts another thread; I believe the audio will be played in its own thread anyway. Is the problem that your application finishes before the clip has finished playing? import javax.sound.sampled.*; import java.io.File; import java.io.IOException; import javax.sound.sampled.LineEvent.Type; private static void playClip(File clipFile) throws IOException, UnsupportedAudioFileException, LineUnavailableException, … Read more

C++ Reading the Data part of a WAV file

This image is taken from a Stanford course So you can see that the audio data occurs immediately after the headers you already read and there will be Subchunk2Size bytes of audio data. The pseudocode for this would be ReadRIFF(); ReadFMT(); int32 chunk2Id = Read32(BigEndian); int32 chunk2Size = Read32(LittleEndian); for (int i = 0; i … Read more

What do the bytes in a .wav file represent?

You will have heard, that audio signals are represented by some kind of wave. If you have ever seen this wave diagrams with a line going up and down — that’s basically what’s inside those files. Take a look at this file picture from http://en.wikipedia.org/wiki/Sampling_rate You see your audio wave (the gray line). The current … Read more

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

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

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