44

いろいろ調べてみましたが、わからないので、どなたか教えていただければ幸いです。

ダイアログが表示されない独自の音声認識アプリを構築しようとしています。

私はすでにいくつかのコードを書いており、それは非常にうまく機能しますが、私の問題は、LogCat にエラーやその他のメッセージが表示されずに認識機能が停止しているように見えることです。

奇妙なことに、「RecognitionListener」インターフェイスからの「onRmsChanged」は常に呼び出されていますが、「onBeginningOfSpeech」は呼び出されていません。

音声認識が開始された直後に話すと、機能します。しかし、数秒待ってもそうはなりません。

使用されている API は 4.0.3 で、バージョン 4.2.1 の Nexus 7 にインストールしました。

何かいい案があればよろしくお願いします。

いくつかのコード スニペット:

私のクラス:

class SpeechListener implements RecognitionListener
{

    public void onBeginningOfSpeech() 
    {
        Log.d(TAG, "onBeginningOfSpeech()");            
    }

    public void onBufferReceived(byte[] buffer) 
    {
        Log.d(TAG, "onBufferReceived()");
    }

    public void onEndOfSpeech() 
    {
        Log.d(TAG, "onEndOfSpeech()");

    }

    public void onError(int error) 
    {
        Log.d(TAG, "onError(): " + error);

        if(error == SpeechRecognizer.ERROR_NO_MATCH)
        {

        }
        else if(error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT)
        {

        }
        else
        {
            tvOutput.setText("Error: " + error);    
        }

    }

    public void onEvent(int eventType, Bundle params) 
    {
        Log.d(TAG, "onEvent()");
    }

    public void onPartialResults(Bundle partialResults) 
    {
        Log.d(TAG, "onPartialResults()");
    }

    public void onReadyForSpeech(Bundle params) 
    {
        Log.d(TAG, "onReadyForSpeech()");
    }

    public void onResults(Bundle results) 
    {
        Log.d(TAG, "onResults(): " + results);

        String str = new String();

        ArrayList<String> data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);

        for(int i = 0; i < data.size(); i++)
        {
            str += data.get(i) + "\n";

        }           
        tvOutput.setText(tvOutput.getText().toString() + "\n\n" + "Results: " + str);           

    }
    public void onRmsChanged(float rmsdB) 
    {
        Log.d(TAG, "onRmsChanged()");
    }

}

そして、MainActivity での私の実装:

    this.srSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
    this.srSpeechRecognizer.setRecognitionListener(new SpeechListener());

    this.iSpeechIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    this.iSpeechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    this.iSpeechIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "voice.recognition.test");      
    this.iSpeechIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 10);

そして、それは始まりました:

srSpeechRecognizer.startListening(iSpeechIntent);

話すログ:

    12-16 13:50:53.576: D/DreamManagerService(485): Dream finished:   android.os.Binder@415bbf38
    12-16 13:50:53.576: I/DreamManagerService(485): Leaving dreamland.
    12-16 13:50:53.576: I/DreamController(485): Stopping dream: name=ComponentInfo{com.google.android.deskclock/com.android.deskclock.Screensaver}, isTest=false, userId=0
    12-16 13:50:53.586: I/PowerManagerService(485): Waking up from dream...
    12-16 13:50:53.616: I/ActivityManager(485): No longer want com.google.android.gsf.login (pid 13171): empty #17
    12-16 13:50:56.796: I/GoogleRecognitionServiceImpl(1461): #startListening [de-DE]
    12-16 13:50:56.806: I/ActivityManager(485): Start proc com.google.android.gsf.login for service com.google.android.gsf.login/com.google.android.gsf.loginservice.GoogleLoginService: pid=13343 uid=10019 gids={50019, 3003, 1007, 1028, 1015, 2001, 3006}
    12-16 13:50:56.866: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:56.886: D/dalvikvm(1461): GC_FOR_ALLOC freed 516K, 12% free 8706K/9892K, paused 18ms, total 18ms
    12-16 13:50:56.906: D/dalvikvm(1461): GC_CONCURRENT freed 160K, 9% free 9015K/9892K, paused 3ms+2ms, total 21ms
    12-16 13:50:56.906: I/AudioService(485):  AudioFocus  requestAudioFocus() from android.media.AudioManager@4135e960com.google.android.speech.audio.AudioController$1@41261910
    12-16 13:50:56.916: I/VS.G3EngineManager(1461): create_rm: m=ENDPOINTER_VOICESEARCH,l=en-US
    12-16 13:50:56.916: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:56.916: I/VS.G3EngineManager(1461): Brought up new g3 instance :/system/usr/srec/en-US/endpointer_voicesearch.config for: en-USin: 3 ms
    12-16 13:50:56.926: I/ConnectionFactoryImpl(1461): Opening SSL connection: vs.google.com:14259
    12-16 13:50:56.966: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.016: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.066: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.116: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.166: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.216: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.266: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.316: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.366: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.416: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.466: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.516: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.566: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.616: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.666: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.716: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.766: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.816: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.866: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.916: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:57.966: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.016: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.066: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.116: I/MainActivity/SpeechListener(13268): onBeginningOfSpeech()
    12-16 13:50:58.126: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.176: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.226: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.276: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.326: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.376: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.426: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.476: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.526: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.576: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.626: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.676: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.726: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.776: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.826: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.876: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.926: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:58.976: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.026: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.076: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.126: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.176: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.236: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.286: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.336: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.386: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.436: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.486: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.536: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.586: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.636: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.646: I/MicrophoneInputStream(1461): mic_close
    12-16 13:50:59.666: I/AudioService(485):  AudioFocus  abandonAudioFocus() from         android.media.AudioManager@4135e960com.google.android.speech.audio.AudioController$1@41261910
    12-16 13:50:59.666: D/dalvikvm(1461): threadid=37: thread exiting, not yet detached (count=0)
    12-16 13:50:59.666: I/MainActivity/SpeechListener(13268): onEndOfSpeech()
    12-16 13:50:59.676: I/decoder(1461): INFO: recognition time wall: 2.732 sec user: 0.54 sec sys: 0.08 sec 
    12-16 13:50:59.686: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.736: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.786: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.826: I/MainActivity/SpeechListener(13268): onResults(): Bundle[mParcelledData.dataSize=292]
    12-16 13:50:59.836: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.886: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.936: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:50:59.986: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:51:00.046: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:51:00.096: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:51:00.146: D/MainActivity/SpeechListener(13268): onRmsChanged()
    12-16 13:51:00.196: D/MainActivity/SpeechListener(13268): onRmsChanged()

話さずにログを記録する:

    12-16 13:53:39.246: I/GoogleRecognitionServiceImpl(1461): #startListening [de-DE]
    12-16 13:53:39.296: D/dalvikvm(1461): GC_FOR_ALLOC freed 567K, 12% free 8708K/9892K, paused 21ms, total 21ms
    12-16 13:53:39.316: D/dalvikvm(1461): GC_CONCURRENT freed 164K, 9% free 9017K/9892K, paused 3ms+2ms, total 21ms
    12-16 13:53:39.316: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.316: I/AudioService(485):  AudioFocus  requestAudioFocus() from         android.media.AudioManager@4135e960com.google.android.speech.audio.AudioController$1@41261910
    12-16 13:53:39.326: I/VS.G3EngineManager(1461): create_rm: m=ENDPOINTER_VOICESEARCH,l=en-US
    12-16 13:53:39.326: I/ConnectionFactoryImpl(1461): Opening SSL connection: vs.google.com:14259
    12-16 13:53:39.326: I/VS.G3EngineManager(1461): Brought up new g3 instance :/system/usr/srec/en-US/endpointer_voicesearch.config for: en-USin: 5 ms
    12-16 13:53:39.366: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.416: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.466: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.516: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.576: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.626: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.676: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.726: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.776: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.826: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.876: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.926: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:39.976: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.026: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.076: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.136: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.176: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.226: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.286: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.336: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.386: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.436: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.486: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.536: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.586: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.636: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.686: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.736: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.786: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.836: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.886: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.936: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:40.986: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.046: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.096: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.146: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.196: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.246: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.296: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.346: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.396: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.446: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.496: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.546: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.596: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.646: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.696: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.746: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.796: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.846: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.896: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.946: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:41.996: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.046: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.096: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.146: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.196: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.246: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.296: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.356: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.406: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.456: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.506: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.556: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.606: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.656: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.706: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.756: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.806: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.856: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.906: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:42.956: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.006: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.056: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.116: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.156: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.216: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.266: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.316: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.366: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.416: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.466: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.516: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.566: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.616: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.666: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.716: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.766: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.816: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.866: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.916: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:43.966: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.016: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.066: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.116: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.166: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.226: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.276: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.326: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.376: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.426: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.476: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.526: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.576: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.626: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.676: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.726: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.776: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.826: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.876: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.926: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:44.976: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.026: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.076: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.126: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.176: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.226: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.276: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.326: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.376: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.426: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.476: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.526: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.576: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.636: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.676: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.736: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.786: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.836: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.886: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.936: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:45.986: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.036: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.086: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.136: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.186: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.236: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.286: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.336: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.386: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.436: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.486: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.536: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.596: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.636: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.696: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.746: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.796: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.846: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.896: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.946: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:46.996: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.046: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.096: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.146: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.196: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.246: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.296: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.346: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.396: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.446: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.496: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.556: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.596: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.656: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.696: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.746: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.796: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.856: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.906: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:47.956: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.006: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.056: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.106: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.156: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.206: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.256: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.306: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.356: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.406: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.456: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.506: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.556: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.616: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.656: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.706: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.766: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.816: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.866: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.916: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:48.966: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.016: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.066: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.116: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.166: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.216: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.266: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.316: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.366: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.416: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.466: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.516: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.566: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.616: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.666: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.716: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.776: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.816: D/dalvikvm(1461): GC_FOR_ALLOC freed 106K, 9% free 9025K/9892K,         paused 32ms, total 32ms
    12-16 13:53:49.816: I/dalvikvm-heap(1461): Grow heap (frag case) to 9.282MB for 320656-byte allocation
    12-16 13:53:49.836: D/dalvikvm(1461): GC_FOR_ALLOC freed 156K, 11% free 9182K/10208K, paused 19ms, total 19ms
    12-16 13:53:49.836: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.886: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.936: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:49.986: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:50.036: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:50.086: D/MainActivity/SpeechListener(13441): onRmsChanged()
    12-16 13:53:50.136: D/MainActivity/SpeechListener(13441): onRmsChanged()
4

5 に答える 5

19

この問題を確実に回避する唯一の解決策は、サードパーティのサービスを使用することです。 4.1.1 と 4.2 はどちらも音声認識サービスのバージョンに依存しており、それを実行しているサービスがサイレント モードで停止するという文書化された動作に準拠していません。

サード パーティの API を使用したくなく、何らかの方法でこのサービスの終了を説明する必要がある場合、それ可能ですが、きれいでも理想的でもありません。

サービスが終了すると、次のメソッドは呼び出されなくなります。

  • onBeginningOfSpeech
  • onError
  • onResults
  • onEndOfSpeech

ただし、サービスが終了する前に onBeginningOfSpeech が呼び出された場合、最終的には onError または onEndOfSpeech が呼び出されることが保証されます。

したがって、Jellybean でサービスの生死を確実に認識したいだけの場合は、組み込みの SpeechRecognizer でこの問題を回避するには、次の手順を実行します。

  • isSpeechRecognizerAlive のようなブール フラグを作成します。
  • SpeechRecognizer を起動するときはいつでも、上記のフラグを false に設定してください。
  • onBeginningOfSpeech で、呼び出された場合は、isSpeechRecognizerAlive を true に設定します。
  • 4 秒の遅延で isSpeechRecognizerAlive のステータスをチェックするハンドラを維持します。false の場合は、SpeechRecognizer インスタンスを手動で強制終了します。真の場合、何もしません。通常の流れがあなたに代わって物事を処理します。

これが継続的な音声認識設定を維持するための理想的なソリューションではない理由

あなたの質問には直接記載されていませんでしたが、音声認識を継続できるようにするために、これを実行したいと考えている人が何人かいます。 4.1.1 と 4.2 でこれを行うのはあまり良い方法ではありません。これは、 Google の SpeechRecognition サービスがオプションではない「ブループ」効果音で開始されるためです。この音を消す方法はないようです。それを制御する API には何もリストされていません。あなたのユーザーは、4 秒間の繰り返しループで「ブループ」されることに感謝しません。

于 2013-01-08T20:59:37.383 に答える
3

次のRecognizerIntentエクストラを提供することを試みることができます。

  • EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS
  • EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS
  • EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS

ただし、この場合にはどれも当てはまりません。WAIT_UNTIL_I_START_SPEAKINGAndroid は単に " " エクストラを提供していません。これはバグではなく (Jelly Bean でもどこでも)、単に機能が不足しているだけです。また、Android の将来のバージョンでそのような追加機能が追加されたとしても、音声認識アプリ (Google 音声検索など) が実際にこれを実装するという保証はないかもしれません。RecognizerIntentのドキュメントには、動作が規定されていない追加機能が多数含まれています。

onEndOfSpeechあなたの最善の選択肢は、またはを取得したらすぐに認識エンジンを再起動することですonError

于 2013-01-02T23:16:42.423 に答える