1、文件上传,使用springmvc一直不想,后来看到别人有一样的情况改成了serverlet就可以了
2、因为要进行语音识别成文字,上传的语音文件是silk格式,需要用到讯飞的语音识别所以必须转成wav,用到了kn007大神的这个工具https://github.com/kn007/silk-v3-decoder才搞定过程比较坎坷
3、还想把返回结果转换成语音文件给小程序进行播放,结果...........silk是有了,但是一直播放不了,因为小程序的silk似乎需要特定的参数格式才行,最后转了个war给前端,让它播放
4、期间使用ffmpeg进行各种格式转换,ffmpeg的参数设置也挺恶心的,下面留一个可用的例子
-
public static void convertAudio(String sourcePath,int sourceHZ,String targetPath,int targetHZ){
-
Properties props=System.getProperties(); //获得系统属性集
-
String osName = props.getProperty("os.name"); //操作系统名称
-
String command = null;
-
if(osName.contains("Windows")){
-
// ffmpeg -y -f s16le -ar 24000 -ac 1 -i "$1.pcm" -f wav -ar 16000 -b:a 16 -ac 1 "${1%.*}.$2"
-
command = "C:\\ffmpeg.exe -y -f s16le -ar "+sourceHZ+" -i "+sourcePath+" -f wav -ar "+targetHZ+" -b:a 8 -ac 1 "+targetPath;
-
}else{
-
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;
-
}
-
System.out.println("格式转换:"+command);
-
ShellExec.execShell(command);
-
}
-
-
public static void pcmToSilk(String pcmPath,String silkPath) throws InterruptedException{
-
//首先 pcm转换成8000的wav,然后wav转成silk
-
// ShellExec.convertAudio(pcmPath, 16000, pcmPath+".wav", 16000);
-
// Thread.sleep(1000);
-
// ShellExec.convertAudio(pcmPath+".wav", 16000, silkPath, 8000);
-
-
-
ShellExec.convertAudio(pcmPath, 16000, silkPath, 8000);
-
}
-
-
public static void pcmToWav(String pcmPath,String wavPath){
-
Properties props=System.getProperties(); //获得系统属性集
-
String osName = props.getProperty("os.name"); //操作系统名称
-
String command = null;
-
if(osName.contains("Windows")){
-
command = "C:\\ffmpeg.exe -f s16le -ar 16000 -i "+pcmPath+" -f wav -ar 16000 -b:a 8 -ac 1 "+wavPath;
-
}else{
-
command = "/usr/local/ffmpeg/bin/ffmpeg -f s16le -ar 16000 -i "+pcmPath+" -f wav -ar 16000 -b:a 16 -ac 1 "+wavPath;
-
}
-
System.out.println("格式转换:"+command);
-
ShellExec.execShell(command);
-
}
-
-
public static void silkToWav(String silkPath,String wavPath){
-
Properties props=System.getProperties(); //获得系统属性集
-
String osName = props.getProperty("os.name"); //操作系统名称
-
String command = null;
-
if(osName.contains("Windows")){
-
// ffmpeg -y -f s16le -ar 24000 -ac 1 -i "$1.pcm" -f wav -ar 16000 -b:a 16 -ac 1 "${1%.*}.$2"
-
command = "C:\\ffmpeg.exe -y -f s16le -ar 8000 -ac 1 -i "+silkPath+" -f wav -ar 16000 -b:a 16 -ac 1 "+wavPath;
-
}else{
-
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;
-
}
-
System.out.println("格式转换:"+command);
-
ShellExec.execShell(command);
-
-
}