英文:
How to convert ogg file to wav using Java?
问题
我在GitHub和Google上搜索,但没有找到一个好的解决方案。
背景:
我正在编写一个Telegram机器人,想要使用Microsoft的Java语音转文本SDK将用户的语音消息转录为文本。该SDK只接受wav文件,因此我需要首先将ogg文件转换为wav文件。
我想找到一个使用Java将ogg文件转换为wav文件的解决方案。
英文:
I search through Github and Google, but not found a good solution.
background:
I'm writing a Telegram bot and want to transcript user's voice message to text using Microsoft's speech-to-text java sdk, the sdk only accept wav files, so I need to first transform ogg files to wav files.
I want to find a solution to convert ogg file to wav using Java.
答案1
得分: 0
finally, I used ffmpeg https://www.ffmpeg.org/ to transform first, it works. Installation of ffmpeg required to run this code
String fileName = file.getName();
String wavFileName = fileName + ".wav";
String cmd = "ffmpeg -i " + fileName + " ./" + wavFileName;
try {
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw a RuntimeException(e);
}
英文:
finally, I used ffmpeg https://www.ffmpeg.org/ to transform first, it works. Installation of ffmpeg required to run this code
String fileName = file.getName();
String wavFileName = fileName + ".wav";
String cmd = "ffmpeg -i " + fileName + " ./" + wavFileName;
try {
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论