eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GetSampleText.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (C) 2011 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.googlecode.eyesfree.espeak;
  17. import android.app.Activity;
  18. import android.content.Intent;
  19. import android.content.res.Configuration;
  20. import android.content.res.Resources;
  21. import android.content.res.Resources.NotFoundException;
  22. import android.os.Bundle;
  23. import android.speech.tts.TextToSpeech;
  24. import android.util.DisplayMetrics;
  25. import android.util.Log;
  26. import java.util.Locale;
  27. /*
  28. * Returns the sample text string for the language requested
  29. */
  30. public class GetSampleText extends Activity {
  31. private static final String TAG = GetSampleText.class.getSimpleName();
  32. @Override
  33. protected void onCreate(Bundle savedInstanceState) {
  34. super.onCreate(savedInstanceState);
  35. final Locale locale = getLocaleFromIntent(getIntent());
  36. final Resources res = getResourcesForLocale(this, locale);
  37. String text = null;
  38. try {
  39. text = res.getString(R.string.sample_text, locale.getDisplayName(locale));
  40. } catch (NotFoundException e) {
  41. e.printStackTrace();
  42. }
  43. final String language = (locale == null) ? "eng" : locale.getISO3Language();
  44. if (text != null) {
  45. // Do nothing.
  46. } else if (language.equals("afr")) {
  47. text = getString(R.string.afr);
  48. } else if (language.equals("bos")) {
  49. text = getString(R.string.bos);
  50. } else if (language.equals("zho")) {
  51. text = getString(R.string.zho);
  52. } else if (language.equals("hrv")) {
  53. text = getString(R.string.hrv);
  54. } else if (language.equals("ces")) {
  55. text = getString(R.string.ces);
  56. } else if (language.equals("nld")) {
  57. text = getString(R.string.nld);
  58. } else if (language.equals("eng")) {
  59. text = getString(R.string.eng);
  60. } else if (language.equals("epo")) {
  61. text = getString(R.string.epo);
  62. } else if (language.equals("fin")) {
  63. text = getString(R.string.fin);
  64. } else if (language.equals("fra")) {
  65. text = getString(R.string.fra);
  66. } else if (language.equals("deu")) {
  67. text = getString(R.string.deu);
  68. } else if (language.equals("ell")) {
  69. text = getString(R.string.ell);
  70. } else if (language.equals("hin")) {
  71. text = getString(R.string.hin);
  72. } else if (language.equals("hun")) {
  73. text = getString(R.string.hun);
  74. } else if (language.equals("isl")) {
  75. text = getString(R.string.isl);
  76. } else if (language.equals("ind")) {
  77. text = getString(R.string.ind);
  78. } else if (language.equals("ita")) {
  79. text = getString(R.string.ita);
  80. } else if (language.equals("kur")) {
  81. text = getString(R.string.kur);
  82. } else if (language.equals("lat")) {
  83. text = getString(R.string.lat);
  84. } else if (language.equals("mkd")) {
  85. text = getString(R.string.mkd);
  86. } else if (language.equals("nor")) {
  87. text = getString(R.string.nor);
  88. } else if (language.equals("pol")) {
  89. text = getString(R.string.pol);
  90. } else if (language.equals("por")) {
  91. text = getString(R.string.por);
  92. } else if (language.equals("ron")) {
  93. text = getString(R.string.ron);
  94. } else if (language.equals("rus")) {
  95. text = getString(R.string.rus);
  96. } else if (language.equals("srp")) {
  97. text = getString(R.string.srp);
  98. } else if (language.equals("slk")) {
  99. text = getString(R.string.slk);
  100. } else if (language.equals("spa")) {
  101. text = getString(R.string.spa);
  102. } else if (language.equals("swa")) {
  103. text = getString(R.string.swa);
  104. } else if (language.equals("swe")) {
  105. text = getString(R.string.swe);
  106. } else if (language.equals("tam")) {
  107. text = getString(R.string.tam);
  108. } else if (language.equals("tur")) {
  109. text = getString(R.string.tur);
  110. } else if (language.equals("vie")) {
  111. text = getString(R.string.vie);
  112. } else if (language.equals("cym")) {
  113. text = getString(R.string.cym);
  114. } else {
  115. Log.e(TAG, "Missing sample text for " + language);
  116. text = getString(R.string.eng);
  117. }
  118. final int result = TextToSpeech.LANG_AVAILABLE;
  119. final Intent returnData = new Intent();
  120. returnData.putExtra("sampleText", text);
  121. setResult(result, returnData);
  122. finish();
  123. }
  124. private static Locale getLocaleFromIntent(Intent intent) {
  125. if (intent != null) {
  126. final String language = intent.getStringExtra("language");
  127. if (language != null) {
  128. return new Locale(language);
  129. }
  130. }
  131. return Locale.getDefault();
  132. }
  133. private static Resources getResourcesForLocale(Activity activity, Locale locale) {
  134. final Configuration config = activity.getResources().getConfiguration();
  135. config.locale = locale;
  136. final DisplayMetrics metrics = new DisplayMetrics();
  137. activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
  138. return new Resources(activity.getAssets(), metrics, config);
  139. }
  140. }