不好意思,误导大家了,这种将silk解密的方式只是在小程序测试的时候可以,上线以后这种方法是不行的,还是需要使用解密转码。参见: https://github测试数据/kn007/silk-v3-decoder
微信小程序 的 录音 文件 就是个坑。。。
录音文件为silk格式,说是silk其实是base64加密后的webm格式,只需将其转为webm格式即可。
我在解决问题的过程中,学到了,遇到问题一定要抓住本质,本来我以为silk是啥格式,这不懵逼了,赶紧找audio是否能播放silk,不能播放就去找网上的转换代码,完全没考虑看看录音文件里面是什么内容,折腾了一顿以后回到问题的本质,silk文件里的内容是base64加密后的webm格式。这样进行base64解密就可以了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import java.io.bufferedreader; import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.io.ioexception; import java.io.inputstreamreader; import com.qcloud.utilities.base64; public class base64webm { public static void readtxtfile(string filepath) { try { string encoding = "utf-8" ; file file = new file(filepath); if (file.isfile() && file.exists()) { // 判断文件是否存在 inputstreamreader read = new inputstreamreader( new fileinputstream(file), encoding); // 考虑到编码格式 bufferedreader bufferedreader = new bufferedreader(read); stringbuilder linetxt = new stringbuilder(); string line = null ; while ((line = bufferedreader.readline()) != null ) { linetxt.append(line); } read.close();
string olddata = linetxt.tostring(); olddata = olddata.replace( "data:audio/webm;base64," , "" ); system.out.println(olddata);
try {
file webmfile = new file( "d:\\project\\liulei\\doc\\互动直播室\\微课网页开发\\silk2mp3\\caole.webm" ); byte [] bt = base64.decode(olddata) ; fileoutputstream in = new fileoutputstream(webmfile); try { in.write(bt, 0 , bt.length); in.close(); // boolean success=true; // system.out.println("写入文件成功"); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } catch (filenotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } } else { system.out.println( "找不到指定的文件" ); } } catch (exception e) { system.out.println( "读取文件内容出错" ); e.printstacktrace(); } }
public static void main(string[] args) { readtxtfile( "d:\\project\\liulei\\doc\\互动直播室\\微课网页开发\\silk2mp3\\liulie.silk" ); } } |
总结
以上所述是小编给大家介绍的微信小程序录音文件格式silk遇到的问题及解决方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
原文链接:https://blog.csdn.net/rjliulei/article/details/77800760
查看更多关于微信小程序录音文件格式silk遇到的问题及解决方法的详细内容...