• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Implementing Text to speech

letaps24

Lurker
Hello everyone, for my senior project i am designing my first android app. I have got the app to run successfully so far, however, one suggestion is to add text to speech, so when users use my app, they can listen to the description of the site, rather than having to read all the text. I have look at tutorials, and tried it in my code, however this is my first time doing this. Any help will be greatly appreciated. I will upload a sample of what I am working on.

Code:
    public class SiteDescriptionActivity extends AppCompatActivity {

        private Toolbar toolbar;
        private CollapsingToolbarLayout collapsingToolbar;
        private ImageView topImage;
        private TextView descriptionView, nextTitleTV, nextTextTV;
        private CardView nextCard;
        TextToSpeech t1;
        EditText ed1;
 

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_site_description);
            ed1=(EditText)findViewById(R.id.exidText);
 
            t1 = new TextToSpeech(getApplicationContext(), new    TextToSpeech.OnInitListener(){
                public void onInit(int status){
                    if(status != TextToSpeech.ERROR){
                        t1.setLanguage(Locale.UK);
                    }
                }
            }

            topImage = (ImageView)      findViewById(R.id.site_details_image);
            toolbar = (Toolbar) findViewById(R.id.site_details_toolbar);
            collapsingToolbar = (CollapsingToolbarLayout)  findViewById(R.id.recipe_details_collapsing_toolbar);
            descriptionView = (TextView)  findViewById(R.id.site_details_description);
            nextTitleTV = (TextView) findViewById(R.id.site_details_next_title);
            nextTextTV = (TextView) findViewById(R.id.site_details_next);

            int id = (int) getIntent().getExtras().getLong("siteID");
            String name = getIntent().getExtras().getString("siteName");

            setTitle(name);

            setSupportActionBar(toolbar);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);

            // Change satus bar color when collapsing
            collapsingToolbar.setStatusBarScrimColor(getResources().getColor(R.color.colorPrimaryDark));
            collapsingToolbar.setTitle(name);

            int drawable=R.drawable.picture_placeholder;
            String description="";
            String nextTitle = "";
            String nextText = "";

            switch (id) {
                case 1:
                    drawable = R.drawable.lyceum;
                    description = getString(R.string.lyceum_description);
                    String toSpeak = ed1.getText().toString();
                    nextTitle = getString(R.string.lyceum_next_title);
                    nextText = getString(R.string.lyceum_next);
                    break;
 
Last edited:
@LV426, I just wanted to make sure the way i did it is correct, and when i instantiated String toSpeak, it will read the proper description.
 
Back
Top Bottom