5

RecognitionServiceRecognitionService.Callbackの機能を理解しようとしています。私はこのフレームワークにかなり慣れていないので、RecognitionService で onStartListening() 関数を呼び出す方法を知りたいです。カスタム音声認識サービスの登録方法についての投稿を見ました。しかし、どの関数がいつ呼び出されているかを確認するために、すべての主要な関数にログ メッセージを挿入しました。

sdk のサンプル アプリも見ましたが、何が起こるかを説明するのはかなり下手です。アクティビティから startService を呼び出したい。

私は次の意図を使用します

Intent startServiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    startServiceIntent.setClass(this, SimpleVoiceService.class);

    startService(startServiceIntent);

誰かがこれを機能させるのを手伝ってくれませんか。誰かが私にこれに関するチュートリアルを教えてくれたり、それを行う方法の一般的な流れを説明してくれたりしたら、それは素晴らしいことです.

どうもありがとう。

4

1 に答える 1

1

The basic idea is to use SpeechRecognizer to connect to the RecognitionService that the user has chosen in the general Android settings.

SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(context);
sr.setRecognitionListener(new RecognitionListener() {
    @Override
    public void onResults(Bundle b) { /* ... */ }

    // other required methods
});

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "");
sr.startListening(intent);

You must provide the implementation of the RecognitionListener-methods, allowing you update the UI in response to the speech recognition events (user started speaking, partial results are available, user stopped speaking, transcribing is still going on, an error occurred, etc.).

See the full implementation in the source code of some keyboard apps, e.g. the VoiceInput class in Hacker's Keyboard.

于 2012-07-26T14:44:27.080 に答える