语音识别不工作的Andr​​oid [英] Speech recognition not works Android

查看:191
本文介绍了语音识别不工作的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在显示器的TextView 我说使用TTS引擎。我有一个按钮

I want display in a TextView what I say using the tts engine. I have a Button:

btnparla.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                    i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                    i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say something");

                    try {
                        startActivityForResult(i, VOICE_REC);
                        //txt.setText("");
                    } catch (ActivityNotFoundException e){
                        Toast t = Toast.makeText(getApplicationContext(), "Errore", Toast.LENGTH_SHORT);
                        t.show();
                    }
                }   

            });

和则:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        // TODO: Implement this method
        super.onActivityResult(requestCode, resultCode, data);

        switch (resultCode) {
            case VOICE_REC: {
                    if (resultCode == Activity.RESULT_OK) {
                        ArrayList<String> dico = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                        resultList.setText(dico.get(0));

                    }
                    break;
                }


                }
        }

其中, resultList 的TextView 的onCreate resultList =(的TextView)findViewById(R.id.list); 。在按钮工作,但在的TextView 不保存任何东西。它不显示我的话。怎么了?

where resultList is a TextView declared in the onCreate resultList = (TextView) findViewById(R.id.list);. The Button works but does not save anything in the TextView. It does not display what I say. What's wrong?

推荐答案

startActivityForResult参数VOICE_REC(I,VOICE_REC); 是请求code不结果code。改变从开关状态开关(结果code)开关(要求code)

The parameter VOICE_REC in startActivityForResult(i, VOICE_REC); is the requestCode not the resultCode. Change the switch condition from switch (resultCode) to switch (requestCode).

    switch (requestCode) {
        case VOICE_REC: {
            if (resultCode == Activity.RESULT_OK) {
                ArrayList<String> dico =  data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                resultList.setText(dico.get(0));

            }
            break;
        }
    }

这篇关于语音识别不工作的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆