मैं एक ऐप बना रहा हूं जो कुछ कार्यों को करने के लिए वॉयस कमांड का उपयोग करता है। मैं here"ओके Google" जैसे वाक्यांश के साथ आवाज के माध्यम से भाषण मान्यता शुरू करें?
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);
}
से कुछ काम कर कोड मिला है हालांकि, इस पद्धति के लिए एक बटन क्लिक के माध्यम से सक्रिय होने की जरूरत है। वॉयस कमांड के माध्यम से भी भाषण पहचानकर्ता शुरू करने का कोई तरीका है? Google नाओ की तरह, जहां आप केवल "ओके Google" कह सकते हैं, फिर यह स्पीच रिकग्नाइज़र गतिविधि खोल देगा और कमांड सुनेंगे?
धन्यवाद।