提交 c652dadb 作者: 王苏进

feat:增加参数接受

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