淡入淡出音乐,一边讲文本 [英] fade in and out music while speaking a text

查看:150
本文介绍了淡入淡出音乐,一边讲文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,它使用TTS(文本到语音)的API。一切都工作的很好,但现在我想淡入/淡出甚至停止音乐(如果用户正在播放音乐的音乐播放器prebuilt),当应用程序讲的文本。现在,我认为音乐和TTS信息播放在同一个流(音乐),它可以是很难理解的语音信息。

I have an Android application that makes use of TTS (Text to speech) API. Everything is working perfectly, but now i want to fade in/out or even stop music (in case user is playing music with prebuilt Music Player), when application speaks a text. Right now, i think both music and TTS messages are played on the same stream (MUSIC), and it can be difficult to understand the voice messages.

我已经试过玩文字在不同的数据流,如AudioManager.STREAM_NOTIFICATIONS。它确实停止音乐,但是不回来的时候文本是口头的,所以我并没有达到目的。有没有发现任何东西,所以我希望有人能帮助在这里。谢谢!

I've tried to play the text on a different stream, like AudioManager.STREAM_NOTIFICATIONS. It does stop the music, but doesn't come back when the text is spoken, so i didn't achieve the goal. Haven't found anything yet, so i hope someone can help here. Thanks!

推荐答案

我终于得到了一些正在工作。并非十全十美。一个比较肮脏的把戏。万一它可以帮助别人:

I finally got something that is working. Not perfect though. A quite dirty trick. Just in case it can help to someone:

这是固定在API 8 AudioManager的requestAudioFocus和abandomAudioFocus方法。

This is fixed on API 8 with requestAudioFocus and abandomAudioFocus methods of AudioManager.

但对于前版本,你可以试试这个。通过不同的河道播放TTS,让我们说STREAM_NOTIFICATIONS。然后你只需要返回音频焦点STREAM_MUSIC。你怎么能做到这一点?发送沉默字符串(),以TTS但这次通过STREAM_MUSIC。效果会:音乐停止时,你的TTS消息被讲,最后你的音乐又回来了语音警报后。不是很好或某事感到骄傲的,但是......如果有人知道的另一种方式,我将AP preciate它

But for former versions, you can try this. Play TTS through a different stream channel, let's say STREAM_NOTIFICATIONS. Then you just need to return audio focus to STREAM_MUSIC. How can you achieve that?. Sending a silence string (" ") to TTS but this time through STREAM_MUSIC. The effect will be: music is stopped, your TTS message gets spoken, and finally your music is back after the voice alert. Not nice or something to feel proud of, but... if someone knows of a different way, i will appreciate it

这篇关于淡入淡出音乐,一边讲文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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