Domanda

Ho implementato una versione del silentvoicrecognitionservice .

Tuttavia, ho un problema con il servizio che non viene spento correttamente nella misura in cui la prossima volta viene avviata l'applicazione, il servizio lancia un errore_recognizer_busy.

Nel caso in cui ti aiuti, questo è il modo in cui il mio servizio è declinato nel manifest:

    <service
        android:name="com.xyz.SilentVoiceRecognitionService"
        android:label="@string/app_name">
    </service>  
.

Il SilentvoicereCognitionService viene avviato dal servizio principale dell'applicazione (in OnStartCommand):

    public int onStartCommand(Intent intent, int flags, int startId) {
    if (mLiveCard == null) {

        [...]

        startService(new Intent(this, SilentVoiceRecognitionService.class));
    }
    return START_STICKY;
}
.

Il servizio è iniziato una volta.Ecco la dichiarazione del file manifest:

    <service
        android:name="com.xyz.XYZService"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
        </intent-filter>
        <meta-data
            android:name="com.google.android.glass.VoiceTrigger"
            android:resource="@xml/voice_trigger_start" />
    </service>
.

Qualcuno ha un'idea perché questo silentvoicrecognitionservice non è arrestato correttamente?

È stato utile?

Soluzione 2

Non sono ancora sicuro del motivo per cui c'è un riconoscimento già ascoltando quando si avvia l'app.Tuttavia, i test per il suo stato in OnError (), annullare il riconoscimento e il riavvio dell'ascolto ha funzionato per me.

Ecco il codice che ho usato:

        @Override
    public void onError(int arg0) {
         String mError = "";
            switch (arg0) {
            case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:                
                mError = " network timeout"; 
                break;
            case SpeechRecognizer.ERROR_NETWORK: 
                mError = " network" ;
                return;
            case SpeechRecognizer.ERROR_AUDIO: 
                mError = " audio"; 
                break;
            case SpeechRecognizer.ERROR_SERVER: 
                mError = " server"; 
                break;
            case SpeechRecognizer.ERROR_CLIENT: 
                mError = " client"; 
                break;
            case SpeechRecognizer.ERROR_SPEECH_TIMEOUT: 
                mError = " speech time out" ; 
                break;
            case SpeechRecognizer.ERROR_NO_MATCH: 
                mError = " no match" ; 
                break;
            case SpeechRecognizer.ERROR_RECOGNIZER_BUSY: 
                mError = " recogniser busy" ; 
                mSpeechRecognizer.cancel();
                break;
            case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS: 
                mError = " insufficient permissions" ; 
                break;
            default:
                mError = "Unknown Error";
            }
            Log.i(TAG,  "Error: " +  arg0 + " - " + mError);
            mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
    }
.

Altri suggerimenti

Forse prova a mettere un stopService nel tuo OnDestroy del tuo servizio / attività.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top