i want to use text to speech in my application, i find many example for using text to speech like this Android Text-To-Speech Application . i want to use text to speech from non activity class , for example i have class that genrate layout and return this layout to my main activity , ihave button on this layout and i want to when clicked on this button call text to speech. how can i use text to speech on non activity class ?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You can use a facade to achieve this.
Define an interface for example
TTSListener.java
:In your Main activity, implement the interface:
Then finally in your non-activity's class, you can invoke the TTS methods:
Create your Speech class as below:
As you noticed
Zillion.getContext()
had been used as replacement ofgetApplicationContext()
, to get the context, you need to create a class extends application, like below:and define the app in the manifest related to this class as: