Reputation: 948
I'm trying to build application that could help me dial a contact just like Google Voice search does, however using Czech language by using Google Voice via RecognizerIntent.
What's the problem, it doesn't seem to browse my contact list.
Let's say the contact name's "Rebro" [or anything that's not part of dictionary "e.g. Schwarzenegger, or so]
No matter what language chosen, or if I pronounce the name using english pronounciation or czech one, it never gets in the results set when calling data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
Is this even somehow possible ? If it is, how can I achieve that ? Thanks a lot in advance
EDIT: Code added...It's a code I found somewhere on the net
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends Activity implements OnClickListener {
private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
private ListView mList;
/**
* Called with the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button speakButton = (Button) findViewById(R.id.button1);
mList = (ListView) findViewById(R.id.listView1);
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() != 0) {
speakButton.setOnClickListener(this);
} else {
speakButton.setEnabled(false);
speakButton.setText("Recognizer not present");
}
}
/**
* Handle the click on the start recognition button.
*/
public void onClick(View v) {
if (v.getId() == R.id.button1) {
startVoiceRecognitionActivity();
}
}
/**
* Fire an intent to start the speech recognition activity.
*/
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
/**
* Handle the results from the recognition activity.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
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);
mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
matches));
}
super.onActivityResult(requestCode, resultCode, data);
}
}
Upvotes: 1
Views: 1594
Reputation: 34380
it is not possible with speechRecongizer because it will allow only the big town cities names not names like any. its upto google to enhance it accordingly. but you can see other library pocketphinx
Upvotes: 0
Reputation: 10672
I think Google Voice Search does not (and cannot) expose all its capability through RecognizerIntent
, i.e. it will just perform general speech transcription without any support for voice commands (call ...
, text ...
) or knowledge about the content of your address book. The RecognizerIntent
API unfortunately does not let you specify a grammar or a list of allowed words.
The solution would be to ignore Google's speech recognizer and implement your own. Look e.g. into Pocketsphinx. You need to have Czech acoustic models, unless you want to pronounce the names in the English way (for which you could use the English acoustic models that CMU Sphinx comes with).
I've implemented an open-source Pocketsphinx-based contacts search app for Estonian, see Inimesed.
Upvotes: 3