科大讯飞的语音听写包,读入文件都省去了,内部直接调用了系统的录音功能,太强大了 都是开发包的功劳啊~~,感觉自己什么都没有做,惭愧............ 工具类 package iflytekTest; import com.iflytek.cloud.speech.*; import java.io.IOException; public class SpeechLisAndWrite { private static StringBuffer mResult = new StringBuffer(); public static String res = ""; public static void Recognize() { if (SpeechRecognizer.getRecognizer() == null) SpeechRecognizer.createRecognizer(); SpeechRecognizer mIat = SpeechRecognizer.getRecognizer(); // 设置听写参数 mIat.setParameter(SpeechConstant.DOMAIN, "iat"); mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn"); mIat.setParameter(SpeechConstant.ACCENT, "mandarin"); mIat.setParameter( SpeechConstant.RESULT_TYPE, "plain" ); // 开始监听 mIat.startListening(mListenser); // 需要等待语音识别结果 try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } // 调用命令打开百度 if(res.equals("百度。")) { try { // rundll32 url.dll,FileProtocolHandler 表示打开默认浏览器 // 可换成 cmd /c start iexplore 表示打开IE String url = "http://www.baidu.com"; Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); } catch (IOException e) { e.printStackTrace(); } } } private static RecognizerListener mListenser = new RecognizerListener() { public void onVolumeChanged(int i) { } public void onBeginOfSpeech() { System.out.println("开始听写"); } public void onEndOfSpeech() { System.out.println("结束听写"); } public void onResult(RecognizerResult recognizerResult, boolean b) { mResult.append(recognizerResult.getResultString()); if(b) { res += mResult.toString(); System.out.println(res); } } public void onError(SpeechError speechError) { } public void onEvent(int i, int i1, int i2, String s) { } }; } 启动类 package iflytekTest; import com.iflytek.cloud.speech.SpeechUtility; public class SpeechLisAndWriteTest { private static final String APPID = "XXXXXX"; // 这里改成自己的 public static void main(String[] args) { SpeechUtility.createUtility("appid=" + APPID); SpeechLisAndWrite.Recognize(); } }
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务