domingo, 20 de janeiro de 2013
Voice recognition Android and Java
This is the base code you can use to implement a voice recognition app for android using java.
private void startVoiceRecognition()
{
final String TAG="teste3";
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
"com.domain.app");
SpeechRecognizer recognizer = SpeechRecognizer
.createSpeechRecognizer(this.getApplicationContext());
RecognitionListener listener = new RecognitionListener() {
@Override
public void onResults(Bundle results) {
ArrayList<String> voiceResults = results
.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if (voiceResults == null) {
Log.e(TAG, "No voice results");
} else {
Log.d(TAG, "Printing matches: ");
for (String match : voiceResults) {
Log.d(TAG, match);
}
}
Remember to add the correct permissions in your AndroidManifest.xml. If you don't you will get several errors. You need to be connected to internet to use voice recognizer.
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
How to change voice recognition language in Android?
This can be useful when you using an app with voice recognition or when you making an app that uses voice recognition. You can change the language in Settings > Voice Input and output > Voice recognition settings > Language . If you don't make this changes you will get wrong results from the voice recognition.
Subscrever:
Comentários (Atom)