BluetoothVoiceDialerActivity

本文介绍了一个处理语音识别失败并尝试重新识别的方法,同时集成了文本转语音(TTS)功能来指导用户进行语音输入。文章通过具体代码示例展示了如何使用TTS进行语音提示,并设置延迟回调确保系统稳定运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当intent为空的时候,要求重试。

 public void onRecognitionFailure(final String msg) {
            if (Config.LOGD) Log.d(TAG, "onRecognitionFailure " + msg);
            // we had zero results.  Just try again.
            askToTryAgain();
        }

 

 

//加上文本阅读器

mTts = new TextToSpeech(this, new TtsInitListener());

 

 

 

两个线程在准备onSpeechCompletion();

   class FallbackRunnable implements Runnable {
        public void run() {
            Log.e(TAG, "utterance completion not delivered, using fallback");
            // This runnable is intended as a fallback to transition to
            // the next state is for some reason we never get a
            // TTS utterance completion.  It will behave just the same
            // as if we had received utterance completion.
            onSpeechCompletion();
        }
    }

    class GreetingRunnable implements Runnable {
        public void run() {
            mState = SPEAKING_GREETING;
            mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
                    SPEAK_NOW_UTTERANCE);
            mTts.speak(getString(R.string.speak_now_tts),
                TextToSpeech.QUEUE_FLUSH,
                mTtsParams);
            // Normally, the we will begin listening for the command after the
            // utterance completes.  As a fallback in case the utterance
            // does not complete, post a delayed runnable to fire
            // the intent.
            mFallbackRunnable = new FallbackRunnable();
            mHandler.postDelayed(mFallbackRunnable, MAX_TTS_DELAY);
        }
    }

//listening command

listenForCommand();

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值