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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.app.Activity;
  19. import android.content.Intent;
  20. import android.os.Bundle;
  21. import android.speech.tts.TextToSpeech;
  22. import java.util.Locale;
  23. /*
  24. * Returns the sample text string for the language requested
  25. */
  26. public class GetSampleText extends Activity {
  27. @Override
  28. protected void onCreate(Bundle savedInstanceState) {
  29. super.onCreate(savedInstanceState);
  30. final Locale locale = getLocaleFromIntent(getIntent());
  31. final String text = SpeechSynthesis.getSampleText(getBaseContext(), locale);
  32. final int result = TextToSpeech.LANG_AVAILABLE;
  33. final Intent returnData = new Intent();
  34. returnData.putExtra(TextToSpeech.Engine.EXTRA_SAMPLE_TEXT, text);
  35. setResult(result, returnData);
  36. finish();
  37. }
  38. private static Locale getLocaleFromIntent(Intent intent) {
  39. if (intent != null) {
  40. final String language = intent.getStringExtra("language");
  41. if (language != null) {
  42. return new Locale(language);
  43. }
  44. }
  45. return Locale.getDefault();
  46. }
  47. }