listing & selecting tts voices

pacoMx

Member
Licensed User
Longtime User
hi, I would like to be able to select voice to be used for tts based on the ones I have currently installed.

Is there a way to list them within the tts library?

Thanks.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code will fill a List with all the supported locales:
B4X:
Sub Process_Globals
   Dim AllLocales() As String
   AllLocales = Array As String("ar", "ar_EG", "bg", "bg_BG", "ca", "ca_ES", "cs", "cs_CZ", "da", _
      "da_DK", "de", "de_AT", "de_BE", "de_CH", "de_DE", "de_LI", _
      "de_LU", "el", "el_CY", "el_GR", "en", "en_AU", "en_BE", "en_BW", _
      "en_BZ", "en_CA", "en_GB", "en_HK", "en_IE", "en_IN", "en_JM", _
      "en_MH", "en_MT", "en_NA", "en_NZ", "en_PH", "en_PK", "en_RH", _
      "en_SG", "en_TT", "en_US", "en_US_POSIX, en_VI", "en_ZA", _
      "en_ZW", "es", "es_AR", "es_BO", "es_CL", "es_CO", "es_CR", _
      "es_DO", "es_EC", "es_ES", "es_GT", "es_HN", "es_MX", "es_NI", _
      "es_PA", "es_PE", "es_PR", "es_PY", "es_SV", "es_US", "es_UY", _
      "es_VE", "et", "et_EE", "eu", "eu_ES", "fa", "fa_IR", "fi", "fi_FI", "fr", "fr_BE", _ 
      "fr_CA", "fr_CH", "fr_FR", "fr_LU", "fr_MC", "gl", "gl_ES", "hr", "hr_HR", "hu", "hu_HU", _
      "in", "in_ID,is", "is_IS", "it", "it_CH", "it_IT", "iw", "iw_IL", "ja", "ja_JP", "kk", "kk_KZ", _
      "ko", "ko_KR", "lt", "lt_LT", "lv", "lv_LV", "mk", "mk_MK", "ms", "ms_BN", "ms_MY", "nl", "nl_BE", "nl_NL", "no", _ 
      "no_NO", "no_NO_NY", "pl", "pl_PL", "pt", "pt_BR", "pt_PT", "ro", "ro_RO", "ru", "ru_RU", "ru_UA", "sh", "sh_BA", _ 
      "sh_CS", "sh_YU", "sk", "sk_SK", "sl", "sl_SI", "sq", "sq_AL", "sr", "sr_BA", "sr_ME", "sr_RS", "sv", "sv_FI", "sv_SE", _ 
      "th", "th_TH", "tr", "tr_TR", "uk", "uk_UA", "vi", "vi_VN", "zh", "zh_CN", "zh_HK", "zh_HANS_SG", "zh_HANT_MO", "zh_MO", "zh_TW")
      Dim tts1 As TTS
End Sub

Sub Globals

End Sub
Sub Activity_Create (FirstTime As Boolean)
   If FirstTime Then
      tts1.Initialize("tts1")
   End If
End Sub

Sub TTS1_Ready (Success As Boolean)
   If Success Then
      Dim listOfSupported As List
      listOfSupported.Initialize
      For i = 0 To AllLocales.Length - 1
         Dim s() As String
         s = Regex.Split("_", AllLocales(i))
         If s.Length = 1 Then
             If tts1.SetLanguage(s(0), "") = True Then listOfSupported.Add(AllLocales(i))
         Else
            If tts1.SetLanguage(s(0), s(1)) = True Then listOfSupported.Add(AllLocales(i))
         End If
      Next
      For i = 0 To listOfSupported.Size - 1
         Log(listOfSupported.Get(i)) 'print to the log
      Next
   End If
End Sub
 
Upvote 0

pacoMx

Member
Licensed User
Longtime User
Thank you Erel.

So for using es_MX I would use

B4X:
    If tts1.SetLanguage("es", "MX") = False Then 'P
            ToastMessageShow("Language nor installled", True)
                Return
       End If

right?

Thanks.
 
Upvote 0

wantlin

Member
Licensed User
Longtime User
Hi Erel

I use tts1.SetLanguage("zh", "TW"), The command is for Taiwanese Chinese.
The TTS1_Speak need the English or Chinese ?

Thank you
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
Can the locale array in this example be used with VR language as well ?
Is there a way to test the suported voices for voice recognition ?
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
Related to post#1: i have the problem, to get more positive results as languages on the device are available. I tried different devices; the problem is currently with danish, finnish, catalan and czech languages. There is not speeaker installed and i get really ugly results, when the device tries to speak. Does anybody know why...
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
@Erel
a simple fix to your code.
B4X:
"en_US_POSIX, en_VI", to "en_US_POSIX", "en_VI"
AND
B4X:
"in_ID,is", TO "in_ID","is"
on post #2
 
Last edited:
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
I'm using your example (Post #2), all i can get are a few languages but totally synthesized.
I've been using French, Chinese (simplified), Viet Namese, Spanish (MX), Italian, German, Russian and a bunch more, now none work except English.
any ideas or suggestions? (appreciated)
Thanks,
Rusty
 
Upvote 0
Top