SpeechSynthesis.java: provide a binding of the eSpeak Get/SetParameter API.

This commit is contained in:
Reece H. Dunn
2013-05-02 16:23:59 +01:00
parent f6edb535c7
commit 23d34d702a
2 changed files with 75 additions and 0 deletions
+23
View File
@@ -311,6 +311,29 @@ JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeSetPitch(
return JNI_FALSE;
}
JNIEXPORT jboolean
JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeSetParameter(
JNIEnv *env, jobject object, jint parameter, jint value) {
if (DEBUG) LOGV("%s(parameter=%d, value=%d)", __FUNCTION__, parameter, value);
const espeak_ERROR result = espeak_SetParameter((espeak_PARAMETER)parameter, (int)value, 0);
switch (result) {
case EE_OK: return JNI_TRUE;
case EE_INTERNAL_ERROR: LOGE("espeak_SetParameter: internal error."); break;
case EE_BUFFER_FULL: LOGE("espeak_SetParameter: buffer full."); break;
case EE_NOT_FOUND: LOGE("espeak_SetParameter: not found."); break;
}
return JNI_FALSE;
}
JNIEXPORT jint
JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeGetParameter(
JNIEnv *env, jobject object, jint parameter, jint current) {
if (DEBUG) LOGV("%s(parameter=%d, pitch=%d)", __FUNCTION__, parameter, current);
return espeak_GetParameter((espeak_PARAMETER)parameter, (int)current);
}
JNIEXPORT jboolean
JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeSynthesize(
JNIEnv *env, jobject object, jstring text, jboolean isSsml) {
@@ -182,6 +182,54 @@ public class SpeechSynthesis {
nativeSetPitch(pitch);
}
/** Don't announce any punctuation characters. */
public static int PUNCT_NONE = 0;
/** Announce every punctuation character. */
public static int PUNCT_ALL = 1;
/** Announce some of the punctuation characters. */
public static int PUNCT_SOME = 2;
public enum ParameterType {
/** Speech rate in words per minute (80 - 450). */
Rate(1),
/** Audio volume in percent (0 - 200; normal = 100). */
Volume(2),
/** Base pitch in percent (0 - 100; normal = 50). */
Pitch(3),
/** Pitch range in percent (0 - 100; normal = 50; monotone = 0). */
PitchRange(4),
/** Which punctuation characters to announce; see the PUNCT_* constants. */
Punctuation(5);
private int value;
private ParameterType(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
public void setParameterValue(ParameterType parameter, int value, int scale) {
setParameterValue(parameter, (value * scale) / 100);
}
public void setParameterValue(ParameterType parameter, int value) {
nativeSetParameter(parameter.getValue(), value);
}
public int getParameterValue(ParameterType parameter) {
return nativeGetParameter(parameter.getValue(), 1);
}
public int getParameterDefaultValue(ParameterType parameter) {
return nativeGetParameter(parameter.getValue(), 0);
}
public void synthesize(String text, boolean isSsml) {
nativeSynthesize(text, isSsml);
}
@@ -260,6 +308,10 @@ public class SpeechSynthesis {
private native final boolean nativeSetPitch(int pitch);
private native final boolean nativeSetParameter(int parameter, int value);
private native final int nativeGetParameter(int parameter, int current);
private native final boolean nativeSynthesize(String text, boolean isSsml);
private native final boolean nativeStop();