Linux centos 7 ,mac java调用微信高清语音speex转wav

linux 专用

yum install speex
yum install speex-devel

Mac

brew install speex

安装 微信 dec lib

如果消失了,可以到github 找一下WeChat speex 的项目,基本都可以
git clone https://github.com/gamelife1314/wechat-speex-declib.git

cd wechat-speex-declib && make && cp ./bin/speex_decode /usr/local/bin/speex2wav

测试

speex2wav s.speex t.wav

下载mediaId 使用新接口

String url = "https://api.weixin.qq.com/cgi-bin/media/get/jssdk?access_token=" + accessToken + "&media_id=" + mediaId + "";

java 调用

public class SpeexUntils {

    public static String speex2wav(String speex, String wav) {
        String command = MessageFormat.format("speex2wav {0} {1}", speex, wav);
        return execCommand(command);
    }


    public static String execCommand(String command) {

        System.out.println(command);

        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(command + " ");
        Process process = null;
        try {
            process = Runtime.getRuntime().exec(command);
            final Process p = process;
            p.waitFor();

            InputStreamReader inputStreamReader = new InputStreamReader(p.getInputStream());
            BufferedReader br = new BufferedReader(inputStreamReader, 4096);
            String line = null;
            int i = 0;
            while ((line = br.readLine()) != null) {

                stringBuffer.append(line);
                System.out.println(line);
            }

            br.close();
            inputStreamReader.close();
            p.exitValue();
            return stringBuffer.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "exception";
        }
    }
}

曲折

由于WeChat 对 speex 进行了加工,标准的speex4j 用不起来。
除非有大神也加工一下speex4j

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容