gpt4 book ai didi

android - 如何以编程方式关闭 Android Speech To Text 对话框

转载 作者:行者123 更新时间:2023-12-04 13:48:35 24 4
gpt4 key购买 nike

我是android编程的新手。
目前,我正在研究 android 中的 Speech To Text。
如果用户这样做,我想以编程方式关闭语音输入提示
什么都不说。

我该怎么做?

这是代码。

public void startSpeech(View view) {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
"Speak something");
try {
startActivityForResult(intent, 84);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
"Speech is currently not supported",
Toast.LENGTH_LONG).show();
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

switch (requestCode) {
case 84: {
if (resultCode == RESULT_OK && data != null) {

ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
// The spoken words...
}
// if user did not speak anything, then close the dialog.
// ???
break;
}

}
}

最佳答案

只需使用

finishActivity(REQ_CODE_SPEECH_INPUT);

关于android - 如何以编程方式关闭 Android Speech To Text 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37437338/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com