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

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

google語音識別啟動方式

2019-11-09 16:17:36
字體:
來源:轉載
供稿:網友
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);
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 翁牛特旗| 分宜县| 新晃| 简阳市| 潞西市| 论坛| 平舆县| 云南省| 荣成市| 慈溪市| 南郑县| 大同市| 会昌县| 忻城县| 揭西县| 阳新县| 文安县| 渑池县| 郎溪县| 彭州市| 廉江市| 兴隆县| 温泉县| 双峰县| 新乡市| 恭城| 临西县| 漳州市| 铁力市| 白朗县| 正定县| 嘉黎县| 广德县| 阜宁县| 龙泉市| 乌鲁木齐市| 普兰店市| 钦州市| 色达县| 修武县| 左贡县|