使用 SpeechRecognizer 获取已识别数据的转录
Get transcription of recognized data using SpeechRecognizer
我使用 SpeechRecognizer 实现 "speech-to-text" 功能,她的工作结果是文本数据:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.US.toString());
intent.putExtra("android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES", new String[]{});
SpeechRecognizer recognizer = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
recognizer.setRecognitionListener(new RecognitionListener() {
@Override
public void onReadyForSpeech(Bundle params) {}
@Override
public void onBeginningOfSpeech() {}
@Override
public void onRmsChanged(float rmsdB) {}
@Override
public void onBufferReceived(byte[] buffer) {}
@Override
public void onEndOfSpeech() {}
@Override
public void onError(int error) {}
@Override
public void onPartialResults(Bundle partialResults) {}
@Override
public void onEvent(int eventType, Bundle params) {}
@Override
public void onResults(Bundle results) {
String result = null;
ArrayList<String> arrOfResults = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
String command = arrOfResults.get(0);
}
});
recognizer.startListening(intent);
是否可以使用此方法获取已识别语音而不是文本的转录?
例如,它在 Google 中实现 翻译:
或者,如有必要,使用不同的方法。
我该怎么做?提前致谢。问候...
SpeechReocgnizer API 仅提供 "text"(我猜是正常正字法文本)和可选的置信度分数,请参阅:https://developer.android.com/reference/android/speech/RecognitionListener.html#onResults(android.os.Bundle)
我使用 SpeechRecognizer 实现 "speech-to-text" 功能,她的工作结果是文本数据:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.US.toString());
intent.putExtra("android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES", new String[]{});
SpeechRecognizer recognizer = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
recognizer.setRecognitionListener(new RecognitionListener() {
@Override
public void onReadyForSpeech(Bundle params) {}
@Override
public void onBeginningOfSpeech() {}
@Override
public void onRmsChanged(float rmsdB) {}
@Override
public void onBufferReceived(byte[] buffer) {}
@Override
public void onEndOfSpeech() {}
@Override
public void onError(int error) {}
@Override
public void onPartialResults(Bundle partialResults) {}
@Override
public void onEvent(int eventType, Bundle params) {}
@Override
public void onResults(Bundle results) {
String result = null;
ArrayList<String> arrOfResults = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
String command = arrOfResults.get(0);
}
});
recognizer.startListening(intent);
是否可以使用此方法获取已识别语音而不是文本的转录?
例如,它在 Google 中实现 翻译:
或者,如有必要,使用不同的方法。
我该怎么做?提前致谢。问候...
SpeechReocgnizer API 仅提供 "text"(我猜是正常正字法文本)和可选的置信度分数,请参阅:https://developer.android.com/reference/android/speech/RecognitionListener.html#onResults(android.os.Bundle)