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

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

问题描述

我的Andr​​oid教程的状态,我可以明确地告诉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?

推荐答案

我得到这个工作在大多数情况下,大多数的设备。下面是启动TTS上使用蓝牙SCO,而不是A2DP语音呼叫流的部分。

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,然后恢复音乐的罚款。然而,当我退出程序后,流媒体,现在通过手机听筒播放,直到我重新启动。我张贴的问题在这里:<一href="http://stackoverflow.com/questions/7290489/audio-stream-stays-on-earpiece-after-using-audiomanager">Audio流用后停留在听筒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://$c$c.google .COM / P / a2dpvolume /

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

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

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