SpeechSynthesis.java: expose the different voice options from eSpeak

This makes the following changes:

1.  setVoice takes a Voice object instead of a language string.

    This is to make the API cleaner and allows SpeechSynthesis
    to pass the correct parameter (identifier for SetVoiceByName,
    or name for SetVoiceByProperties) to espeak.

2.  The espeak_SetVoiceByName API is also exposed to support passing
    the voice variant to use.

3.  The age parameter has been re-added with the constants:
    *  SpeechSynthesis.AGE_ANY
    *  SpeechSynthesis.AGE_YOUNG
    *  SpeechSynthesis.AGE_OLD
    based on the behaviour of the eSpeak voice selection algorithm.

NOTE: Due to the way that voice selection is implemented in eSpeak,
if variant is specified, the age and gender cannot be specified and
vice versa.
This commit is contained in:
Reece H. Dunn
2013-05-02 18:06:41 +01:00
parent 88eab88d8a
commit cc72825682
3 changed files with 41 additions and 7 deletions
@@ -45,6 +45,10 @@ public class SpeechSynthesis {
public static final int GENDER_MALE = 1;
public static final int GENDER_FEMALE = 2;
public static final int AGE_ANY = 0;
public static final int AGE_YOUNG = 12;
public static final int AGE_OLD = 60;
static {
System.loadLibrary("ttsespeak");
@@ -169,8 +173,14 @@ public class SpeechSynthesis {
return voices;
}
public void setVoice(String language, int gender) {
nativeSetVoice(language, gender);
public void setVoice(Voice voice, String variant, int gender, int age) {
// NOTE: espeak_SetVoiceByProperties does not support specifying the
// voice variant (e.g. klatt), but espeak_SetVoiceByName does.
if (variant == null) {
nativeSetVoiceByProperties(voice.name, gender, age);
} else {
nativeSetVoiceByName(voice.identifier + "+" + variant);
}
}
public void setRate(int rate) {
@@ -300,7 +310,9 @@ public class SpeechSynthesis {
private native final String[] nativeGetAvailableVoices();
private native final boolean nativeSetVoice(String language, int gender);
private native final boolean nativeSetVoiceByName(String name);
private native final boolean nativeSetVoiceByProperties(String language, int gender, int age);
private native final boolean nativeSetRate(int rate);