如何使用Java将ogg文件转换为wav文件?

huangapple go评论60阅读模式
英文:

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);
            }

huangapple
  • 本文由 发表于 2023年2月24日 10:21:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75552091.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定