如何在 Text To Speech 停止时启动语音识别。

兰吉特·瓦马德万

我想在 Text To Speech 停止后立即启动语音识别。以下是我采取的步骤。

第 1 步:初始化语音识别。

    mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
    mSpeechRecognizer.setRecognitionListener(recognitionListener);

    mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,
            Locale.getDefault());

步骤 2:初始化文本到语音。

    TextToSpeech myTTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if(myTTS.getEngines().size() == 0){
                Toast.makeText(Robo.this,"No Engines Installed",Toast.LENGTH_LONG).show();
            }else{


                if (status == TextToSpeech.SUCCESS){
                    //Toast.makeText(MainActivity.this,"Status working.",Toast.LENGTH_LONG).show();
                    //message = "How may i help you.";
                    myTTS.setLanguage(Locale.US);
                    ttsInitialized();
                    speak("what is your name.");
                }

            }
        }
    });

步骤 3:初始化 Utterance Listener 以检查 Speech 是否完成。

    myTTS.setOnUtteranceProgressListener(new UtteranceProgressListener() {
        @Override
        public void onStart(String utteranceId) {

        }

        @Override
        public void onDone(String utteranceId) {

            //btn.performClick();
            myTTS.shutdown();
            mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
        }

        @Override
        public void onError(String utteranceId) {

        }
    });

在 onDone() 方法中 mSpeechRecognizer.startListening(mSpeechRecognizerIntent); 用于启动语音识别,但不启动语音识别。请看问题。

兰吉特·瓦马德万

正如@Regulus 所说,我添加了一个 Handler 并且它起作用了。

    @Override
    public void onDone(String utteranceId) {

        Handler mainHandler = new Handler(Looper.getMainLooper());
            Runnable myRunnable = new Runnable() {
                @Override
                public void run() {
                    mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
                } // This is your code
            };
            mainHandler.post(myRunnable);

    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Python程序中嵌入Google Speech to Text API?

来自分类Dev

如何停止Sublime Text 2在启动时崩溃

来自分类Dev

如何自动在我的页面上启动Google语音识别?

来自分类Dev

Highlight text while Text to Speech is running

来自分类Dev

speech to text javascript to recognize medical dictionary

来自分类Dev

如何在Twilio中集成Google Text-To-Speech(或XML标签中带有“&”的URL)

来自分类Dev

如何在Web Speech API中继续识别而不重复权限信息栏?

来自分类Dev

如何对IBM Waston Speech to text API使用关键字发现功能?

来自分类Dev

Kaldi是否会返回类似于Google Speech-To-Text API的任何识别置信度参数?

来自分类Dev

如何使用Python接收Watson Speech to Text SDK的全部输出?

来自分类Dev

如何在Google Speech-to-Text API中进行多个streamingRecognize请求?

来自分类Dev

如何在PHP中正确实现Microsoft Text to Speech

来自分类Dev

如何在python语音识别器中启动mp4文件?

来自分类Dev

尝试使用Google Cloud Text-to-Speech API时无效的JWT

来自分类Dev

如何为Microsoft Text to Speech引擎添加更多声音?

来自分类Dev

Microsoft Speech无法识别语音

来自分类Dev

如何设置语音识别器的开始和停止

来自分类Dev

Android Speech-To-Text:语音停止后保持活动状态的选项

来自分类Dev

如何在HTML5 Web Speech API上使用多个按钮识别器

来自分类Dev

如何对IBM Waston Speech to text API使用关键字发现功能?

来自分类Dev

如何在cordova应用程序中使用Watson Text2Speech REST API?

来自分类Dev

Speech to Text 音频格式

来自分类Dev

Watson Speech to Text:如何在 Windows 10 上设置我的用户名和密码

来自分类Dev

Unity Speech to Text with Azure

来自分类Dev

如何在 C# 中使用 System.Speech 获取原始语音数据?

来自分类Dev

IBM Text to Speech:如何在德语文本中正确发音英语单词?

来自分类Dev

使用 Microsoft Cognitive Speech + Websocket 进行连续语音识别 - Xamarin

来自分类Dev

如何将 Google Cloud Text-to-Speech 与 Meteor 集成

来自分类Dev

如何通过 firemonkey 在 iOS 应用中实现 text-2-speech 功能?

Related 相关文章

  1. 1

    如何在Python程序中嵌入Google Speech to Text API?

  2. 2

    如何停止Sublime Text 2在启动时崩溃

  3. 3

    如何自动在我的页面上启动Google语音识别?

  4. 4

    Highlight text while Text to Speech is running

  5. 5

    speech to text javascript to recognize medical dictionary

  6. 6

    如何在Twilio中集成Google Text-To-Speech(或XML标签中带有“&”的URL)

  7. 7

    如何在Web Speech API中继续识别而不重复权限信息栏?

  8. 8

    如何对IBM Waston Speech to text API使用关键字发现功能?

  9. 9

    Kaldi是否会返回类似于Google Speech-To-Text API的任何识别置信度参数?

  10. 10

    如何使用Python接收Watson Speech to Text SDK的全部输出?

  11. 11

    如何在Google Speech-to-Text API中进行多个streamingRecognize请求?

  12. 12

    如何在PHP中正确实现Microsoft Text to Speech

  13. 13

    如何在python语音识别器中启动mp4文件?

  14. 14

    尝试使用Google Cloud Text-to-Speech API时无效的JWT

  15. 15

    如何为Microsoft Text to Speech引擎添加更多声音?

  16. 16

    Microsoft Speech无法识别语音

  17. 17

    如何设置语音识别器的开始和停止

  18. 18

    Android Speech-To-Text:语音停止后保持活动状态的选项

  19. 19

    如何在HTML5 Web Speech API上使用多个按钮识别器

  20. 20

    如何对IBM Waston Speech to text API使用关键字发现功能?

  21. 21

    如何在cordova应用程序中使用Watson Text2Speech REST API?

  22. 22

    Speech to Text 音频格式

  23. 23

    Watson Speech to Text:如何在 Windows 10 上设置我的用户名和密码

  24. 24

    Unity Speech to Text with Azure

  25. 25

    如何在 C# 中使用 System.Speech 获取原始语音数据?

  26. 26

    IBM Text to Speech:如何在德语文本中正确发音英语单词?

  27. 27

    使用 Microsoft Cognitive Speech + Websocket 进行连续语音识别 - Xamarin

  28. 28

    如何将 Google Cloud Text-to-Speech 与 Meteor 集成

  29. 29

    如何通过 firemonkey 在 iOS 应用中实现 text-2-speech 功能?

热门标签

归档