这篇文章主要介绍“小程序怎么实现科大讯飞接口”,在日常操作中,相信很多人在小程序怎么实现科大讯飞接口问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”小程序怎么实现科大讯飞接口”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
下面为java的讯飞语音接口开发了,直接贴代码
package com.example.utils;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/**
* Created by songzs on 2017/12/12.
* 封装的转码工具类
*/
public class FFMPEGUtil {
public static String silk2Pcm(String inputfile,String outputfile){
Listcommend = new ArrayList();
commend.add("/usr/local/silk2pcm_tool/SILKCodec/SILK_SDK_SRC_ARM/./decoder");
commend.add(inputfile);
commend.add(outputfile);
StringBuffer test=new StringBuffer();
for(int i=0;i<commend.size();i++)< p="">
test.append(commend.get(i)+" ");
System.out.println("decoder命令:"+test+"");
exec(test);
return outputfile;
}
public static String pcm2Wav(String inputfile,String outputfile){
//ffmpeg -f s16le -ar 12k -ac 2 -i /path/to/pcm -f wav -ar 16k -ac 1 /path/to/wav
Listcommend = new ArrayList();
commend.add("ffmpeg");
commend.add("-f");
commend.add("s16le");
commend.add("-ar");
commend.add("12k");
commend.add("-ac");
commend.add("2");
commend.add("-i");
commend.add(inputfile);
commend.add("-f");
commend.add("wav");
commend.add("-ar");
commend.add("16k");
commend.add("-ac");
commend.add("1");
commend.add(outputfile);
StringBuffer test=new StringBuffer();
for(int i=0;i<commend.size();i++)< p="">
test.append(commend.get(i)+" ");
System.out.println("ffmpeg命令:"+test+"");
exec(test);
return outputfile;
}
public static String silk_remove_word(String filepath){
Listcommend = new ArrayList();
commend.add("/home/workspace/./test.sh");
commend.add(filepath);
StringBuffer test=new StringBuffer();
for(int i=0;i<commend.size();i++)< p="">
test.append(commend.get(i)+" ");
System.out.println("test命令:"+test+"");
exec(test);
return filepath;
}
private static void exec(StringBuffer test){
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(test.toString());
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ( (line = br.readLine()) != null) ;
} catch (Exception e) {
e.printStackTrace();
}
}
}
到此,关于“小程序怎么实现科大讯飞接口”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注天达云网站,小编会继续努力为大家带来更多实用的文章!