Tuesday, May 3, 2011

Audio Conversion

Audio Conversion

It is not only enough to archive documents but it is really important to convert audio formats to archival audio file format when archiving audio.
The .wav can be identify as the archival format for the audio. wav stands for Waveform Audio File Format and standard for storing an audio bit stream on personal computers. The wav is flexible file formats designed to store more or less any combination of sampling rates or bit rates. This makes it suitable file format for storing and archiving an original recording.

To convert audio files we can use JLayer library.

convert .mp3 to .wav can done using the bellow line, by importing the jlayer.

import javazoom.jl.converter.Converter;

Converter audiocon = new Converter();
audiocon.convert(inputfile, outputfile);


to convert .aiff and .au audio files we can use javax.sound as the bellow,

import javax.sound.sampled.*;

public String convert_to_wav(String inputFile, String outputFile){

AudioFileFormat inFileFormat;
File inFile;
File outFile;

inFile = new File(inputFile);
outFile = new File(outputfile);

try {
// query file type
inFileFormat = AudioSystem.getAudioFileFormat(inFile);


AudioInputStream inFileAIS =
AudioSystem.getAudioInputStream(inFile);

if (AudioSystem.isFileTypeSupported(
AudioFileFormat.Type.WAVE, inFileAIS)) {

AudioSystem.write(inFileAIS,
AudioFileFormat.Type.WAVE, outFile);
System.out.println("Successfully done conversion, "
+ outFile.getPath() + ", from "
+ inFileFormat.getType() + " file, " +
inFile.getPath() + ".");
inFileAIS.close();

} else
System.out.println("Warning: AIFF conversion of "
+ inFile.getPath()
+ " is not currently supported by AudioSystem.");
} catch (UnsupportedAudioFileException e) {
System.out.println("Error: " + inFile.getPath()
+ " is not a supported audio file type!");
e.printStackTrace();
} catch (IOException e) {
System.out.println("Error: failure attempting to read "
+ inFile.getPath() + "!");
e.printStackTrace();
}
}

No comments:

Post a Comment