Java源码示例:android.support.v17.leanback.widget.SpeechRecognitionCallback
示例1
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
mFragment = (SearchFragment) getFragmentManager().findFragmentById(R.id.search_fragment);
if (USE_INTERNAL_SPEECH_RECOGNIZER) {
mSpeechRecognitionCallback = new SpeechRecognitionCallback() {
@Override
public void recognizeSpeech() {
if (DEBUG) {
Log.v(TAG, "recognizeSpeech");
}
startActivityForResult(mFragment.getRecognizerIntent(), REQUEST_SPEECH);
}
};
mFragment.setSpeechRecognitionCallback(mSpeechRecognitionCallback);
}
}
示例2
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tv_search);
mFragment = (SearchFragment) getFragmentManager()
.findFragmentById(R.id.search_fragment);
SpeechRecognitionCallback speechRecognitionCallback = new SpeechRecognitionCallback() {
@Override
public void recognizeSpeech() {
startActivityForResult(mFragment.getRecognizerIntent(), REQUEST_SPEECH);
}
};
mFragment.setSpeechRecognitionCallback(speechRecognitionCallback);
}
示例3
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
setSearchResultProvider(this);
setOnItemViewClickedListener(new ItemViewClickedListener());
if (!hasPermission(Manifest.permission.RECORD_AUDIO)) {
// SpeechRecognitionCallback is not required and if not provided recognition will be handled
// using internal speech recognizer, in which case you must have RECORD_AUDIO permission
setSpeechRecognitionCallback(new SpeechRecognitionCallback() {
@Override
public void recognizeSpeech() {
if (DEBUG) Log.v(TAG, "recognizeSpeech");
try {
startActivityForResult(getRecognizerIntent(), REQUEST_SPEECH);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "Cannot find activity for speech recognizer", e);
}
}
});
}
}
示例4
/**
* Set this callback to have the fragment pass speech recognition requests
* to the activity rather than using an internal recognizer.
*/
public void setSpeechRecognitionCallback(SpeechRecognitionCallback callback) {
mSpeechRecognitionCallback = callback;
if (mSearchBar != null) {
mSearchBar.setSpeechRecognitionCallback(mSpeechRecognitionCallback);
}
if (callback != null) {
releaseRecognizer();
}
}
示例5
/**
* Set this callback to have the fragment pass speech recognition requests
* to the activity rather than using an internal recognizer.
*/
public void setSpeechRecognitionCallback(SpeechRecognitionCallback callback) {
mSpeechRecognitionCallback = callback;
if (mSearchBar != null) {
mSearchBar.setSpeechRecognitionCallback(mSpeechRecognitionCallback);
}
if (callback != null) {
releaseRecognizer();
}
}