2

I am trying to create an app which verbally speaks a given text string via TextToSpeech. I was previously looking for a way to select a given language from a string. However, now I am trying to work out how I can install a language from the Google Play store if it is not already on the device.

E.G. If Russian is not installed, and I provide the Russian country code (which I have), it needs to check and install the language pack if needed. The language can change at any time, by user intervention.

This something I am completely confused on how it works.

I did find this link: http://android-developers.blogspot.com.au/2009/09/introduction-to-text-to-speech-in.html

I have the basic structure of the app TextToSpeech build...as you can see below. I have not put in the code for changing the language within the app, nor have i used any variables for the language. I have left it static for simplicity in this code I have shown. The below code is rebuilt when the language is changed.

t1=new TextToSpeech(context, new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if(status != TextToSpeech.ERROR) {
                    User u = new User(context);
                    t1.setLanguage(Locale.US); // TODO: 22/09/2015 FIX LOCALE FOR TextToSpeech
                    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        /** creates a high quality voice when on Lollipop or better android version */
                        Voice voice = new Voice("voice", Locale.US, Voice.QUALITY_VERY_HIGH, Voice.LATENCY_NORMAL, false, null);
                        t1.setVoice(voice);
                    }
                }
            }
        });

        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TextView tv = (TextView) v.findViewById(R.id.to_language);
                String toSpeak = tv.getText().toString();
                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null, v.getTag().toString());

                    t1.setOnUtteranceProgressListener(new UtteranceProgressListener() {
                        @Override
                        public void onStart(String utteranceId) {
                           //tv.setTextColor(Color.parseColor("#57d801"));
                        }

                        @Override
                        public void onDone(String utteranceId) {
                            //tv.setTextColor(Color.parseColor("#FFFFFF"));
                        }

                        @Override
                        public void onError(String utteranceId) {

                        }
                    });
                } else {
                    t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
                    t1.setOnUtteranceCompletedListener(new TextToSpeech.OnUtteranceCompletedListener() {
                        @Override
                        public void onUtteranceCompleted(String utteranceId) {

                        }
                    });
                }
            }
        });

I do not want someone to just do it for me. I was hoping that someone might be able to explain it better to me then the site above, more in reference to my problem. So that I can understand and implement a solution to solve my problem.

This is eventually going to have to work offline without the internet (with the exception of downloading additional languages).

Travis Knight
  • 301
  • 1
  • 4
  • 18

0 Answers0