कई 3 पार्टी भाषण मान्यता विकल्पों मूल्यांकन करने के बाद, Google ध्वनि पहचान से है अब तक का सबसे सटीक है। Google वॉयस पहचान का उपयोग करते समय दो बुनियादी दृष्टिकोण हैं।
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
अपने onActivityResults(), तो आपको मैचों सेवा द्वारा दिया संभाल होगा
तो:
/**
* Handle the results from the recognition activity.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//Toast.makeText(this, "voice recog result: " + resultCode, Toast.LENGTH_LONG).show();
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
// Fill the list view with the strings the recognizer thought it could have heard
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
// handleResults
if (matches != null) {
handleResults(matches);
}
}
}
दूसरा दृष्टिकोण और अधिक शामिल है सबसे आसान एक आशय का शुभारंभ और उसके अनुसार परिणाम को संभालने के लिए है लेकिन एक त्रुटि स्थिति के बेहतर संचालन के लिए अनुमति देता है जो पहचान सेवा चल रहा है, जबकि हो सकता है। इस दृष्टिकोण का उपयोग करके, आप अपना खुद का मान्यता श्रोता और कॉलबैक विधियां बनाएंगे।
शुरू सुन: उदाहरण के लिए:
mSpeechRecognizer.startListening(mRecognizerIntent);
जहां mRecognizerIntent:
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(getBaseContext());
mSpeechRecognizer.setRecognitionListener(mRecognitionListener);
mRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mRecognizerIntent.putExtra("calling_package", "com.you.package");
तो, अपने श्रोता बनाएँ:
private RecognitionListener mRecognitionListener = new RecognitionListener() {
public void onBufferReceived(byte[] buffer) {
// TODO Auto-generated method stub
//Log.d(TAG, "onBufferReceived");
}
public void onError(int error) {
// TODO Auto-generated method stub
// here is where you handle the error...
public void onEvent(int eventType, Bundle params) {
// TODO Auto-generated method stub
Log.d(TAG, "onEvent");
}
public void onPartialResults(Bundle partialResults) {
// TODO Auto-generated method stub
Log.d(TAG, "onPartialResults");
}
public void onReadyForSpeech(Bundle params) {
// TODO Auto-generated method stub
Log.d(TAG, "onReadyForSpeech");
}
public void onResults(Bundle results) {
Log.d(TAG, ">>> onResults");
//Toast.makeText(getBaseContext(), "got voice results!", Toast.LENGTH_SHORT);
ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
handleResults(matches);
}
public void onRmsChanged(float rmsdB) {
// TODO Auto-generated method stub
//Log.d(TAG, "onRmsChanged");
}
public void onBeginningOfSpeech() {
// TODO Auto-generated method stub
Log.d(TAG, "onBeginningOfSpeech");
}
public void onEndOfSpeech() {
// TODO Auto-generated method stub
Log.d(TAG, "onEndOfSpeech");
}
};
आप अपने handleResults जोड़ सकते हैं() करने के लिए जो कुछ भी तुम्हें चाहिए।
जब मैं खोज रहा था तब पहली बार मैंने सीएमयूएसफ़िनक्स के बारे में नहीं सुना है। जानकारी के लिए धन्यवाद। – LefterisL