Xunfei Voice+


示例代码

第三方程序在使用讯飞语音服务前要在开发程序中检测是否已经安装了讯飞语音服务,并且选择讯飞语音服务为默认语音服务,然后就可以调用相应的语言服务。 示例代码:
// 创建SpeechRecognizer对象
SpeechRecognizer recognizer = new SpeechRecognizer(this, initListener);

// 转写示例
recognizer.setParam( ENGINE_TYPE, "clound");
recognizer.setParam( VAD_BOS, "4000");
recognizer.setParam( PARAMS, "asr_ptt=0");
recognizer.setParam( LANGUAGE, "zh_cn");
recognizer.setParam( LANG_LOCAL, "cantonese");
recognizer.setParam( DOMAIN, "sms");
recognizer.startListening( recognizerListener);



// 构建ABNF语法文件示例
recognizer.buildGrammar( "abnf", "#abnf....", grammarListener);



// 构建词典示例
recognizer.setParam( ENGINE_TYPE, "local");
recognizer.updateLexicon( "contact", "张三,李四.........", lexiconListener);



// 识别示例
recognizer.setParam( ENGINE_TYPE, "local");
recognizer.setParam( VAD_BOS, "4000");
recognizer.setParam( GRAMMAR_ID, "abnfid");
recognizer.startListening( recognizerListener);

};