java 如何在java中编写FLAC文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7466698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to write FLAC files in java
提问by Raveesh Sharma
I have a requirement to write FLAC files in java. Earlier I was writing the audio input into a WAV file and then converting it to FLAC file using a external converter
我需要用 java 编写 FLAC 文件。早些时候我将音频输入写入 WAV 文件,然后使用外部转换器将其转换为 FLAC 文件
I was looking into JFlac to find any API through which I can write FLAC files. I found that AudioFileFormat.TYPE in java supports only the following file formats - AIFC, AIFF, SND, AU, WAVE .
我正在研究 JFlac 以找到任何可以编写 FLAC 文件的 API。我发现 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。
回答by nxhoaf
You can use thislib. Here is a simple example using version 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. For more documentation, see here:
你可以使用这个库。这是一个使用版本 0.2.3 (javaFlacEncoder-0.2.3-all.tar.gz) 的简单示例。提取下载的文件,然后将 javaFlacEncoder-0.2.3.jar 导入到您的项目中。有关更多文档,请参见此处:
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");
}
}
回答by Alexey Romanov
You canwrite audio stream directly to a FLAC file with javaflacencoder:
您可以使用 javaflacencoder 将音频流直接写入 FLAC 文件:
AudioSystem.write(audioInputStream, FLACFileWriter.FLAC, new File("E:\temp.flac"));
回答by kijong
If you want to change sample rates, use ffmpeglike this ffmpeg -i sourcefile.wav -ar 16000 targetfile.flac
如果你想改变采样率, 像这样 使用ffmpeg ffmpeg -i sourcefile.wav -ar 16000 targetfile.flac