没有谷歌对话框的语音识别 [英] Speech recognition without Google dialog boxes

查看:34
本文介绍了没有谷歌对话框的语音识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将尝试在没有 Google 对话框的情况下使用带有 RecognitionListener 的语音识别但不能只在启动应用程序时发出哔声.我在清单文件中添加了权限音频记录和互联网.我希望你告诉我并帮助我找到错误......我在日志猫上没有错误......我想要在用户打招呼时进行循环,Toast 显示消息 Regognition OK,列表视图显示结果.

I will try to use the Speech recognition without Google dialog boxes with RecognitionListener but does not works only beep when start the application.I have added permissions Audio record and Internet into the manifest file.I hope you tell me and help me to find the wrong...I have not errors on Log cat...I want to make a loop when user say hello a Toast show up a mesage Regognition OK and a list view shows the results.

 public  class MainActivity extends Activity  implements RecognitionListener
{

 private ListView wordsList;

private SpeechRecognizer mSpeechRecognizer;
private Intent mSpeechRecognizerIntent; 


protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
    mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                                     RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                                     this.getPackageName());

    wordsList = (ListView) findViewById(R.id.listView1); 

    mSpeechRecognizer.startListening(mSpeechRecognizerIntent);

}


    public void onBeginningOfSpeech(){ }

        public void onBufferReceived(byte[] buffer){ }

        public void onEndOfSpeech(){ }

        public void onError(int error){

           //mSpeechRecognizer.startListening(mSpeechRecognizerIntent);

    }

    public void onEvent(int eventType, Bundle params){ }


    public void onPartialResults(Bundle partialResults){ }


    public void onReadyForSpeech(Bundle params){


        Toast.makeText(getBaseContext(), "Voice recording starts", Toast.LENGTH_SHORT).show();

    }

    public void onResults(Bundle results)
    {

        ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);


        wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,  matches));


        if ( matches.contains("hello") {

            Toast.makeText(getBaseContext(), "Recognision OK!!!", Toast.LENGTH_SHORT).show();

          }

    }

    public void onRmsChanged(float rmsdB) { }

  }

推荐答案

您错过了:

mSpeechRecognizer.setRecognitionListener();

参数要么是实现监听器的上下文,要么是您创建的自定义监听器.

The parameter will be either be the context which implements the listener, or the custom listener you've created.

目前您的代码没有设置侦听器,您只有侦听器代码.

At the moment your code is not setting the listener, you just have the listener code.

如果你没有实现RecognitionListener,那么你可以这样做:

If you do not implement RecognitionListener, then you can do it this way:

mSpeechRecognizer.setRecognitionListener(new RecognitionListener() {

                                @Override
                                public void onBeginningOfSpeech() {
                                    // TODO Auto-generated method stub

                                }

                                @Override
                                public void onBufferReceived(byte[] arg0) {
                                    // TODO Auto-generated method stub

                                }

                                @Override
                                public void onEndOfSpeech() {
                                    // TODO Auto-generated method stub

                                }

                                @Override
                                public void onError(int arg0) {
                                    // TODO Auto-generated method stub

                                }

                                @Override
                                public void onEvent(int arg0, Bundle arg1) {
                                    // TODO Auto-generated method stub

                                }

                                @Override
                                public void onPartialResults(Bundle partialResults) {
                                    // TODO Auto-generated method stub

                                }

                                @Override
                                public void onReadyForSpeech(Bundle params) {
                                    // TODO Auto-generated method stub

                                }

                                @Override
                                public void onResults(Bundle results) {
                                    // TODO Auto-generated method stub

                                }

                                @Override
                                public void onRmsChanged(float rmsdB) {
                                    // TODO Auto-generated method stub

                                }

                            });

这篇关于没有谷歌对话框的语音识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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