TTS 输出总是转到 A2DP [英] TTS output always going to A2DP

查看:33
本文介绍了TTS 输出总是转到 A2DP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Android 教程指出我可以明确告诉 TTS 引擎使用哪个流:

My Android tutorial states that I can explicitly tell the TTS engine which stream to use:

音乐播放:

params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_MUSIC));

对于电话:

params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL));

我的理解是,音频路由到蓝牙耳机的工作原理是 STREAM_MUSIC 转到 A2DP(在 Android 蓝牙设置中也称为媒体音频")和 STREAM_VOICE_CALL 转到 HSP(在 Android 蓝牙设置中也称为电话音频").

My understanding is that audio routing to a Bluetooth headset works such that STREAM_MUSIC goes to A2DP (aka "media audio" in Android Bluetooth settings) and STREAM_VOICE_CALL goes to HSP (aka "phone audio" in Android Bluetooth settings).

但是无论我在我的小应用程序中使用 STREAM_MUSIC 还是 STREAM_VOICE_CALL音频总是出于某种原因去A2DP.

But regardless whether I use STREAM_MUSIC or STREAM_VOICE_CALL in my little application, the audio always goes for some reason to A2DP.

我做错了什么?有没有办法将 TTS 输出路由到耳机的 HSP 配置文件?

What am I am doing wrong? Is there a way to route TTS output to headset's HSP profile?

推荐答案

我在大多数设备上都能正常工作.这是使用蓝牙 SCO 而不是 A2DP 在语音呼叫流上启动 TTS 的部分.

I got this working for the most part, on most devices. Here is the part that starts the TTS on the voice call stream using Bluetooth SCO instead of A2DP.

if (mTtsReady) {
    myHash = new HashMap<String, String>();

    myHash.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "A2DP_Vol");

    OLD_AUDIO_MODE = am2.getMode();
    if(SMSstream == 1){
        if (am2.isBluetoothScoAvailableOffCall()) {
            am2.startBluetoothSco();
        }
        if(!am2.isSpeakerphoneOn()){
            speakerPhoneWasOn = false;
            am2.setSpeakerphoneOn(true);
        }
        myHash.put(TextToSpeech.Engine.KEY_PARAM_STREAM,
                String.valueOf(AudioManager.STREAM_VOICE_CALL));
        am2.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL,
                AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

    }
    else{
        am2.requestAudioFocus(null, AudioManager.STREAM_MUSIC,
        AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
        myHash.put(TextToSpeech.Engine.KEY_PARAM_STREAM,
                String.valueOf(AudioManager.STREAM_MUSIC));
    }

    new CountDownTimer(SMS_DELAY, SMS_DELAY/2) {

        @Override
        public void onFinish() {
            try {
                mTts.speak(str, TextToSpeech.QUEUE_ADD,
                        myHash);
            } catch (Exception e) {
                Toast.makeText(application,
                        R.string.TTSNotReady,
                        Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }

        }

        @Override
        public void onTick(long arg0) {

        }

    }.start();
}

现在我遇到了让流在完成后恢复的问题.阅读 TTS 一切正常.它将暂停任何音乐,播放 TTS,然后恢复音乐正常.但是,当我稍后退出应用程序时,媒体流现在通过手机听筒播放,直到我重新启动.我在这里发布了这个问题:使用 AudioManager 后音频流留在听筒上

Now I just have a problem getting the stream to revert back when done. It all works fine to read TTS. It will pause any music, play the TTS, and then resume music fine. However, when I exit the app later the stream for media now plays through the phone earpiece until I reboot. I posted that question here: Audio stream stays on earpiece after using AudioManager

您可以在此处查看我的整个项目:http://code.google.com/p/a2dpvolume/

You can see my whole project here: http://code.google.com/p/a2dpvolume/

这篇关于TTS 输出总是转到 A2DP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆