提交 c652dadb 作者: 王苏进

feat:增加参数接受

上级 ab852fdf
......@@ -26,19 +26,21 @@ class AivoicePlugin: FlutterPlugin, MethodCallHandler, EventChannel.StreamHandle
private var asrConfig : Map<String, String>? = null
private var ttsConfig : Map<String, String>? = null
private val eventChannel: EventChannel? = null
private var events: EventSink? = null
private val asrCenter: AsrCenter by lazy {
AsrCenter(context, AsrCenter.AsrCenterCallback {
AsrCenter(asrConfig, context, AsrCenter.AsrCenterCallback {
sendMessageToFlutter(it)
})
}
private val ttsNovelCenter: TtsNovelCenter by lazy {
TtsNovelCenter(context, TtsNovelCenter.TtsNovelCenterCallback {
TtsNovelCenter(ttsConfig, context, TtsNovelCenter.TtsNovelCenterCallback {
sendMessageToFlutter(it)
})
}
......@@ -58,7 +60,7 @@ class AivoicePlugin: FlutterPlugin, MethodCallHandler, EventChannel.StreamHandle
asrConfig = call.arguments as Map<String, String>?
// 现有的实现
asrCenter.initEngineBtnClicked()
asrCenter.startEngineBtnClicked()
}
"stopEngine" -> {
// 现有的实现
......@@ -96,6 +98,7 @@ class AivoicePlugin: FlutterPlugin, MethodCallHandler, EventChannel.StreamHandle
ttsNovelCenter.resumePlayback()
}
"ttsInitEngine" -> {
ttsConfig = call.arguments()
ttsNovelCenter.initEngineInternal()
}
"ttsUnInitEngine" -> {
......
......@@ -45,6 +45,9 @@ public class AsrCenter implements SpeechEngine.SpeechListener {
private Context _context = null;
private final Map<String, String> _config;
// Record
private Handler recordHandler = null;
private Runnable recordRunnable = null;
......@@ -75,9 +78,10 @@ public class AsrCenter implements SpeechEngine.SpeechListener {
@SuppressLint({"ClickableViewAccessibility", "InflateParams", "HardwareIds", "UseCompatLoadingForDrawables"})
public AsrCenter(Context context,AsrCenterCallback callback ) {
public AsrCenter(Map<String, String> config, Context context, AsrCenterCallback callback ) {
_context = context;
_callback = callback;
_config = config;
Log.i(SpeechDemoDefines.TAG, "Asr onCreate");
......@@ -185,17 +189,11 @@ public class AsrCenter implements SpeechEngine.SpeechListener {
//【必需配置】识别服务Uri
mSpeechEngine.setOptionString(SpeechEngineDefines.PARAMS_KEY_ASR_URI_STRING, uri);
String appid = mSettings.getString(R.string.config_app_id);
if (appid.isEmpty()) {
appid = SensitiveDefines.APPID;
}
String appid = _config.get("appId");
//【必需配置】鉴权相关:Appid
mSpeechEngine.setOptionString(SpeechEngineDefines.PARAMS_KEY_APP_ID_STRING, appid);
String token = mSettings.getString(R.string.config_token);
if (token.isEmpty()) {
token = SensitiveDefines.TOKEN;
}
String token = _config.get("token");
//【必需配置】鉴权相关:Token
mSpeechEngine.setOptionString(SpeechEngineDefines.PARAMS_KEY_APP_TOKEN_STRING, token);
......
......@@ -65,6 +65,8 @@ public class TtsNovelCenter implements SpeechEngine.SpeechListener {
public String textFromFlutter = "";
private final Map<String, String> _config;
private final String[] mTtsTextTypeArray = {
SpeechEngineDefines.TTS_TEXT_TYPE_PLAIN,
......@@ -141,12 +143,11 @@ public class TtsNovelCenter implements SpeechEngine.SpeechListener {
@SuppressLint({"ClickableViewAccessibility", "InflateParams", "HardwareIds"})
public TtsNovelCenter (Context context, TtsNovelCenterCallback callback ) {
public TtsNovelCenter (Map<String, String> config, Context context, TtsNovelCenterCallback callback ) {
Log.i(SpeechDemoDefines.TAG, "Tts onCreate");
_context = context;
_callback = callback;
_config = config;
String viewId = SpeechDemoDefines.TTS_VIEW;
mSettings = SettingsActivity.getSettings(viewId);
......@@ -246,17 +247,11 @@ public class TtsNovelCenter implements SpeechEngine.SpeechListener {
// ------------------------ 在线合成相关配置 -----------------------
mCurAppId = mSettings.getString(R.string.config_app_id);
if (mCurAppId.isEmpty()) {
mCurAppId = SensitiveDefines.APPID;
}
mCurAppId = _config.get("appId");
//【必需配置】在线合成鉴权相关:Appid
mSpeechEngine.setOptionString(SpeechEngineDefines.PARAMS_KEY_APP_ID_STRING, mCurAppId);
String token = mSettings.getString(R.string.config_token);
if (token.isEmpty()) {
token = SensitiveDefines.TOKEN;
}
String token = _config.get("token");
//【必需配置】在线合成鉴权相关:Token
mSpeechEngine.setOptionString(SpeechEngineDefines.PARAMS_KEY_APP_TOKEN_STRING, token);
......
......@@ -147,7 +147,7 @@ class _MyAppState extends State<MyApp> {
],
),
),
floatingActionButton: asrView,
floatingActionButton: ttsView,
),
);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论