Android Studio 中没有文本字段和按钮的文本到语音 [英] Text To Speech without textfield and button in Android Studio

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

问题描述

因此,我想在不使用 Android Studio 中的文本字段和按钮的情况下创建文本到语音.例如,当我打开应用程序时,它会说欢迎使用我的应用程序"而没有文本字段或任何按钮.我怎样才能做到这一点?需要你的帮助.

So, I want to create a text to speech without the use of textfield and button in Android Studio. For example when I open the app it will say "WELCOME TO MY APP" without text field or any button. How can I do that? Need your help.

推荐答案

只需在 onCreate() 中添加:

Just add this in your onCreate():

myTTS = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if (status != TextToSpeech.ERROR) {
                    // replace this Locale with whatever you want                    
                    Locale localeToUse = new Locale("en","US");
                    myTTS.setLanguage(localeToUse);
                    myTTS.speak("Hi, Welcome to my app!", TextToSpeech.QUEUE_FLUSH, null);
                }
            }
        });

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

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