2017-12-07 7 views
1

내 안드로이드 응용 프로그램에서 SpeechRecognizer 라이브러리를 사용하려고하는데, 지금까지 그 작업으로 인해 질문이 남습니다. 우선, 말하기를 그만 두지 않습니다. 자신을 인식하는 음성을 멈추려면 다음 번에 '일치하지 않습니다!'라는 메시지가 나타납니다. 곧.SpeechRecognizer가 시작 직후에는 일치하지 않습니다.

제 질문은 : Google 음성 인식을 사용할 때 (예 : 웹에서 검색 할 때) 매력처럼 작동합니다. 내 응용 프로그램에서는 완벽하지는 않지만 라이브러리는 동일합니다. 내 구현에 어떤 문제가 있습니까?

내 코드 (간체) :

참고 : 나는 음성 인식보다 유연하게 부분적인 결과를 사용하려고하지만, 인식이 좀 더 빨리 된 것을 제외하고 나는 어떤 효과를 볼 수 없습니다.

public void setupVoiceRecognition(Activity activity) { 
     mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(activity.getApplicationContext()); 
     mSpeechRecognizer.setRecognitionListener(this); 

     mRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
     mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, 
       activity.getPackageName()); 
     mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, 
       true); 
     mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 
       RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 
     mRecognizerIntent.putExtra(EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 5000); 
     mRecognizerIntent.putExtra(EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 3000); 
     mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3); 
     mContext = activity.getApplicationContext(); 
     if (mMainBtn != null) { 
      mMainBtn.setOnClickListener(new View.OnClickListener() { 
       @Override public void onClick(View view) { 
        VoiceRecognition.this.onClick(); 
       } 
      }); 
     } 
    }  

    public void forceStop() { 
     if (mListening) { 
      toggleListening(false); 
     } 
    }  

    public void onClick() {    
     toggleListening(!mListening);    
    } 


    private void toggleListening(boolean start) { 
     mPartialLength = 0; 
     if (start) { 
      mSpeechRecognizer.startListening(mRecognizerIntent); 
     } else { 
      mSpeechRecognizer.stopListening(); 
     } 
     if (mMainBtn != null) { 
      mMainBtn.setImageResource((start) ? R.drawable.icon_record_active : R.drawable.icon_record_white); 
     } 
     if (mSupportBtn != null) { 
      mSupportBtn.setImageResource((start) ? R.drawable.icon_record_active : R.drawable.icon_record_white); 
     } 
     mListening = start; 
    } 

    ... 

    @Override public void onError(int i) { 
     if (mListening) { 
      String errorText; 
      switch (i) { 
       case SpeechRecognizer.ERROR_AUDIO: 
        errorText = MyApp.getContext().getString(R.string.speech_recognition_err3); 
        break; 

       ... 

      } 
      MyApp.showToast(errorText); 
      toggleListening(false); 
      if (i == NO_MATCH) { 
       toggleListening(true); 
      } 
     } 
    } 

    @Override public void onResults(Bundle bundle) { 
     ArrayList<String> matches = bundle 
       .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); 
     if (matches != null) { 
      String fullText = mViewForText.getText().toString(); 
      mViewForText.setText(fullText.substring(0, fullText.length() - mPartialLength) + matches.get(0) + " "); 
      mViewForText.requestFocus(View.FOCUS_RIGHT); 
      mViewForText.setSelection(mViewForText.getText().length()); 
      mPartialLength = 0; 
      forceStop(); 
     } 
    } 

    @Override public void onPartialResults(Bundle bundle) { 
     ArrayList<String> matches = bundle 
       .getStringArrayList(EXTRA_PARTIAL_RESULTS); 
     if (matches != null) { 
      mViewForText.setText(mViewForText.getText().toString() + matches.get(0) + " "); 
      mPartialLength += matches.get(0).length() + 1; 
      mViewForText.requestFocus(View.FOCUS_RIGHT); 
      mViewForText.setSelection(mViewForText.getText().length()); 
     } 
    } 
} 

답변

1

Google은 타사 앱을 위해 SpeechRecognizer를 통해 연속 음성 인식을 비활성화했습니다. 나는 그들이 매우 잘 작동하지만 무료가 아니라 지금 API (https://cloud.google.com/speech/)를 지불했기 때문이라고 생각합니다.

정보 NO_MATCH 오류. Google은 자체 경고음 신호를 듣고 연설 시작이라고 가정합니다. 비프 음이 인식되지 않으면 NO_MATCH 오류가 반환됩니다.

옵션이 있습니다. 인식 서비스에 대한보다 안정적인 작업을 위해 Google 앱을 다운 그레이드 할 수 있습니다. 마지막으로 정상적으로 작동하는 Google 앱 버전은 6.2.34

입니다.
관련 문제