欢迎光临,了解微信小程序开发,就上易用通!

微信小程序 java服务端记

发布:2018-04-21 10:18浏览: 来源:网络 作者:cola

1、文件上传,使用springmvc一直不想,后来看到别人有一样的情况改成了serverlet就可以了

2、因为要进行语音识别成文字,上传的语音文件是silk格式,需要用到讯飞的语音识别所以必须转成wav,用到了kn007大神的这个工具https://github.com/kn007/silk-v3-decoder才搞定过程比较坎坷

3、还想把返回结果转换成语音文件给小程序进行播放,结果...........silk是有了,但是一直播放不了,因为小程序的silk似乎需要特定的参数格式才行,最后转了个war给前端,让它播放

4、期间使用ffmpeg进行各种格式转换,ffmpeg的参数设置也挺恶心的,下面留一个可用的例子

 

[java] view plain copy
 
  1.     public static void convertAudio(String sourcePath,int sourceHZ,String targetPath,int targetHZ){  
  2.         Properties props=System.getProperties(); //获得系统属性集      
  3.         String osName = props.getProperty("os.name"); //操作系统名称  
  4.         String command = null;  
  5.         if(osName.contains("Windows")){  
  6. //          ffmpeg -y -f s16le -ar 24000 -ac 1 -i "$1.pcm" -f wav -ar 16000 -b:a 16 -ac 1 "${1%.*}.$2"  
  7.             command = "C:\\ffmpeg.exe -y -f s16le -ar "+sourceHZ+" -i "+sourcePath+" -f wav -ar "+targetHZ+" -b:a 8 -ac 1 "+targetPath;           
  8.         }else{  
  9.             command = "/usr/local/ffmpeg/bin/ffmpeg -y -f s16le -ar "+sourceHZ+" -ac 1 -i "+sourcePath+" -f wav -ar "+targetHZ+" -b:a 8 -ac 1 "+targetPath;  
  10.         }  
  11.         System.out.println("格式转换:"+command);  
  12.         ShellExec.execShell(command);  
  13.     }  
  14.       
  15.     public static void pcmToSilk(String pcmPath,String silkPath) throws InterruptedException{  
  16.         //首先 pcm转换成8000的wav,然后wav转成silk  
  17. //      ShellExec.convertAudio(pcmPath, 16000, pcmPath+".wav", 16000);  
  18. //      Thread.sleep(1000);  
  19. //      ShellExec.convertAudio(pcmPath+".wav", 16000, silkPath, 8000);  
  20.           
  21.   
  22.         ShellExec.convertAudio(pcmPath, 16000, silkPath, 8000);  
  23.     }  
  24.       
  25.     public static void pcmToWav(String pcmPath,String wavPath){  
  26.         Properties props=System.getProperties(); //获得系统属性集      
  27.         String osName = props.getProperty("os.name"); //操作系统名称  
  28.         String command = null;  
  29.         if(osName.contains("Windows")){  
  30.             command = "C:\\ffmpeg.exe -f s16le -ar 16000 -i "+pcmPath+" -f wav -ar 16000 -b:a 8 -ac 1 "+wavPath;              
  31.         }else{  
  32.             command = "/usr/local/ffmpeg/bin/ffmpeg -f s16le -ar 16000 -i "+pcmPath+" -f wav -ar 16000 -b:a 16 -ac 1 "+wavPath;  
  33.         }  
  34.         System.out.println("格式转换:"+command);  
  35.         ShellExec.execShell(command);  
  36.     }  
  37.       
  38.     public static void silkToWav(String silkPath,String wavPath){  
  39.         Properties props=System.getProperties(); //获得系统属性集      
  40.         String osName = props.getProperty("os.name"); //操作系统名称  
  41.         String command = null;  
  42.         if(osName.contains("Windows")){  
  43. //          ffmpeg -y -f s16le -ar 24000 -ac 1 -i "$1.pcm" -f wav -ar 16000 -b:a 16 -ac 1 "${1%.*}.$2"  
  44.             command = "C:\\ffmpeg.exe -y -f s16le -ar 8000 -ac 1 -i "+silkPath+" -f wav -ar 16000 -b:a 16 -ac 1 "+wavPath;            
  45.         }else{  
  46.             command = "/usr/local/ffmpeg/bin/ffmpeg -y -f s16le -ar 8000 -ac 1 -i "+silkPath+" -f wav -ar 16000 -b:a 16 -ac 1 "+wavPath;  
  47.         }  
  48.         System.out.println("格式转换:"+command);  
  49.         ShellExec.execShell(command);  
  50.       
  51.     }  





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。