2017-02-27 1 views
0

안녕하세요이 서비스를 인식 구글의 연설을 실행하고 듣고 해달라고하지만 내가 그것을 다시 시작하거나구글 음성 recognation 리스너

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


    SpeechRecognitionListener listener = new SpeechRecognitionListener(); 
    mSpeechRecognizer.setRecognitionListener(listener); 

    CountDownTimer mTimer = new CountDownTimer(1500, 500) { 
     @Override 
     public void onTick(long l) { 
     } 

     @Override 
     public void onFinish() { 
      Log.d("Speech", "Timer.onFinish: Timer Finished, Restart recognizer"); 
      //mSpeechRecognizer.cancel(); 
      mSpeechRecognizer.startListening(mSpeechRecognizerIntent); 
     } 
    }; 

mTimer.start(); 
+0

얼마나 오래 지속 되었습니까? – FreedomPride

+0

2-3 초 사운드 환경이 없으며 스스로를 닫고 어떻게 다시 시작할 수 있습니까 countdowntimer doesnt effective ?? – xllllll

+0

이 매개 변수를 다소 큰 숫자로 변경할 수 있습니까 ??? 'CountDownTimer mTimer = 새로운 CountDownTimer (1500, 500)' – FreedomPride

답변

0

이 CountdownTimer를 꺼내 루프 할 수있는 방법 초 후에 수신을 중지합니다. 이것을 메서드에 넣고 메서드를 호출하여 청취를 시작합니다.

try { 
     startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); 
    } catch (ActivityNotFoundException a) { 
     Toast.makeText(getApplicationContext(), 
       "Speech not supported on your device", 
       Toast.LENGTH_SHORT).show(); 
    } 

음성 출력은 onActivitySpeech 메서드에서 가져올 수 있습니다.

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == REQ_CODE_SPEECH_INPUT) { 
     if (resultCode == RESULT_OK && data != null) { 
     //Handle the output 
     } 
    } 
} 
+0

오류 인식을 다시 시작하면 루프가 필요합니다. 이것은 단일 시작입니다. – xllllll

+0

resultCode 값을 확인하십시오. RESULT_OK가 아닌 경우 startActivityForResult 메서드가 포함 된 메서드를 호출합니다. –

+0

하지만 팝업이 표시됩니다. 원하지 않습니다. – xllllll

관련 문제