国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

google語音識別啟動方式

2019-11-09 15:02:20
字體:
來源:轉載
供稿:網友
1.非Intent方式,沒有google語音識別的界面
PRivate void initGoogleSpeechRecognizer() {    speechGoogle = android.speech.SpeechRecognizer.createSpeechRecognizer(this);    speechGoogle.setRecognitionListener(recognitionListener);    recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, Locale.getDefault().toString());    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault().toString());    // only for 6.0    recognizerIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);    recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName());    recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);}
    private RecognitionListener recognitionListener = new RecognitionListener() {        @Override        public void onBeginningOfSpeech() {            Log.d("GoogleVoice", "onBeginningOfSpeech");//            onSpeechBegin();        }        @Override        public void onBufferReceived(byte[] buffer) {            Log.d("GoogleVoice", "onBufferReceived: " + Arrays.toString(buffer));        }        @Override        public void onEndOfSpeech() {            Log.d("GoogleVoice", "onEndOfSpeech");
           // onSpeechEnd();        }        @Override        public void onError(int errorCode) {            String errorMessage = getErrorText(errorCode);            Log.e("GoogleVoice", "onError : " + errorMessage);
            // onSpeechError();        }        @Override        public void onEvent(int arg0, Bundle arg1) {            Log.d("GoogleVoice", "onEvent");        }        @Override        public void onPartialResults(Bundle arg0) {            Log.d("GoogleVoice", "onPartialResults");        }        @Override        public void onReadyForSpeech(Bundle arg0) {            Log.d("GoogleVoice", "onReadyForSpeech");          //  onSpeechBegin();                   }        @Override        public void onResults(Bundle results) {            ArrayList<String> matches = results.getStringArrayList(android.speech.SpeechRecognizer.RESULTS_RECOGNITION);            if (matches != null && matches.size() > 0) {                Log.d("GoogleVoice", "Google voice onResults:" + matches.get(0));   
 		// onSpeechResult(matches.get(0));            } else {                Log.e("GoogleVoice", "Google voice onResults:" + " results error");            }        }        @Override        public void onRmsChanged(float rmsdB) {            // Log.i(LOG_TAG, "onRmsChanged: " + rmsdB);            //onSpeechChange();        }    };
2.intent方式,有google語音識別默認的界面
final int SPEECHTOTEXT = 1;
//speechGoogle.startListening(recognizerIntent);Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);// Getting an instance of PackageManagerPackageManager pm = getPackageManager();// Querying Package ManagerList<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);if(activities.size()<=0){    Toast.makeText(getBaseContext(),            "No Activity found to handle the action ACTION_RECOGNIZE_SPEECH",            Toast.LENGTH_SHORT).show();    return;}intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,        RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");startActivityForResult(intent,SPEECHTOTEXT);
上一篇:GreenDAO

下一篇:CoreText使用介紹

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 保山市| 兰溪市| 四子王旗| 余姚市| 石首市| 绩溪县| 分宜县| 孟津县| 儋州市| 河曲县| 加查县| 乐业县| 泗水县| 汾阳市| 温宿县| 江都市| 贺兰县| 公主岭市| 夏邑县| 淮南市| 新邵县| 青神县| 麦盖提县| 湛江市| 龙山县| 孟州市| 三明市| 正安县| 巢湖市| 正阳县| 武乡县| 大埔区| 石屏县| 雷波县| 徐州市| 沂水县| 柏乡县| 务川| 新津县| 宁津县| 乐都县|