2017-04-06 3 views
-2

좋은 하루,Android 용 음성 인식/받아쓰기

나는 요리/조리법 앱을 제작하는 초기 단계에 있습니다. 앱의 주된 목적은 음성 받아쓰기를 사용하여 요리법을 따르고 트래버스 할 수있게하는 것입니다. 누구든지 이러한 기능을 구현하는 방법에 대한 올바른 방향으로 나를 가리킬 수 있습니까?

감사합니다!

답변

1

은 시스템의 내장 음성 인식 작업을 호출하여 사용자로부터 음성 입력을 얻습니다. 이것은 사용자로부터 입력을 얻은 다음 검색을하거나 메시지로 보내는 것과 같이 입력을 처리하는 데 유용합니다.

앱에서 ACTION_RECOGNIZE_SPEECH 동작을 사용하여 startActivityForResult()를 호출합니다. 그러면 음성 인식 작업이 시작되고 onActivityResult()에서 결과를 처리 할 수 ​​있습니다.

private static final int SPEECH_REQUEST_CODE = 0; 

// Create an intent that can start the Speech Recognizer activity 
private void displaySpeechRecognizer() { 
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 
      RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 
// Start the activity, the intent will be populated with the speech text 
    startActivityForResult(intent, SPEECH_REQUEST_CODE); 
} 

// This callback is invoked when the Speech Recognizer returns. 
// This is where you process the intent and extract the speech text from the intent. 
@Override 
protected void onActivityResult(int requestCode, int resultCode, 
     Intent data) { 
    if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) { 
     List<String> results = data.getStringArrayListExtra(
       RecognizerIntent.EXTRA_RESULTS); 
     String spokenText = results.get(0); 
     // Do something with spokenText 
    } 
    super.onActivityResult(requestCode, resultCode, data); 
}