// Import necessary libraries import java.io.File; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.UnsupportedAudioFileException; import javax.sound.sampled.spi.FormatConversionProvider; public class G711aToAAC { public static void main(String[] args) { // Get the input file File inputFile = new File("input.g711a"); // Get the output file File outputFile = new File("output.aac"); try { // Get the audio input stream from the input file AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputFile); // Get the audio format of the input file AudioFormat sourceFormat = audioInputStream.getFormat(); // Set the target audio format AudioFormat targetFormat = new AudioFormat(AudioFormat.Encoding.AAC, sourceFormat.getSampleRate(), sourceFormat.getSampleSizeInBits(), sourceFormat.getChannels(), sourceFormat.getFrameSize(), sourceFormat.getFrameRate(), false); // Get the format conversion provider FormatConversionProvider formatConversionProvider = AudioSystem.getFormatConversionProviders()[0]; // Convert the audio input stream to the target format AudioInputStream convertedAudioInputStream = formatConversionProvider.getAudioInputStream(targetFormat, audioInputStream); // Write the converted audio input stream to the output file AudioSystem.write(convertedAudioInputStream, AudioFileFormat.Type.AAC, outputFile); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }
标签:sampled,java,sourceFormat,file,import,G711a,input,ChatGPT,javax From: https://www.cnblogs.com/qwangg/p/17116830.html