private string Recognition(IList <byte[]> data) { string result = ""; int ret = 0; for (int i = 0; i < data.Count; i++) { ret = USCDLL.usc_feed_buffer(handle, data[i], data[i].Length); if ((int)StatusUsc.USC_RECOGNIZER_PARTIAL_RESULT == ret || (int)StatusUsc.USC_RECOGNIZER_SPEAK_END == ret) { // TODO Log(String.Format("中间结果:{0}", USCDLL.usc_get_result(handle))); } else if (0 > ret) { break; } Thread.Sleep(20); } // 停止语音输入 ret = USCDLL.usc_stop_recognizer(handle); if (ret == 0) { // 获取剩余识别结果 string leftResult = USCDLL.usc_get_result(handle); result = leftResult; } byte[] bl = Encoding.Default.GetBytes(result); result = Encoding.UTF8.GetString(bl); return(result); }
private void Initialize() { int ret = 0; ret = USCDLL.usc_create_service(out handle); if (ret != Convert.ToInt32(StatusUsc.USC_ASR_OK)) { Log(String.Format("create_service -> error: {0}", ret)); } ret = USCDLL.usc_login_service(handle); if (ret != Convert.ToInt32(StatusUsc.USC_ASR_OK)) { Log(String.Format("login_service -> error: {0}", ret)); } // 设置识别AppKey secret ret = USCDLL.usc_set_option(handle, ParamIdUsc.USC_OPT_ASR_APP_KEY, appKey); if (0 != ret) { Log(String.Format("set_option[1] -> ret: {0}", ret)); } ret = USCDLL.usc_set_option(handle, ParamIdUsc.USC_OPT_USER_SECRET, appSecret); if (0 != ret) { Log(String.Format("set_option[2] -> ret: {0}", ret)); } }
public string Recognition(byte[] data) { int ret = 0; ret = USCDLL.usc_set_option(handle, ParamIdUsc.USC_OPT_INPUT_AUDIO_FORMAT, ""); if (0 != ret) { Log(String.Format("set_option[3] -> ret: {0}", ret)); } ret = USCDLL.usc_set_option(handle, ParamIdUsc.USC_OPT_RECOGNITION_FIELD, ""); if (0 != ret) { Log(String.Format("set_option[4] -> ret: {0}", ret)); } ret = USCDLL.usc_start_recognizer(handle); if ((int)StatusUsc.USC_ASR_OK != ret) { Log(String.Format("start_recognizer -> ret: {0}", ret)); } return(Recognition(GroupData(data))); }