【问题标题】:How to Text-to-Speech plays on Bluetooth in Android?如何在 Android 的蓝牙上播放文字转语音?
【发布时间】:2013-03-13 17:35:56
【问题描述】:

我是安卓新手。我创建了一个可以使用 Android Text-To-Speech 读取传入消息的应用程序。到目前为止,它很好。现在用户想要它必须通过配对的蓝牙播放。

我已经阅读了所有的论坛,但我没有明白。现在我如何在蓝牙上播放我的 TTS 引擎?

有人知道吗?

提前致谢。

【问题讨论】:

    标签: android text-to-speech android-audiomanager bluetooth-sco


    【解决方案1】:

    Using the Android RecognizerIntent with a bluetooth headset使用我的答案

    并创建一个如下所示的说话方法

    protected void speak(String text)
    {
    
        HashMap<String, String> myHashRender = new HashMap<String, String>();
    
        if (mBluetoothHelper.isOnHeadsetSco())
        {
            myHashRender.put(TextToSpeech.Engine.KEY_PARAM_STREAM, 
                    String.valueOf(AudioManager.STREAM_VOICE_CALL));
        }
        mTts.speak(text, TextToSpeech.QUEUE_FLUSH, myHashRender);
    }
    

    【讨论】:

    • mBluetoothHelper 无法解析为我的 MainActivity 中的变量
    • 您是否将上述链接中的BluetoothHeadsetUtils复制到您的项目中?
    • 是的,我复制了,由于错误,我将您的两行转换为 BluetoothHeadsetUtils mBluetoothHelper = new BluetoothHeadsetUtils(this);
    • 我修复了那里的错误。应该是BluetoothHeadsetUtils mBluetoothHelper;然后另一行是正确的。 mBluetoothHelper 应该是您班级中的班级成员。您将其声明为局部变量,这就是您收到错误的原因。
    • 大约一个小时前,我对 BluetoothHeadsetUtils 类进行了轻微修改。确保您获得最新更新。如果你在课堂上有 mIsStarted,那么你就是最新的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    • 2011-11-04
    • 2016-05-10
    • 2021-11-18
    • 2017-07-17
    • 1970-01-01
    • 2021-04-16
    相关资源
    最近更新 更多