首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >隐藏tap to speech界面google speech api

隐藏tap to speech界面google speech api
EN

Stack Overflow用户
提问于 2016-01-02 23:18:52
回答 1查看 743关注 0票数 0

我正在尝试开发使用语音命令访问主菜单的游戏。我想问一下如何隐藏google speech的点击语音界面?因为它几乎覆盖了我所有的屏幕。

EN

回答 1

Stack Overflow用户

发布于 2016-01-03 00:03:07

调用promptSpeechInput()启动语音识别活动。使用onActivityResult()捕捉结果,

代码语言:javascript
复制
/**
 * Showing google speech input dialog
 * */
private void promptSpeechInput() {
    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,
            getString(R.string.speech_prompt));
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(),
                getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}

/**
 * Receiving speech input
 * */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

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

            ArrayList<String> result = data
                    .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            txtSpeechInput.setText(result.get(0));
        }
        break;
    }

    }
}

例如,从按钮:

代码语言:javascript
复制
 speechRecButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            promptSpeechInput();
        }
    });

有关更多具体信息,请访问:http://www.androidhive.info/2014/07/android-speech-to-text-tutorial/

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34567444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档