如何将微信上传AMR格式语音转化为MP3格式

1. 服务器安装ffmpeg

2. 执行命令 ffmpeg -i {amr_file_path} -f mp3 -acodec libmp3lame -y {mp3_file_path}

    public static boolean changeAmr2Mp3(final String ffmpegPath, final String amrFilePath, final String mp3FilePath) {

        if (!Mp3TranslateUtils.checkfile(amrFilePath)) {
            Mp3TranslateUtils.LOGGER.error(amrFilePath + " is not file");
            return false;
        }

        final List<String> command = new ArrayList<String>();
        command.add(ffmpegPath);
        command.add("-i");
        command.add(amrFilePath);
        command.add("-f");
        command.add("mp3");
        command.add("-acodec");
        command.add("libmp3lame");
        command.add("-y");
        command.add(mp3FilePath);
        try {
            final ProcessBuilder builder = new ProcessBuilder();
            builder.redirectErrorStream(true);
            builder.command(commend);
            final Process process = builder.start();
            try {
                process.waitFor();
            } catch (final InterruptedException e) {
                e.printStackTrace();
                Thread.currentThread().interrupt();
            }
            process.getErrorStream().close();
            return true;
        } catch (final Exception e) {
            e.printStackTrace();
            return false;
        }
    }

 

posted @ 2017-04-17 15:20  栖息之鹰  阅读(337)  评论(0编辑  收藏  举报