Chirag Jain
Chirag Jain

Reputation: 628

TextToSpeech Accent Change

I am using below library for TextToSpeech functionality to speak something -

'net.gotev:speech:1.3.1'

Now I need to change its accent for all country as US English I tried -

Speech.getInstance().setLocale(Locale.US);

but it is not working, please guide me.

With the help of below code I am trying to let it speak a word -

Speech.getInstance().say("Hello", new TextToSpeechCallback() {

                @Override
                public void onStart() {

                }

                @Override
                public void onCompleted() {

                }

                @Override
                public void onError() {

                }
            });

Now it actually speaks in locale based English accent for example - if it is run by Russian user then due to its locale it speaks this English in Russian accent but I want that it should be spoken in US ENGLISH accent rather than its locale based accent

Upvotes: 2

Views: 228

Answers (1)

Nerdy Bunz
Nerdy Bunz

Reputation: 7437

After looking at the code of that library, I think you would be much better off just working with the standard Android TextToSpeech object.

Using the normal TextToSpeech, doing what you are trying to do could be as simple as:

TextToSpeech tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int i) {
                tts.setLanguage(Locale.US);
                tts.speak("Hello", TextToSpeech.QUEUE_FLUSH, null);
            }
        });

PROBLEMS I SEE WITH THAT LIBRARY:

  • It does not use it's own embedded engine, and instead simply wraps a standard Android TextToSpeech object without knowing what type of engine is on the device!
  • It is using a Singleton Pattern, which, in the case of certain speech engines like Google, is prone to memory leaks.
  • And this problem relates to your question: It does nothing meaningful to check or respond to the initialization of it's internal TextToSpeech object. This means that when it attempts to set the default Locale on its internal TTS object, it actually does nothing... but the error is invisible because the TTS does this by default, anyway. But, when you try to manually set the Locale, the same thing happens (nothing), because the TTS object is not yet initialized.

Upvotes: 2

Related Questions