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
网友评论