提交 2830ee85 作者: 王苏进

feat: 语音识别相关

上级 49603dc4
...@@ -53,6 +53,7 @@ class AivoicePlugin: FlutterPlugin, MethodCallHandler, EventChannel.StreamHandle ...@@ -53,6 +53,7 @@ class AivoicePlugin: FlutterPlugin, MethodCallHandler, EventChannel.StreamHandle
asrConfig = call.arguments as Map<String, String>? asrConfig = call.arguments as Map<String, String>?
// 现有的实现 // 现有的实现
asrCenter.initEngineBtnClicked() asrCenter.initEngineBtnClicked()
asrCenter.startEngineBtnClicked()
} }
"stopEngine" -> { "stopEngine" -> {
// 现有的实现 // 现有的实现
...@@ -63,12 +64,16 @@ class AivoicePlugin: FlutterPlugin, MethodCallHandler, EventChannel.StreamHandle ...@@ -63,12 +64,16 @@ class AivoicePlugin: FlutterPlugin, MethodCallHandler, EventChannel.StreamHandle
asrCenter.uninitEngineBtnClicked() asrCenter.uninitEngineBtnClicked()
} }
"startOrStopEngine" -> { "startOrStopEngine" -> {
// 现有的实现 if(call.arguments == true) {
asrCenter.startEngineBtnClicked() asrCenter.startEngineBtnClicked()
} else {
asrCenter.stopEngineBtnClicked()
}
} }
"prepareEnvironment" -> { "prepareEnvironment" -> {
val re = SpeechEngineGenerator.PrepareEnvironment(context, context as Application?) val re = SpeechEngineGenerator.PrepareEnvironment(context, context as Application?)
println("prepare:===>$re")
} }
"ttsStartEngineBtnClick" -> { "ttsStartEngineBtnClick" -> {
println("来自安卓") println("来自安卓")
...@@ -106,6 +111,7 @@ class AivoicePlugin: FlutterPlugin, MethodCallHandler, EventChannel.StreamHandle ...@@ -106,6 +111,7 @@ class AivoicePlugin: FlutterPlugin, MethodCallHandler, EventChannel.StreamHandle
} }
"destoryAsrVoice" -> { "destoryAsrVoice" -> {
// 空实现 // 空实现
asrCenter.destroy();
result.success(null) result.success(null)
} }
else -> { else -> {
...@@ -128,8 +134,9 @@ class AivoicePlugin: FlutterPlugin, MethodCallHandler, EventChannel.StreamHandle ...@@ -128,8 +134,9 @@ class AivoicePlugin: FlutterPlugin, MethodCallHandler, EventChannel.StreamHandle
this.events = null this.events = null
} }
fun sendMessageToFlutter(message: Map<*, *>?) { private fun sendMessageToFlutter(message: Map<*, *>?) {
if (events != null) { if (events != null) {
context.run { }
events?.success(message) events?.success(message)
} }
} }
......
...@@ -10,6 +10,7 @@ import android.content.pm.PackageManager; ...@@ -10,6 +10,7 @@ import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.util.Log; import android.util.Log;
//import androidx.lifecycle.LifecycleObserver; //import androidx.lifecycle.LifecycleObserver;
//import androidx.lifecycle.ProcessLifecycleOwner; //import androidx.lifecycle.ProcessLifecycleOwner;
...@@ -122,7 +123,7 @@ public class AsrCenter implements SpeechEngine.SpeechListener { ...@@ -122,7 +123,7 @@ public class AsrCenter implements SpeechEngine.SpeechListener {
} }
public void onDestroy() { public void destroy() {
Log.i(SpeechDemoDefines.TAG, "Asr onDestroy"); Log.i(SpeechDemoDefines.TAG, "Asr onDestroy");
uninitEngine(); uninitEngine();
...@@ -324,6 +325,7 @@ public class AsrCenter implements SpeechEngine.SpeechListener { ...@@ -324,6 +325,7 @@ public class AsrCenter implements SpeechEngine.SpeechListener {
public void startEngineBtnClicked() { public void startEngineBtnClicked() {
Log.i(SpeechDemoDefines.TAG, "配置启动参数."); Log.i(SpeechDemoDefines.TAG, "配置启动参数.");
configStartAsrParams(); configStartAsrParams();
//【可选配置】是否启用云端自动判停,仅一句话识别场景生效 //【可选配置】是否启用云端自动判停,仅一句话识别场景生效
Log.i(SpeechDemoDefines.TAG, "开启 ASR 云端自动判停"); Log.i(SpeechDemoDefines.TAG, "开启 ASR 云端自动判停");
...@@ -488,6 +490,9 @@ public class AsrCenter implements SpeechEngine.SpeechListener { ...@@ -488,6 +490,9 @@ public class AsrCenter implements SpeechEngine.SpeechListener {
mFinishTalkingTimestamp = 0; mFinishTalkingTimestamp = 0;
} }
final long response_delay = delay; final long response_delay = delay;
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
try { try {
// 从回调的 json 数据中解析 ASR 结果 // 从回调的 json 数据中解析 ASR 结果
JSONObject reader = new JSONObject(data); JSONObject reader = new JSONObject(data);
...@@ -511,6 +516,11 @@ public class AsrCenter implements SpeechEngine.SpeechListener { ...@@ -511,6 +516,11 @@ public class AsrCenter implements SpeechEngine.SpeechListener {
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
}
});
} }
public void speechError(final String data) { public void speechError(final String data) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论