0

我的应用使用 android.speech.SpeechRecognizer。大多数设备工作正常,但在设备魅族 MX6 有例外

java.lang.SecurityException: Not allowed to bind to service Intent { act=android.speech.RecognitionService cmp=com.mediatek.voicecommand.vis/.VoiceWakeupRecognitionService }

更新

语音识别器:

private SpeechRecognizer createSpeechRecognizer(){
    SpeechRecognizer speechRecogn = SpeechRecognizer.createSpeechRecognizer(App.getContext());
    speechRecogn.setRecognitionListener(this);
    return speechRecogn;
}

识别器意图:

 public static Intent createRecognizerIntent(String language){    
        Intent recognIntent = new Intent(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN ?
                RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE :
                RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        recognIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
        recognIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, true);
        recognIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, App.getContext().getPackageName());
        recognIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        recognIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, MAX_RESULTS_VARIANTS);
        recognIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, false);
        recognIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, new Long(10000));
        recognIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, new Long(10000));

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN)
            recognIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);

        recognIntent.putExtra("android.speech.extra.DICTATION_MODE", true);

        if (NetworkManager.isWiFiAvailable(App.getContext())
                && ControllersSsidHelper.isSsidOfControllerWithAnyStatus(ImWiFiManager.getInstance().getSsid()))
            recognIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);

        return recognIntent;
    }

开始收听:

 private void startSpeechRecognition(){
            speechRecognizer = createSpeechRecognizer();
            try {
                speechRecognizer.startListening(recognizerIntent);
            } catch (Exception e){
            }
        }

清单(权限和使用功能):

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:required="false"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:required="false"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:required="false"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" android:required="false" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" android:required="false" />
<uses-permission android:name="android.permission.BLUETOOTH" android:required="false" />
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature android:name="android.hardware.location.network" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-feature android:name="android.hardware.microphone" android:required="false" />
<uses-feature android:name="android.permission.UPDATE_DEVICE_STATS" android:maxSdkVersion="22" android:required="false" />
4

0 回答 0