Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Converting wav file formats Using java Sound API  RSS feed

murali chevuri
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My name is Murali. I am doing project on Sound Systems. My work is converting the differen wav file formats to a Standard format. For example 44000 sampled rate wav file to 8000 Sample rate. When I am trying to converting the file. I am getting exception like Unsupported Conversion. Please help me. Thanks in advance. I am sending my code. Please check and advise me.


import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;

public class Audio

int nDefaultSampleSizeInBits = 16;
float fDefaultSampleRate = 8000;
AudioFormat.Encoding defaultEncoding = AudioFormat.Encoding.PCM_SIGNED;
AudioFileFormat.Type defaultFileType = AudioFileFormat.Type.WAVE;
boolean bDefaultBigEndian = false;
int nDefaultChannels = 1;
float frameRate= 8000;
int frameSize = 2;
AudioFormatdefaultFormat = null;
File inputFile = null;
File outputFile = null;

public Audio(String sou,String tar)

//Standard Format
defaultFormat = new AudioFormat(defaultEncoding,fDefaultSampleRate,nDefaultSampleSizeInBits,nDefaultChannels,frameSize,frameRate,bDefaultBigEndian);
inputFile = new File(sou);
outputFile = new File(tar);
catch(Exception e)

protected void convert() throws UnsupportedAudioFileException, IOException

AudioFileFormatinputFileFormat = AudioSystem.getAudioFileFormat(inputFile);
AudioFormatinputFormat = inputFileFormat.getFormat();

System.out.println("No Change");
AudioInputStream sourceStream = AudioSystem.getAudioInputStream(inputFile);
intnWrittenBytes = 0;
AudioInputStream stream = AudioSystem.getAudioInputStream(defaultFormat,sourceStream);
nWrittenBytes = AudioSystem.write(stream, defaultFileType, outputFile);
System.out.println("Written bytes: " + nWrittenBytes);

public static void main(String args[])
new Audio(args[0],args[1]);
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!