mike nelson
mike nelson

Reputation: 22166

What do the Android Voice names / codes mean?

I am calling the Voice.getName() method like so:

Set<Voice> voices = tts.getVoices();
String name = voice.getName();

This returns code names rather than friendly display names. What I want is a display name, but there doesn't seem to be any way to get this.

Is it possible to translate the codes into something meaningful to create user friendly names? And to eliminate duplicates? A lot sound similar - but just a little bit different.

These are some codes returned for English UK:

en-GB-language
en-gb-x-rjs-local
en-gb-x-rjs-network
en-gb-x-fis-local
en-gb-x-fis-network
en-gb-x-fis#female_1-local
en-gb-x-rjs#female_1-local
en-gb-x-rjs#female_2-local
en-gb-x-fis#female_2-local
en-gb-x-rjs#male_1-local

My thoughts so far:

Does anyone have a better understanding of these?

Upvotes: 16

Views: 2378

Answers (2)

Dananjaya
Dananjaya

Reputation: 669

In my flutter development, I used following package to get human readable name by passing 'locale'. Maybe you can check out that package code and rebuild your own to make friendly display names.

TTS package: https://pub.dev/packages/flutter_tts

Locale names extension package: https://pub.dev/packages/locale_names

Dart code:

String getHumanVoiceName(String locale) {
  String name = locale;
  List subs = locale.split("-");

  Locale? _locale;
  if (subs.length == 1) {
    _locale = Locale.fromSubtags(languageCode: subs[0]);
  } else if (subs.length == 2) {
    _locale = Locale.fromSubtags(languageCode: subs[0], countryCode: subs[1]);
  } else if (subs.length == 3) {
    _locale = Locale.fromSubtags(
        languageCode: subs[0], scriptCode: subs[1], countryCode: subs[2]);
  }
  name =
      "${_locale!.nativeDisplayCountry} (${_locale!.defaultDisplayLanguage})";

  return name;
}

Upvotes: 0

joe
joe

Reputation: 5612

This may or may not be helpful, but for those of you not working directly with Android, and thus without access to an API that lists the voice codes, I've just found this URL on a forum thread which seems to list the URLs of the android TTS voices:

https://dl.google.com/dl/android/tts/v2/voices-list-r1.proto

Reading that as text (utf-8) gives some decoding errors, but it's enough to extract the codes:

en-GBGhttps://dl.google.com/dl/android/tts/v2/en-gb-x-fis-phone-hmm-r2.zvoice ����dBfemaleJen-gb-x-fis-phone-hmmP�X�`hen-GB #1x�$�
en-GBJhttps://dl.google.com/dl/android/tts/v2/en-gb-x-fis-diphone-usel-r2.zvoice ؾ0���dBfemaleJen-gb-x-fis-diphone-uselP�X�`hen-GB #1x��
en-GBGhttps://dl.google.com/dl/android/tts/v2/en-gb-x-rjs-phone-hmm-r2.zvoice �0���dBmaleJen-gb-x-rjs-phone-hmmP�X�`hen-GB #2x��
en-GBJhttps://dl.google.com/dl/android/tts/v2/en-gb-x-rjs-diphone-usel-r2.zvoice ��0���dBmaleJen-gb-x-rjs-diphone-uselP�X�`hen-GB #2x���
en-USGhttps://dl.google.com/dl/android/tts/v2/en-us-x-sfg-phone-hmm-r2.zvoice �*0���dBfemaleJen-us-x-sfg-phone-hmmP�X�`hren-USx�6�
en-USJhttps://dl.google.com/dl/android/tts/v2/en-us-x-sfg-diphone-usel-r4.zvoice ��
   0���dBfemaleJen-us-x-sfg-diphone-uselP�X�`hren-USx���
de-DEGhttps://dl.google.com/dl/android/tts/v2/de-de-x-nfh-phone-hmm-r2.zvoice �"0���dBfemaleJde-de-x-nfh-phone-hmmP�X�`hrde-DEx�+�
pt-BRGhttps://dl.google.com/dl/android/tts/v2/pt-br-x-afs-phone-hmm-r2.zvoice ����dBfemaleJpt-br-x-afs-phone-hmmP�X�`hrpt-BRx�#�
es-ESGhttps://dl.google.com/dl/android/tts/v2/es-es-x-ana-phone-hmm-r2.zvoice �#0���dBfemaleJes-es-x-ana-phone-hmmP�X�`hres-ESx�.�
es-USGhttps://dl.google.com/dl/android/tts/v2/es-us-x-sfb-phone-hmm-r2.zvoice �*0���dBfemaleJes-us-x-sfb-phone-hmmP�X�`hres-USx�6�
fr-FRGhttps://dl.google.com/dl/android/tts/v2/fr-fr-x-vlf-phone-hmm-r2.zvoice �.0���dBfemaleJfr-fr-x-vlf-phone-hmmP�X�`hrfr-FRx�>�
it-ITGhttps://dl.google.com/dl/android/tts/v2/it-it-x-kda-phone-hmm-r2.zvoice �,0���dBfemaleJit-it-x-kda-phone-hmmP�X�`hrit-ITx�>�
ko-KRGhttps://dl.google.com/dl/android/tts/v2/ko-kr-x-ism-phone-hmm-r2.zvoice �00���dBfemaleJko-kr-x-ism-phone-hmmP�X�`hrko-KRx�:

I still don't know what the codes mean, but at least this gives me the mapping between the language codes and the fis, rjs, etc codes, so it's a start.

Upvotes: 1

Related Questions