[英]How to write FLAC files in java
I have a requirement to write FLAC files in java. 我需要用Java编写FLAC文件。 Earlier I was writing the audio input into a WAV file and then converting it to FLAC file using a external converter 之前,我将音频输入写入WAV文件,然后使用外部转换器将其转换为FLAC文件
I was looking into JFlac to find any API through which I can write FLAC files. 我一直在寻找JFlac,以查找可以用来编写FLAC文件的任何API。 I found that AudioFileFormat.TYPE in java supports only the following file formats - AIFC, AIFF, SND, AU, WAVE . 我发现Java中的AudioFileFormat.TYPE仅支持以下文件格式-AIFC,AIFF,SND,AU,WAVE。
I would like to have a method where I can capture the audio from the microphone and, using an API such as Audiosystem.write, write it to a FLAC file instead of WAV file. 我希望有一种方法可以捕获麦克风中的音频,并使用Audiosystem.write等API将其写入FLAC文件而不是WAV文件。
Please suggest a method or an API that can solve my problem. 请提出一种可以解决我的问题的方法或API。
You can use this lib. 您可以使用此库。 Here is a simple example using version 0.2.3 (javaFlacEncoder-0.2.3-all.tar.gz). 这是使用0.2.3版本(javaFlacEncoder-0.2.3-all.tar.gz)的简单示例。 Extract the dowloaded file, and then import javaFlacEncoder-0.2.3.jar to your project. 提取下载的文件,然后将javaFlacEncoder-0.2.3.jar导入您的项目。 For more documentation, see here : 有关更多文档,请参见此处 :
package fr.telecomParisTech;
import java.io.File;
import javaFlacEncoder.FLAC_FileEncoder;
public class SoundConverter {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
FLAC_FileEncoder flacEncoder = new FLAC_FileEncoder();
File inputFile = new File("hello.wav");
File outputFile = new File("hello.flac");
flacEncoder.encode(inputFile, outputFile);
System.out.println("Done");
}
}
您可以使用javaflacencoder将音频流直接写入FLAC文件:
AudioSystem.write(audioInputStream, FLACFileWriter.FLAC, new File("E:\\temp.flac"));
如果要更改采样率,请像这样使用ffmpeg ffmpeg -i sourcefile.wav -ar 16000 targetfile.flac
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.