How can I use speech recognition without the annoying dialog in android phones

前端 未结 4 2348
囚心锁ツ
囚心锁ツ 2020-11-22 14:47

Is this possible without modify the android APIs? I\'ve found a article about this. There\'s one a comment that I should do modifications to the android APIs. But it didn\'

4条回答
  •  余生分开走
    2020-11-22 15:25

    Thanks for posting this! I found it helpful to define the onclick listener in oncreate:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        mText = (TextView) findViewById(R.id.textView1);     
        MyRecognitionListener listener = new MyRecognitionListener();
        sr = SpeechRecognizer.createSpeechRecognizer(this);       
        sr.setRecognitionListener(listener);
    
        findViewById(R.id.button1).setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) 
            {
                    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);    
                    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
                    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,1); 
                    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
                    sr.startListening(intent);
            }
        });     
    }
    

提交回复
热议问题