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 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2012-2013 Reece H. Dunn
  3. * Copyright (C) 2011 The Android Open Source Project
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package com.reecedunn.espeak;
  18. import android.annotation.SuppressLint;
  19. import android.app.Activity;
  20. import android.content.Intent;
  21. import android.os.Bundle;
  22. import android.speech.tts.TextToSpeech;
  23. import java.util.Locale;
  24. /*
  25. * Returns the sample text string for the language requested
  26. */
  27. @SuppressLint("NewApi")
  28. public class GetSampleText extends Activity {
  29. @Override
  30. protected void onCreate(Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. final Locale locale = getLocaleFromIntent(getIntent());
  33. final String text = SpeechSynthesis.getSampleText(getBaseContext(), locale);
  34. final int result = TextToSpeech.LANG_AVAILABLE;
  35. final Intent returnData = new Intent();
  36. returnData.putExtra(TextToSpeech.Engine.EXTRA_SAMPLE_TEXT, text);
  37. setResult(result, returnData);
  38. finish();
  39. }
  40. private static Locale getLocaleFromIntent(Intent intent) {
  41. if (intent != null) {
  42. final String language = intent.getStringExtra("language");
  43. if (language != null) {
  44. return new Locale(language);
  45. }
  46. }
  47. return Locale.getDefault();
  48. }
  49. }