Android Tutorial User selection of a voice for Text To Speech.

I've just added a speech to text facility to my note taking app using

and text to speech using the internal TTS library. The default voice is a female but I wanted a different voice so I started messing with JavaObject and native code but eventually stumbled across the fact that it is possible for the user to select the default speech to text text to speech voice through Settings! I didn't know this so maybe you don't either.

Settings -> System -> Languages and input -> Text-to-speech output -> Cog icon by 'Preferred engine' -> Install voice data

You now get a list of lots of languages. The one for your locale should already be loaded so tap on it and you are offered a choice of voices. Selecting one will play a short example of the voice. For English(United Kingdom) there is a choice of six, three very similarly accented females and three very similarly accented males.
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
I wonder if there is some standardized intent (that works on all devices and OS versions) that will jump the user right to that setting instead of them having to navigate manually to it?
 

drgottjr

Expert
Licensed User
Longtime User
this should take you there:

B4X:
    Dim i As Intent
    i.Initialize("com.android.settings.TTS_SETTINGS", "")
    StartActivity(i)      ' or StartActivityForResult, depending

and don't forget my monographs on the virtures of google's voice recognition versus
vosk's (and coupled with translation and speech output). i'm still trying to have my app
installed on all tesla models to facilitate communication with highway police when you
run over someone in a foreign country.

https://www.b4x.com/android/forum/threads/143453/#content

https://www.b4x.com/android/forum/threads/143639/#content
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Apparently this should go directly to the install voice data activity but I am failing dismally to get it to work using a B4A Intent. Any takers?
Java:
setting.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          Intent  intent = new Intent();
          intent.setComponent(new ComponentName("com.google.android.tts","com.google.android.tts.local.voicepack.ui.VoiceDataInstallActivity"));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    });
 

hatzisn

Expert
Licensed User
Longtime User
Or use my TTSFunctions module. See my contributions in my signature.
 

agraham

Expert
Licensed User
Longtime User
Nice module, but I'd rather run that install voice Activity as it already contains all the logic to download languages and select a voice, including letting you hear it before you close that activity.
The name of the activity is
"com.google.android.apps.speech.tts.googletts.local.voicepak.ui.VoiceDataInstallActivity"
I can invoke it using the 'Activity Launcher' app from the store but I haven't managed to invoke it either directly or with an Intent or by inline Java :(
 

hatzisn

Expert
Licensed User
Longtime User
Nice module, but I'd rather run that install voice Activity as it already contains all the logic to download languages and select a voice, including letting you hear it before you close that activity.
The name of the activity is
"com.google.android.apps.speech.tts.googletts.local.voicepak.ui.VoiceDataInstallActivity"
I can invoke it using the 'Activity Launcher' app from the store but I haven't managed to invoke it either directly or with an Intent or by inline Java :(

Just out of curiosity... Why is the voice data install activity better than the SetVoice function combined with the GetVoices function from the module? You can get the voices (of current locale or all voices), add them in a "combobox" and have the user select a voice inside your application. This can be done by setting a voice according to the selected in a combobox value and speak a certain sentence on ValueChanged of the combobox. If the user likes this voice he/she clicks ok and you keep in saved data the selected voice's values setting it dynamically when the app starts or in the background with a Receiver. Then your app will use the voice the user selected not forcing the entire device using this voice.
 

hatzisn

Expert
Licensed User
Longtime User
It's just easier as the functionality exists in that activity without me reinventing the wheel and as the only user is me I don't give a toss whether it affects the whole device or not as this is the only text to speech app I have on the device.

I am not exactly ChatGPT to evaluate this but from the context I suppose I kind of got into your nurves. Honestly, I ask you to forgive me if this is the case... It was just a curiosity question...:)
 
Last edited:
Top