Android中的文本到语音模式 [英] Text to speech pattern in Android

查看:52
本文介绍了Android中的文本到语音模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用中使用TextToSpeech.

I'm trying to use TextToSpeech in my app.

我将其写为绑定服务.当我需要在活动停止之前阅读文本时出现问题.它只说一半的文本,因为活动调用取消绑定并完成自身.

I wrote it as a bound service. Problem appears when I need to read text before activity stops. It says just half of text because activity calls unbind and finish itself.

如果我不想直接将文本写成活动性,将文本写成语音的更好的模式是什么?

What is better pattern to write Text to speech if I dont want write it direct into actvivity?

推荐答案

而不是仅绑定服务,而是使用 startService()启动您的服务,然后进行绑定.在 onUtteranceCompleted()中阅读文本后,调用 stopSelf().

Instead of just bind service, start your service using startService() and then bind. After reading the text in onUtteranceCompleted() call stopSelf().

这篇关于Android中的文本到语音模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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