午夜91福利视频,午夜成人在线观看,午夜在线视频免费观看,午夜福利短视频,精品午夜成人免费视频APP

小程序模板網

微信小程序 java服務端記

發布時間(jian):2018-04-21 10:18 所屬欄目:小程序開發教程

1、文(wen)件上(shang)傳,使(shi)用springmvc一(yi)(yi)直不想,后來看到別人(ren)有(you)一(yi)(yi)樣的情況改(gai)成了(le)serverlet就可以了(le)

2、因為要(yao)進行語(yu)音識(shi)別(bie)成(cheng)文(wen)字,上(shang)傳的(de)語(yu)音文(wen)件是(shi)silk格式,需要(yao)用到(dao)訊(xun)飛的(de)語(yu)音識(shi)別(bie)所以必須轉成(cheng)wav,用到(dao)了kn007大神的(de)這個工(gong)具//github.com/kn007/silk-v3-decoder才搞定過(guo)程比(bi)較(jiao)坎坷

3、還想把返回(hui)結果轉換成語音文件給(gei)小程序進(jin)行播(bo)(bo)放(fang),結果...........silk是(shi)有了(le),但是(shi)一直播(bo)(bo)放(fang)不了(le),因(yin)為(wei)小程序的silk似乎需要(yao)特(te)定的參數格式才(cai)行,最后轉了(le)個(ge)war給(gei)前(qian)端(duan),讓它播(bo)(bo)放(fang)

4、期間使用ffmpeg進行各種格式轉換,ffmpeg的參(can)數(shu)設置也挺(ting)惡心的,下面留一個可用的例子

 

[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.     }  


易優(you)小程序(企業版)+靈活(huo)api+前后(hou)代(dai)碼開源(yuan) 碼(ma)云倉(cang)庫:
本文地址://www.jinyoudianli.com/wxmini/doc/course/23877.html 復制鏈接 如(ru)需定制請(qing)聯系易優客服咨詢:

工作日 8:30-12:00 14:30-18:00
周六及部分節假日提供值(zhi)班(ban)服務

易(yi)小優
轉人工 ×