How Can I Implement Google Voice Typing In My Application?

前端 未结 4 2150
梦毁少年i
梦毁少年i 2021-02-14 05:19

I am trying to add a button in my application that starts Google Voice Typing (or the default speech recognition). I have tried following this tutorial. This tutorial is incredi

相关标签:
4条回答
  • 2021-02-14 05:47

    I had the same issue, but after a long time looking for continuous voice dictation on an activity, I solved that problem using pocketsphinx.

    I couldn't find the way to integrate Google Voice Typing on an activity, just on an input method by following that tutorial. If it confuse you, just download this demo and modify it. Good Luck!

    0 讨论(0)
  • 2021-02-14 05:49

    You can trigger an intent from a button listener

    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
    

    And the result can be get from

    private TextToSpeech mTts;
    protected void onActivityResult(
            int requestCode, int resultCode, Intent data) {
        if (requestCode == MY_DATA_CHECK_CODE) {
            if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
                // success, create the TTS instance
                mTts = new TextToSpeech(this, this);
            } else {
                // missing data, install it
                Intent installIntent = new Intent();
                installIntent.setAction(
                    TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                startActivity(installIntent);
            }
        }
    }
    

    Refer this link for more info.

    0 讨论(0)
  • 2021-02-14 05:52

    If you want to follow the tutorial that you mention then you need to implement an IME (input method editor) first, see http://developer.android.com/guide/topics/text/creating-input-method.html

    This IME can have a regular keyboard look-and-feel or contain just a microphone button.

    The user of your app will first have to click on a text field to launch the IME. (Note that there can be several IMEs installed on the device and they have to be explicitly enabled in the Settings.) Then the user will have to click on the microphone button to trigger the speech recognition.

    The tutorial provides a jar that lets you directly call Google's recognizer. It would be nicer if instead you called the recognizer via the SpeechRecognizer-interface (http://developer.android.com/reference/android/speech/SpeechRecognizer.html), this way the user can decide whether to use Google's or something else.

    The SpeechRecognizer is given a listener which supports the method onPartialResults, which allows you to monitor the recognition hypotheses while the user is speaking. It's up to you how you display them. Note however that the specification of SpeechRecognizer does not promise that this method gets called. This depends on the implementation of the recognizer service. Regarding Google's implementation: what it supports keeps changing unannounced, it does not have a public API nor even release notes.

    You might be able to reuse my project Kõnele (http://kaljurand.github.io/K6nele/about/), which contains two implementations of SpeechRecognizer and an IME that uses them. One of the implementations offers continuous recognition of arbitrarily long audio input, using the Kaldi GStreamer server (https://github.com/alumae/kaldi-gstreamer-server). You would need to set up your own instance of the server porting it to the language that you want to recognize (unless you want to use the Estonian server that Kõnele uses by default).

    0 讨论(0)
  • 2021-02-14 06:06

    Voice recognition samples are found where you have the android SDK..

    example:

    $ find $SDK_ROOT/samples -name *recogni*
    
    
    ./android-19/legacy/VoiceRecognitionService/res/xml/recognizer.xml
    ./android-19/legacy/VoiceRecognitionService/src/com/example/android/voicerecognitionservice
    ./android-19/legacy/ApiDemos/res/layout/voice_recognition.xml
    ./android-18/legacy/VoiceRecognitionService/res/xml/recognizer.xml
    ./android-18/legacy/VoiceRecognitionService/src/com/example/android/voicerecognitionservice
    ./android-18/legacy/ApiDemos/res/layout/voice_recognition.xml
    ./android-21/legacy/VoiceRecognitionService/res/xml/recognizer.xml
    ./android-21/legacy/VoiceRecognitionService/src/com/example/android/voicerecognitionservice
    ./android-21/legacy/ApiDemos/res/layout/voice_recognition.xml
    

    any one of the services should help show how to do a RecognizerIntent

    The "APIDemo" seems to include use of a RecognizerIntent. check the source for that one. Otherwise look into the services and carve them up into an intent.

    0 讨论(0)
提交回复
热议问题