国产探花免费观看_亚洲丰满少妇自慰呻吟_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使用介紹

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桂平市| 迁安市| 西藏| 武威市| 舞阳县| 东平县| 香河县| 陆丰市| 河东区| 依兰县| 汕尾市| 泰兴市| 清涧县| 金川县| 乐昌市| 巴林左旗| 阿荣旗| 黄陵县| 睢宁县| 南康市| 米脂县| 眉山市| 昔阳县| 六盘水市| 绍兴县| 尉氏县| 元阳县| 丘北县| 枣强县| 浦江县| 临江市| 航空| 安顺市| 高淳县| 会宁县| 长兴县| 宿松县| 乌苏市| 湟中县| 通化市| 三穗县|