|
|
|
@ -11,6 +11,7 @@ import io.flutter.plugin.common.EventChannel |
|
|
|
import io.flutter.plugin.common.MethodChannel |
|
|
|
import io.flutter.plugin.common.MethodChannel.Result |
|
|
|
import org.json.JSONObject |
|
|
|
import java.io.File |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -27,13 +28,10 @@ class VolcSpeechBridge( |
|
|
|
private const val TAG = "VolcSpeechBridge" |
|
|
|
private const val CHANNEL_NAME = "com.example.deep_voice/speech_recognition" |
|
|
|
private const val EVENT_CHANNEL_NAME = "com.example.deep_voice/speech_recognition_events" |
|
|
|
|
|
|
|
// 定义指令常量 |
|
|
|
private const val DIRECTIVE_START_RECOGNITION = 1 |
|
|
|
private const val DIRECTIVE_STOP_RECOGNITION = 2 |
|
|
|
} |
|
|
|
|
|
|
|
private var engine: SpeechEngine? = null |
|
|
|
private var engineHandler: Long = 0 |
|
|
|
private var methodResult: Result? = null |
|
|
|
private var eventSink: EventChannel.EventSink? = null |
|
|
|
private var isInitialized = false |
|
|
|
@ -46,7 +44,8 @@ class VolcSpeechBridge( |
|
|
|
"initialize" -> { |
|
|
|
val appKey = call.argument<String>("appKey") ?: "" |
|
|
|
val accessKey = call.argument<String>("accessKey") ?: "" |
|
|
|
initialize(appKey, accessKey, result) |
|
|
|
val cluster = call.argument<String>("cluster") ?: "volcano_asr" |
|
|
|
initialize(appKey, accessKey, cluster, result) |
|
|
|
} |
|
|
|
"startRecognition" -> { |
|
|
|
startRecognition(result) |
|
|
|
@ -57,6 +56,9 @@ class VolcSpeechBridge( |
|
|
|
"isInitialized" -> { |
|
|
|
result.success(isInitialized) |
|
|
|
} |
|
|
|
"checkEngineCapabilities" -> { |
|
|
|
checkEngineCapabilities(result) |
|
|
|
} |
|
|
|
else -> { |
|
|
|
result.notImplemented() |
|
|
|
} |
|
|
|
@ -78,32 +80,75 @@ class VolcSpeechBridge( |
|
|
|
/** |
|
|
|
* 初始化火山语音识别引擎 |
|
|
|
*/ |
|
|
|
fun initialize(appKey: String, accessKey: String, result: Result) { |
|
|
|
fun initialize(appKey: String, accessKey: String, cluster: String, result: Result) { |
|
|
|
methodResult = result |
|
|
|
try { |
|
|
|
Log.i(TAG, "Initializing Volcengine Speech Engine") |
|
|
|
|
|
|
|
// 前置操作:环境依赖 |
|
|
|
SpeechEngineGenerator.PrepareEnvironment(activity.applicationContext, activity.application) |
|
|
|
|
|
|
|
// 创建引擎实例 |
|
|
|
engine = SpeechEngineGenerator.getInstance() |
|
|
|
engine?.createEngine() |
|
|
|
engineHandler = engine?.createEngine() ?: 0 |
|
|
|
|
|
|
|
// 设置监听器 |
|
|
|
engine?.setListener(this) |
|
|
|
if (engineHandler == 0L) { |
|
|
|
Log.e(TAG, "Failed to create engine instance") |
|
|
|
result.error("CREATE_ERROR", "Failed to create engine instance", null) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 设置引擎类型 |
|
|
|
engine?.setOptionString(engineHandler, SpeechEngineDefines.PARAMS_KEY_ENGINE_NAME_STRING, SpeechEngineDefines.ASR_ENGINE) |
|
|
|
|
|
|
|
// 设置用户ID(必填) |
|
|
|
engine?.setOptionString(engineHandler, SpeechEngineDefines.PARAMS_KEY_UID_STRING, "deep_voice_user") |
|
|
|
|
|
|
|
// 设置设备ID(选填) |
|
|
|
engine?.setOptionString(engineHandler, SpeechEngineDefines.PARAMS_KEY_DEVICE_ID_STRING, "deep_voice_device") |
|
|
|
|
|
|
|
// 设置日志级别 |
|
|
|
engine?.setOptionString(engineHandler, SpeechEngineDefines.PARAMS_KEY_LOG_LEVEL_STRING, SpeechEngineDefines.LOG_LEVEL_WARN) |
|
|
|
|
|
|
|
// 禁用日志文件,避免权限问题 |
|
|
|
engine?.setOptionBoolean(engineHandler, "enable_log_file", false) |
|
|
|
|
|
|
|
// 设置应用 ID 和访问密钥 |
|
|
|
engine?.setOptionString("app_id", appKey) |
|
|
|
engine?.setOptionString("access_key", accessKey) |
|
|
|
engine?.setOptionString(engineHandler, SpeechEngineDefines.PARAMS_KEY_APP_ID_STRING, appKey) |
|
|
|
engine?.setOptionString(engineHandler, SpeechEngineDefines.PARAMS_KEY_APP_TOKEN_STRING, "Bearer;$accessKey") |
|
|
|
|
|
|
|
// 设置语音识别参数 |
|
|
|
engine?.setOptionBoolean("enable_punctuation", true) // 启用标点符号 |
|
|
|
engine?.setOptionBoolean("enable_intermediate_result", true) // 启用中间结果 |
|
|
|
engine?.setOptionBoolean("enable_vad", true) // 启用语音活动检测 |
|
|
|
// 设置网络参数 |
|
|
|
engine?.setOptionString(engineHandler, SpeechEngineDefines.PARAMS_KEY_ASR_ADDRESS_STRING, "wss://openspeech.bytedance.com") |
|
|
|
engine?.setOptionString(engineHandler, SpeechEngineDefines.PARAMS_KEY_ASR_URI_STRING, "/api/v2/asr") |
|
|
|
engine?.setOptionString(engineHandler, SpeechEngineDefines.PARAMS_KEY_ASR_CLUSTER_STRING, cluster) |
|
|
|
|
|
|
|
// 设置语言(普通话) |
|
|
|
engine?.setOptionString("language", "zh") |
|
|
|
// 设置音频来源为内置录音机 |
|
|
|
engine?.setOptionString(engineHandler, SpeechEngineDefines.PARAMS_KEY_RECORDER_TYPE_STRING, SpeechEngineDefines.RECORDER_TYPE_RECORDER) |
|
|
|
|
|
|
|
// 启用音量获取 |
|
|
|
engine?.setOptionBoolean(engineHandler, SpeechEngineDefines.PARAMS_KEY_ENABLE_GET_VOLUME_BOOL, true) |
|
|
|
|
|
|
|
// 设置最大录音时长(60秒) |
|
|
|
engine?.setOptionInt(engineHandler, SpeechEngineDefines.PARAMS_KEY_VAD_MAX_SPEECH_DURATION_INT, 60000) |
|
|
|
|
|
|
|
// 控制识别效果 |
|
|
|
engine?.setOptionBoolean(engineHandler, SpeechEngineDefines.PARAMS_KEY_ASR_SHOW_NLU_PUNC_BOOL, true) // 返回标点符号 |
|
|
|
engine?.setOptionBoolean(engineHandler, SpeechEngineDefines.PARAMS_KEY_ASR_AUTO_STOP_BOOL, true) // 开启自动判停 |
|
|
|
|
|
|
|
// 设置结果返回形式为增量返回 |
|
|
|
engine?.setOptionString(engineHandler, SpeechEngineDefines.PARAMS_KEY_ASR_RESULT_TYPE_STRING, SpeechEngineDefines.ASR_RESULT_TYPE_SINGLE) |
|
|
|
|
|
|
|
// 设置上下文 |
|
|
|
engine?.setContext(activity.applicationContext) |
|
|
|
|
|
|
|
// 设置监听器 |
|
|
|
engine?.setListener(this) |
|
|
|
|
|
|
|
// 初始化引擎 |
|
|
|
val ret = engine?.initEngine() |
|
|
|
Log.i(TAG, "Calling initEngine()") |
|
|
|
val ret = engine?.initEngine(engineHandler) |
|
|
|
Log.i(TAG, "initEngine() returned: $ret") |
|
|
|
|
|
|
|
if (ret == SpeechEngineDefines.ERR_NO_ERROR) { |
|
|
|
isInitialized = true |
|
|
|
Log.i(TAG, "Volcengine Speech Engine initialized successfully") |
|
|
|
@ -127,17 +172,24 @@ class VolcSpeechBridge( |
|
|
|
fun startRecognition(result: Result) { |
|
|
|
try { |
|
|
|
if (!isInitialized) { |
|
|
|
Log.e(TAG, "Cannot start recognition: Engine not initialized") |
|
|
|
result.error("NOT_INITIALIZED", "Speech engine is not initialized", null) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
Log.i(TAG, "Starting speech recognition") |
|
|
|
val ret = engine?.sendDirective(DIRECTIVE_START_RECOGNITION, "") |
|
|
|
|
|
|
|
// 先调用同步停止,避免SDK内部异步线程带来的问题 |
|
|
|
engine?.sendDirective(engineHandler, SpeechEngineDefines.DIRECTIVE_SYNC_STOP_ENGINE, "") |
|
|
|
|
|
|
|
// 启动引擎 |
|
|
|
val ret = engine?.sendDirective(engineHandler, SpeechEngineDefines.DIRECTIVE_START_ENGINE, "") |
|
|
|
Log.d(TAG, "Start engine directive returned: $ret") |
|
|
|
|
|
|
|
if (ret == SpeechEngineDefines.ERR_NO_ERROR) { |
|
|
|
Log.i(TAG, "Successfully started recognition") |
|
|
|
result.success("Recognition started") |
|
|
|
// 发送状态更新到 Flutter |
|
|
|
sendEvent("status", "listening") |
|
|
|
// 状态会通过回调更新 |
|
|
|
} else { |
|
|
|
Log.e(TAG, "Start recognition failed with error code: $ret") |
|
|
|
result.error("START_ERROR", "Start recognition failed with error code: $ret", null) |
|
|
|
@ -154,20 +206,28 @@ class VolcSpeechBridge( |
|
|
|
fun stopRecognition(result: Result) { |
|
|
|
try { |
|
|
|
if (!isInitialized) { |
|
|
|
Log.e(TAG, "Cannot stop recognition: Engine not initialized") |
|
|
|
result.error("NOT_INITIALIZED", "Speech engine is not initialized", null) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
Log.i(TAG, "Stopping speech recognition") |
|
|
|
val ret = engine?.sendDirective(DIRECTIVE_STOP_RECOGNITION, "") |
|
|
|
|
|
|
|
if (ret == SpeechEngineDefines.ERR_NO_ERROR) { |
|
|
|
// 先发送音频输入完成指令 |
|
|
|
val finishRet = engine?.sendDirective(engineHandler, SpeechEngineDefines.DIRECTIVE_FINISH_TALKING, "") |
|
|
|
Log.d(TAG, "Finish talking directive returned: $finishRet") |
|
|
|
|
|
|
|
// 然后停止引擎 |
|
|
|
val stopRet = engine?.sendDirective(engineHandler, SpeechEngineDefines.DIRECTIVE_STOP_ENGINE, "") |
|
|
|
Log.d(TAG, "Stop engine directive returned: $stopRet") |
|
|
|
|
|
|
|
if (finishRet == SpeechEngineDefines.ERR_NO_ERROR || stopRet == SpeechEngineDefines.ERR_NO_ERROR) { |
|
|
|
Log.i(TAG, "Successfully stopped recognition") |
|
|
|
result.success("Recognition stopped") |
|
|
|
// 发送状态更新到 Flutter |
|
|
|
sendEvent("status", "idle") |
|
|
|
// 状态会通过回调更新 |
|
|
|
} else { |
|
|
|
Log.e(TAG, "Stop recognition failed with error code: $ret") |
|
|
|
result.error("STOP_ERROR", "Stop recognition failed with error code: $ret", null) |
|
|
|
Log.e(TAG, "Stop recognition failed with error codes: finish=$finishRet, stop=$stopRet") |
|
|
|
result.error("STOP_ERROR", "Stop recognition failed", null) |
|
|
|
} |
|
|
|
} catch (e: Exception) { |
|
|
|
Log.e(TAG, "Stop recognition failed", e) |
|
|
|
@ -180,7 +240,10 @@ class VolcSpeechBridge( |
|
|
|
*/ |
|
|
|
fun dispose() { |
|
|
|
try { |
|
|
|
engine?.destroyEngine() |
|
|
|
if (engineHandler != 0L) { |
|
|
|
engine?.destroyEngine(engineHandler) |
|
|
|
engineHandler = 0 |
|
|
|
} |
|
|
|
engine = null |
|
|
|
isInitialized = false |
|
|
|
Log.i(TAG, "Volcengine Speech Engine released") |
|
|
|
@ -216,36 +279,60 @@ class VolcSpeechBridge( |
|
|
|
*/ |
|
|
|
override fun onSpeechMessage(messageType: Int, messageData: ByteArray?, messageLength: Int) { |
|
|
|
try { |
|
|
|
Log.d(TAG, "Received speech message type: $messageType, length: $messageLength") |
|
|
|
|
|
|
|
if (messageData != null) { |
|
|
|
val dataString = try { |
|
|
|
String(messageData, 0, messageLength) |
|
|
|
} catch (e: Exception) { |
|
|
|
"Unable to convert to string: ${e.message}" |
|
|
|
} |
|
|
|
Log.d(TAG, "Message data: $dataString") |
|
|
|
} |
|
|
|
|
|
|
|
when (messageType) { |
|
|
|
// 初始化完成消息 |
|
|
|
1 -> { |
|
|
|
Log.i(TAG, "Engine initialized successfully") |
|
|
|
isInitialized = true |
|
|
|
|
|
|
|
// 通知 Flutter 初始化完成 |
|
|
|
methodResult?.success("Engine initialized") |
|
|
|
methodResult = null |
|
|
|
|
|
|
|
// 发送状态更新到 Flutter |
|
|
|
sendEvent("status", "initialized") |
|
|
|
// 引擎启动成功 |
|
|
|
SpeechEngineDefines.MESSAGE_TYPE_ENGINE_START -> { |
|
|
|
Log.i(TAG, "Engine started successfully") |
|
|
|
sendEvent("status", "listening") |
|
|
|
} |
|
|
|
|
|
|
|
// 错误消息 |
|
|
|
2 -> { |
|
|
|
val errorCode = messageData?.let { String(it, 0, messageLength).toIntOrNull() } ?: -1 |
|
|
|
Log.e(TAG, "Engine error: $errorCode") |
|
|
|
|
|
|
|
// 通知 Flutter 识别出错 |
|
|
|
val errorData = JSONObject().apply { |
|
|
|
put("code", errorCode) |
|
|
|
put("message", "Error code: $errorCode") |
|
|
|
// 引擎关闭 |
|
|
|
SpeechEngineDefines.MESSAGE_TYPE_ENGINE_STOP -> { |
|
|
|
Log.i(TAG, "Engine stopped") |
|
|
|
sendEvent("status", "idle") |
|
|
|
} |
|
|
|
|
|
|
|
// 错误信息 |
|
|
|
SpeechEngineDefines.MESSAGE_TYPE_ENGINE_ERROR -> { |
|
|
|
messageData?.let { |
|
|
|
val errorJson = String(it, 0, messageLength) |
|
|
|
Log.e(TAG, "Engine error: $errorJson") |
|
|
|
|
|
|
|
try { |
|
|
|
val jsonObject = JSONObject(errorJson) |
|
|
|
val errorCode = jsonObject.optInt("err_code", -1) |
|
|
|
val errorMsg = jsonObject.optString("err_msg", "Unknown error") |
|
|
|
val reqId = jsonObject.optString("req_id", "") |
|
|
|
|
|
|
|
Log.e(TAG, "Error details: code=$errorCode, message=$errorMsg, reqId=$reqId") |
|
|
|
|
|
|
|
// 通知 Flutter 识别出错 |
|
|
|
val errorData = JSONObject() |
|
|
|
errorData.put("code", errorCode) |
|
|
|
errorData.put("message", errorMsg) |
|
|
|
errorData.put("reqId", reqId) |
|
|
|
|
|
|
|
sendEvent("error", errorData.toString()) |
|
|
|
} catch (e: Exception) { |
|
|
|
Log.e(TAG, "Error parsing error JSON", e) |
|
|
|
sendEvent("error", "Error code: Unknown") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sendEvent("error", errorData.toString()) |
|
|
|
} |
|
|
|
|
|
|
|
// VAD 状态变化消息 |
|
|
|
3 -> { |
|
|
|
SpeechEngineDefines.MESSAGE_TYPE_VAD_STATE -> { |
|
|
|
val state = messageData?.let { String(it, 0, messageLength).toIntOrNull() } ?: -1 |
|
|
|
Log.i(TAG, "VAD state changed: $state") |
|
|
|
|
|
|
|
@ -258,36 +345,149 @@ class VolcSpeechBridge( |
|
|
|
sendEvent("vad", vadState) |
|
|
|
} |
|
|
|
|
|
|
|
// 识别结果消息 |
|
|
|
4 -> { |
|
|
|
// 中间识别结果 |
|
|
|
SpeechEngineDefines.MESSAGE_TYPE_PARTIAL_RESULT -> { |
|
|
|
messageData?.let { |
|
|
|
val resultJson = String(it, 0, messageLength) |
|
|
|
Log.d(TAG, "Partial recognition result: $resultJson") |
|
|
|
|
|
|
|
try { |
|
|
|
val jsonObject = JSONObject(resultJson) |
|
|
|
val text = jsonObject.optString("text", "") |
|
|
|
val isFinal = jsonObject.optBoolean("is_final", false) |
|
|
|
|
|
|
|
Log.i(TAG, "Recognition result: $text, isFinal: $isFinal") |
|
|
|
|
|
|
|
// 发送识别结果到 Flutter |
|
|
|
val resultData = JSONObject().apply { |
|
|
|
put("text", text) |
|
|
|
put("isFinal", isFinal) |
|
|
|
if (jsonObject.has("result")) { |
|
|
|
val resultArray = jsonObject.getJSONArray("result") |
|
|
|
if (resultArray.length() > 0) { |
|
|
|
val result = resultArray.getJSONObject(0) |
|
|
|
val text = result.optString("text", "") |
|
|
|
|
|
|
|
if (text.isNotEmpty()) { |
|
|
|
Log.i(TAG, "Partial recognition text: $text") |
|
|
|
|
|
|
|
// 发送识别结果到 Flutter |
|
|
|
val resultData = JSONObject() |
|
|
|
resultData.put("text", text) |
|
|
|
resultData.put("isFinal", false) |
|
|
|
|
|
|
|
sendEvent("result", resultData.toString()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e: Exception) { |
|
|
|
Log.e(TAG, "Error parsing partial result JSON", e) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 最终识别结果 |
|
|
|
SpeechEngineDefines.MESSAGE_TYPE_FINAL_RESULT -> { |
|
|
|
messageData?.let { |
|
|
|
val resultJson = String(it, 0, messageLength) |
|
|
|
Log.d(TAG, "Final recognition result: $resultJson") |
|
|
|
|
|
|
|
try { |
|
|
|
val jsonObject = JSONObject(resultJson) |
|
|
|
|
|
|
|
sendEvent("result", resultData.toString()) |
|
|
|
if (jsonObject.has("result")) { |
|
|
|
val resultArray = jsonObject.getJSONArray("result") |
|
|
|
if (resultArray.length() > 0) { |
|
|
|
val result = resultArray.getJSONObject(0) |
|
|
|
val text = result.optString("text", "") |
|
|
|
|
|
|
|
if (text.isNotEmpty()) { |
|
|
|
Log.i(TAG, "Final recognition text: $text") |
|
|
|
|
|
|
|
// 发送识别结果到 Flutter |
|
|
|
val resultData = JSONObject() |
|
|
|
resultData.put("text", text) |
|
|
|
resultData.put("isFinal", true) |
|
|
|
|
|
|
|
sendEvent("result", resultData.toString()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e: Exception) { |
|
|
|
Log.e(TAG, "Error parsing result JSON", e) |
|
|
|
Log.e(TAG, "Error parsing final result JSON", e) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 当前音量 |
|
|
|
SpeechEngineDefines.MESSAGE_TYPE_VOLUME -> { |
|
|
|
val volume = messageData?.let { String(it, 0, messageLength).toFloatOrNull() } ?: 0f |
|
|
|
// 将 [0-1] 的音量值转换为 [0-100] 的整数 |
|
|
|
val volumeInt = (volume * 100).toInt().coerceIn(0, 100) |
|
|
|
Log.d(TAG, "Volume level: $volume (normalized: $volumeInt)") |
|
|
|
|
|
|
|
// 发送音量变化事件到 Flutter |
|
|
|
sendEvent("volume", volumeInt) |
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
Log.d(TAG, "Received unknown message type: $messageType") |
|
|
|
// 尝试解析未知消息类型的数据 |
|
|
|
messageData?.let { |
|
|
|
try { |
|
|
|
val dataString = String(it, 0, messageLength) |
|
|
|
Log.d(TAG, "Unknown message data: $dataString") |
|
|
|
} catch (e: Exception) { |
|
|
|
Log.e(TAG, "Error parsing unknown message data", e) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e: Exception) { |
|
|
|
Log.e(TAG, "Error processing speech message", e) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 检查引擎能力和支持的指令 |
|
|
|
*/ |
|
|
|
fun checkEngineCapabilities(result: Result) { |
|
|
|
try { |
|
|
|
Log.i(TAG, "Checking engine capabilities") |
|
|
|
|
|
|
|
if (engine == null) { |
|
|
|
Log.e(TAG, "Engine is null, cannot check capabilities") |
|
|
|
result.error("ENGINE_NULL", "Engine is null", null) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 获取引擎版本信息 |
|
|
|
val version = engine?.getVersion() ?: "Unknown" |
|
|
|
Log.i(TAG, "Engine version: $version") |
|
|
|
|
|
|
|
// 创建能力信息对象 |
|
|
|
val capabilities = JSONObject() |
|
|
|
capabilities.put("version", version) |
|
|
|
|
|
|
|
// 列出支持的指令 |
|
|
|
val supportedDirectives = JSONObject() |
|
|
|
supportedDirectives.put("DIRECTIVE_START_ENGINE", SpeechEngineDefines.DIRECTIVE_START_ENGINE) |
|
|
|
supportedDirectives.put("DIRECTIVE_STOP_ENGINE", SpeechEngineDefines.DIRECTIVE_STOP_ENGINE) |
|
|
|
supportedDirectives.put("DIRECTIVE_FINISH_TALKING", SpeechEngineDefines.DIRECTIVE_FINISH_TALKING) |
|
|
|
supportedDirectives.put("DIRECTIVE_SYNC_STOP_ENGINE", SpeechEngineDefines.DIRECTIVE_SYNC_STOP_ENGINE) |
|
|
|
supportedDirectives.put("DIRECTIVE_UPDATE_ASR_HOTWORDS", SpeechEngineDefines.DIRECTIVE_UPDATE_ASR_HOTWORDS) |
|
|
|
|
|
|
|
capabilities.put("supported_directives", supportedDirectives) |
|
|
|
|
|
|
|
// 列出支持的消息类型 |
|
|
|
val supportedMessageTypes = JSONObject() |
|
|
|
supportedMessageTypes.put("MESSAGE_TYPE_ENGINE_START", SpeechEngineDefines.MESSAGE_TYPE_ENGINE_START) |
|
|
|
supportedMessageTypes.put("MESSAGE_TYPE_ENGINE_STOP", SpeechEngineDefines.MESSAGE_TYPE_ENGINE_STOP) |
|
|
|
supportedMessageTypes.put("MESSAGE_TYPE_ENGINE_ERROR", SpeechEngineDefines.MESSAGE_TYPE_ENGINE_ERROR) |
|
|
|
supportedMessageTypes.put("MESSAGE_TYPE_PARTIAL_RESULT", SpeechEngineDefines.MESSAGE_TYPE_PARTIAL_RESULT) |
|
|
|
supportedMessageTypes.put("MESSAGE_TYPE_FINAL_RESULT", SpeechEngineDefines.MESSAGE_TYPE_FINAL_RESULT) |
|
|
|
supportedMessageTypes.put("MESSAGE_TYPE_VOLUME", SpeechEngineDefines.MESSAGE_TYPE_VOLUME) |
|
|
|
supportedMessageTypes.put("MESSAGE_TYPE_VAD_STATE_CHANGED", SpeechEngineDefines.MESSAGE_TYPE_VAD_STATE) |
|
|
|
|
|
|
|
capabilities.put("supported_message_types", supportedMessageTypes) |
|
|
|
|
|
|
|
// 返回结果 |
|
|
|
result.success(capabilities.toString()) |
|
|
|
} catch (e: Exception) { |
|
|
|
Log.e(TAG, "Error checking engine capabilities", e) |
|
|
|
result.error("CHECK_ERROR", e.message, null) |
|
|
|
} |
|
|
|
} |
|
|
|
} |