Browse Source

Use API 21.

master
Reece H. Dunn 10 years ago
parent
commit
3d2308e285

+ 2
- 2
android/build.gradle View File



android { android {
buildToolsVersion '19.1' buildToolsVersion '19.1'
compileSdkVersion 19
compileSdkVersion 21


defaultConfig { defaultConfig {
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 19
targetSdkVersion 21
} }


sourceSets { sourceSets {

+ 22
- 22
android/eSpeakTests/src/com/reecedunn/espeak/test/TextToSpeechTest.java View File

{ {
assertThat(getEngine(), is(notNullValue())); assertThat(getEngine(), is(notNullValue()));


Locale initialLocale = getEngine().getLanguage();
Locale initialLocale = getLanguage(getEngine());
assertThat(getEngine().isLanguageAvailable(new Locale("cel")), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED)); assertThat(getEngine().isLanguageAvailable(new Locale("cel")), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(getEngine().getLanguage().getLanguage(), is(initialLocale.getLanguage()));
assertThat(getEngine().getLanguage().getCountry(), is(initialLocale.getCountry()));
assertThat(getEngine().getLanguage().getVariant(), is(initialLocale.getVariant()));
assertThat(getLanguage(getEngine()).getLanguage(), is(initialLocale.getLanguage()));
assertThat(getLanguage(getEngine()).getCountry(), is(initialLocale.getCountry()));
assertThat(getLanguage(getEngine()).getVariant(), is(initialLocale.getVariant()));
} }


public void testLanguages() public void testLanguages()
context = "iana1"; context = "iana1";
assertThat(getEngine().isLanguageAvailable(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE)); assertThat(getEngine().isLanguageAvailable(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().setLanguage(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE)); assertThat(getEngine().setLanguage(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(data.variant));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
assertThat(getLanguage(getEngine()).getVariant(), is(data.variant));


context = "iana2"; context = "iana2";
assertThat(getEngine().isLanguageAvailable(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE)); assertThat(getEngine().isLanguageAvailable(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().setLanguage(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE)); assertThat(getEngine().setLanguage(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(""));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
assertThat(getLanguage(getEngine()).getVariant(), is(""));


context = "iana3"; context = "iana3";
assertThat(getEngine().isLanguageAvailable(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE)); assertThat(getEngine().isLanguageAvailable(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().setLanguage(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE)); assertThat(getEngine().setLanguage(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(""));
assertThat(getEngine().getLanguage().getVariant(), is(""));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(""));
assertThat(getLanguage(getEngine()).getVariant(), is(""));


context = "java1"; context = "java1";
assertThat(getEngine().isLanguageAvailable(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE)); assertThat(getEngine().isLanguageAvailable(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().setLanguage(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE)); assertThat(getEngine().setLanguage(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(data.variant));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
assertThat(getLanguage(getEngine()).getVariant(), is(data.variant));


context = "java2"; context = "java2";
assertThat(getEngine().isLanguageAvailable(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE)); assertThat(getEngine().isLanguageAvailable(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().setLanguage(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE)); assertThat(getEngine().setLanguage(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(""));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
assertThat(getLanguage(getEngine()).getVariant(), is(""));


context = "java3"; context = "java3";
assertThat(getEngine().isLanguageAvailable(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE)); assertThat(getEngine().isLanguageAvailable(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().setLanguage(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE)); assertThat(getEngine().setLanguage(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(""));
assertThat(getEngine().getLanguage().getVariant(), is(""));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(""));
assertThat(getLanguage(getEngine()).getVariant(), is(""));
} }
catch (AssertionError e) catch (AssertionError e)
{ {

+ 16
- 0
android/eSpeakTests/src/com/reecedunn/espeak/test/TextToSpeechTestCase.java View File



package com.reecedunn.espeak.test; package com.reecedunn.espeak.test;


import android.os.Build;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener; import android.speech.tts.TextToSpeech.OnInitListener;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
{ {
return mEngine; return mEngine;
} }

@SuppressWarnings("deprecation")
public static Locale getLanguage(TextToSpeech engine) {
if (engine != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
android.speech.tts.Voice voice = engine.getVoice();
if (voice != null) {
return voice.getLocale();
}
} else {
return engine.getLanguage();
}
}
return null;
}
} }

+ 2
- 0
android/src/com/reecedunn/espeak/GetSampleText.java View File



package com.reecedunn.espeak; package com.reecedunn.espeak;


import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
/* /*
* Returns the sample text string for the language requested * Returns the sample text string for the language requested
*/ */
@SuppressLint("NewApi")
public class GetSampleText extends Activity { public class GetSampleText extends Activity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {

+ 25
- 7
android/src/com/reecedunn/espeak/eSpeakActivity.java View File



findViewById(R.id.speak).setOnClickListener(new View.OnClickListener() { findViewById(R.id.speak).setOnClickListener(new View.OnClickListener() {
@Override @Override
@SuppressWarnings("deprecation")
public void onClick(View v) { public void onClick(View v) {
mTts.speak(mText.getText().toString(), TextToSpeech.QUEUE_ADD, null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mTts.speak(mText.getText().toString(), TextToSpeech.QUEUE_ADD, null, null);
} else {
mTts.speak(mText.getText().toString(), TextToSpeech.QUEUE_ADD, null);
}
} }
}); });


mTts = new TextToSpeech(this, mInitListener); mTts = new TextToSpeech(this, mInitListener);
} }


@SuppressWarnings("deprecation")
private Locale getTtsLanguage() {
if (mTts != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
android.speech.tts.Voice voice = mTts.getVoice();
if (voice != null) {
return voice.getLocale();
}
} else {
return mTts.getLanguage();
}
}
return null;
}

private void populateInformationView() { private void populateInformationView() {
mInformation.clear(); mInformation.clear();


if (mTts != null) {
Locale language = mTts.getLanguage();
if (language != null) {
final String currentLocale = getString(R.string.current_tts_locale);
mInformation.add(new Pair<String,String>(currentLocale, mTts.getLanguage().getDisplayName()));
}
Locale language = getTtsLanguage();
if (language != null) {
final String currentLocale = getString(R.string.current_tts_locale);
mInformation.add(new Pair<String, String>(currentLocale, language.getDisplayName()));
} }


final String availableVoices = getString(R.string.available_voices); final String availableVoices = getString(R.string.available_voices);

Loading…
Cancel
Save