android.speech.tts.Voice Java Examples

The following examples show how to use android.speech.tts.Voice. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SaiyTextToSpeech.java    From Saiy-PS with GNU Affero General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private SaiyVoice getEngineDefaultSaiyVoice() {

    final Voice voice = getDefaultVoice();

    if (voice != null) {
        final SaiyVoice saiyVoice = new SaiyVoice(voice);
        saiyVoice.setEngine(getInitialisedEngine());
        saiyVoice.setGender(saiyVoice.getName());

        if (DEBUG) {
            MyLog.i(CLS_NAME, "getEngineDefaultSaiyVoice: setting Gender: " + saiyVoice.getGender().name());
        }

        return saiyVoice;
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "getEngineDefaultSaiyVoice: voice null");
        }
        return null;
    }
}
 
Example #2
Source File: SaiyTextToSpeech.java    From Saiy-PS with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Set<Voice> getVoices() {
    final long then = System.nanoTime();

    if (defaultVoiceSet == null || defaultVoiceSet.isEmpty()) {
        defaultVoiceSet = super.getVoices();
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "getVoices: already prepared");
        }
    }

    if (DEBUG) {
        MyLog.getElapsed("getVoices", then);
    }

    return defaultVoiceSet;
}
 
Example #3
Source File: SaiyTextToSpeech.java    From Saiy-PS with GNU Affero General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Set<SaiyVoice> getSaiyVoices() {
    final long then = System.nanoTime();
    final Set<Voice> voiceSet = getVoices();

    if (saiyVoiceSet == null || saiyVoiceSet.size() != voiceSet.size()) {
        saiyVoiceSet = SaiyVoice.getSaiyVoices(voiceSet, getInitialisedEngine());
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "getSaiyVoices: already prepared");
        }
    }

    if (DEBUG) {
        MyLog.getElapsed("getSaiyVoices", then);
    }
    return saiyVoiceSet;
}
 
Example #4
Source File: NaviVoice.java    From PocketMaps with MIT License 6 votes vote down vote up
public ArrayList<String> getVoiceListCompat()
{
  if (!ttsReady) { return null; }
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
  {
    HashSet<Voice> allVoices = new HashSet<Voice>();
    Set<Voice> curVoices = getVoiceListGreater21(wantedLang);
    log("Found " + curVoices.size() + " voices for " + wantedLang);
    if (curVoices != null) { allVoices.addAll(curVoices); }
    curVoices = getVoiceListGreater21(fallbackLang);
    log("Found " + curVoices.size() + " voices for " + fallbackLang);
    if (curVoices != null) { allVoices.addAll(curVoices); }
    ArrayList<String> curList = new ArrayList<String>();
    for (Voice v : allVoices)
    {
      curList.add(v.getLocale() + ":" + v.getName());
    }
    return curList;
  }
  else
  {
    return null;
  }
}
 
Example #5
Source File: NaviVoice.java    From PocketMaps with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Voice searchWantedVoiceGreater21(Locale selLang)
{
  Set<Voice> curVoices = getVoiceListGreater21(selLang);
  if (curVoices.size() == 0) { return null; }
  if (Variable.getVariable().getTtsWantedVoice() != null)
  {
    for (Voice v : curVoices)
    {
      if (v.getName().equals(Variable.getVariable().getTtsWantedVoice().split(":")[1]))
      {
          return v;
      }
    }
  }
  return curVoices.iterator().next();
}
 
Example #6
Source File: SaiyTextToSpeech.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SaiyVoice getBoundSaiyVoice() {

    final Voice voice = getVoice();

    if (voice != null) {
        final SaiyVoice saiyVoice = new SaiyVoice(voice);
        saiyVoice.setEngine(getInitialisedEngine());
        saiyVoice.setGender(saiyVoice.getName());
        return saiyVoice;
    } else {
        return null;
    }
}
 
Example #7
Source File: NaviVoice.java    From PocketMaps with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Set<Voice> getVoiceListGreater21(Locale lang)
{
  if (!ttsReady) { return null; }
  Set<Voice> allV = tts.getVoices();
  if (allV==null) { return null; }
  Set<Voice> selV = new HashSet<>();
  for (Voice curV : allV)
  {
      if (curV.getLocale().getISO3Language().equals(lang.getISO3Language())) { selV.add(curV); }
  }
  return selV;
}
 
Example #8
Source File: SpeechCachePrepare.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
public Voice getVoice() {
    return voice;
}
 
Example #9
Source File: SpeechCachePrepare.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setVoice(@NonNull final Voice voice) {
    this.voice = voice;
}
 
Example #10
Source File: SaiyVoice.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
public SaiyVoice(@NonNull final Voice voice) {
    super(voice.getName(), voice.getLocale(), voice.getQuality(), voice.getLatency(), voice.isNetworkConnectionRequired(),
            voice.getFeatures());
}
 
Example #11
Source File: SaiyVoice.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public int compare(final Voice v1, final Voice v2) {
    return v1.getLocale().toString().compareTo(v2.getLocale().toString());
}
 
Example #12
Source File: SaiyTextToSpeech.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Voice getDefaultVoice() {
    return super.getDefaultVoice();
}
 
Example #13
Source File: SaiyTextToSpeech.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Voice getVoice() {
    return super.getVoice();
}
 
Example #14
Source File: SaiyTextToSpeech.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public int setVoice(final Voice voice) {
    return super.setVoice(voice);
}
 
Example #15
Source File: LanguageMenuProcessor.java    From talkback with Apache License 2.0 4 votes vote down vote up
/**
 * This method returns null if Accessibility service is null, if its the lock screen or if the
 * number of languages installed on the device is not more than 1.
 */
public static HashMap<Locale, String> getInstalledLanguages(TalkBackService service) {
  if (service == null) {
    return null;
  }
  // We do not want to show languages menu if the user is on the lock screen.
  if (ScreenMonitor.isDeviceLocked(service)) {
    return null;
  }

  HashMap<Locale, String> languagesAvailable = new HashMap<Locale, String>();

  languagesAvailable.put(null, service.getString(R.string.reset_user_language_preference));

  FailoverTextToSpeech mTts = service.getSpeechController().getFailoverTts();
  Set<Voice> voices;
  try {
    voices = mTts.getEngineInstance().getVoices();
  } catch (Exception e) {
    LogUtils.e(TAG, "TTS client crashed while generating language menu items");
    e.printStackTrace();
    return null;
  }
  if (voices == null) {
    return null;
  }

  for (Voice voice : voices) {
    Set<String> features = voice.getFeatures();
    // Filtering the installed voices to add to the menu
    if ((features != null)
        && !features.contains(TextToSpeech.Engine.KEY_FEATURE_NOT_INSTALLED)
        && !voice.isNetworkConnectionRequired()) {

      String country = voice.getLocale().getDisplayCountry();
      if (!TextUtils.isEmpty(country)) {
        String menuItem =
            service.getString(
                R.string.template_language_options_menu_item,
                voice.getLocale().getDisplayLanguage(),
                voice.getLocale().getDisplayCountry());
        languagesAvailable.put(voice.getLocale(), menuItem);
      } else {
        languagesAvailable.put(voice.getLocale(), voice.getLocale().getDisplayLanguage());
      }
    }
  }
  // Do not populate the menu if there is just one language installed.
  // In the language menu, we have one default menu item labelled as "Reset". We want to ignore
  // that item while deciding if we want to populate the menu. The menu would be populated only if
  // we have 3 or more items in the list (including Reset).
  if (languagesAvailable.size() <= 2) {
    return null;
  }
  return languagesAvailable;
}