Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7713489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:53:20+00:00 2026-06-01T01:53:20+00:00

I have a text to speech application where the user can select a language

  • 0

I have a text to speech application where the user can select a language and also select a male or female voice. The problem is that for each language there are different strings used to called the male and female voice but in my preference I only have two options (male and female).

<string-array name="Language">
    <item>English (US)</item>
    <item>English (UK)</item>
    <item>French (France)</item>
    <item>Spanish (Spain)</item>
    <item>Italian</item>
</string-array>

<string-array name="languageAlias">
    <item>"en-US"</item>
    <item>"en-GB"</item>
    <item>"fr-FR"</item>
    <item>"es-ES"</item>
    <item>"it-IT"</item>
</string-array>

<string-array name="Voice">
    <item>Male</item>
    <item>Female</item>
</string-array>

<string-array name="VoiceAlias">
    <item>"usenglishmale"</item>
    <item>"usenglishfemale"</item>
    <item>"ukenglishmale"</item>
    <item>"ukenglishfemale"</item>
    <item>"eurfrenchmale"</item>
    <item>"eurfrenchfemale"</item>
    <item>"eurspanishmale"</item>
    <item>"eurspanishfemale"</item>
    <item>"euritalianmale"</item>
    <item>"euritalianfemale"</item>        
</string-array>

I’m trying to find a way to only reference the relevant male and female voiceAlias depending on the language selected. Is it possible to do this here or do I have to write some code which changes the values of the voiceAlias array depending on the language selected?

Thanks in Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:53:22+00:00Added an answer on June 1, 2026 at 1:53 am

    Ok, you can accomplish this with two ListPreferences and an OnPreferenceChangeListener for each. First the XML:

    <ListPreference 
        android:key="language_preference"
        android:title="Language"
        android:entries="@array/Language"
        android:entryValues="@array/languageAlias"/>
    
    <ListPreference 
        android:key="gender_preference"
        android:title="Gender"
        android:entries="@array/Voice"
        android:entryValues="@array/VoiceData"/>
    

    Let’s make a new entry in res/values/array.xml:

    <string-array name="VoiceData">
        <item>0</item>
        <item>1</item>
    </string-array>
    

    And now in your extention of PreferenceActivity, we’re going to take the string values which persist in your SharedPreferences and from them create a completely new entry in the SharedPreferences which gets its value from “VoiceAlias”.

    SharedPreferences shareprefs = getPreferenceManager().getSharedPreferences();
    Resources resources = YourContext.getResources();
    
    private void makeVoiceData() {
        String languageData = shareprefs.getString("language_preference", "en-US");
        int genderData = Integer.parseInt(shareprefs.getString("gender_preference", "0"));
        String[] voiceAlias = resources.getStringArray(R.array.VoiceAlias);
    
        int a = 0
        String[] languageAlias = resources.getStringArray(R.array.languageAlias);
        for (a ; a < languageAlias.length ; a++) {
            if (languageAlias[a].equals(languageData)) {
                break;
            }
        }
    
        shareprefs.putString("VoiceAlias", voiceAlias[(2 * a) + genderData]);
    }
    
    ListPreference language_preference = getPreference("language_preference");
    ListPreference gender_preference = getPreference("gender_preference");
    
    language_preference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        public boolean onPreferenceChanged(Preference preference, Object newValue) {
            shareprefs.putString("language_preference", (String) newValue);
            makeVoiceData();
        }
    });
    
    gender_preference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        public boolean onPreferenceChanged(Preference preference, Object newValue) {
            shareprefs.putString("gender_preference", (String) newValue);
            makeVoiceData();
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android application that makes use of TTS (Text to speech) API.
I have an app that uses text to speech to inform the user every
i have an application of text to speech convertor and now want to prepare
I seek some insight in creating an application that converts text to speech in
I have this game, that contains a lot of text as speech. I would
I have successfully managed to get System.Speech.Synthesis to read English text in arbitrary voices
I have text within a paragraph tag that that fits snug on the bottom
I have text input boxes. There is validation for each of the boxes using
I have text I am displaying in SIlverlight that is coming from a CMS
I have text file with some stuff that i would like to put into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.