mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-12-04 23:56:14 +00:00
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:
@@ -241,16 +241,38 @@ JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeGetAvailableVoices(
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean
|
||||
JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeSetVoice(
|
||||
JNIEnv *env, jobject object, jstring language, jint gender) {
|
||||
JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeSetVoiceByName(
|
||||
JNIEnv *env, jobject object, jstring name) {
|
||||
const char *c_name = name ? env->GetStringUTFChars(name, NULL) : NULL;
|
||||
|
||||
if (DEBUG) LOGV("%s(name=%s)", __FUNCTION__, c_name);
|
||||
|
||||
const espeak_ERROR result = espeak_SetVoiceByName(c_name);
|
||||
|
||||
if (c_name) env->ReleaseStringUTFChars(name, c_name);
|
||||
|
||||
switch (result) {
|
||||
case EE_OK: return JNI_TRUE;
|
||||
case EE_INTERNAL_ERROR: LOGE("espeak_SetVoiceByName: internal error."); break;
|
||||
case EE_BUFFER_FULL: LOGE("espeak_SetVoiceByName: buffer full."); break;
|
||||
case EE_NOT_FOUND: LOGE("espeak_SetVoiceByName: not found."); break;
|
||||
}
|
||||
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean
|
||||
JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeSetVoiceByProperties(
|
||||
JNIEnv *env, jobject object, jstring language, jint gender, jint age) {
|
||||
const char *c_language = language ? env->GetStringUTFChars(language, NULL) : NULL;
|
||||
|
||||
if (DEBUG) LOGV("%s(language=%s, gender=%d)", __FUNCTION__, c_language, gender);
|
||||
if (DEBUG) LOGV("%s(language=%s, gender=%d, age=%d)", __FUNCTION__, c_language, gender, age);
|
||||
|
||||
espeak_VOICE voice_select;
|
||||
memset(&voice_select, 0, sizeof(espeak_VOICE));
|
||||
voice_select.languages = c_language;
|
||||
voice_select.gender = (int) gender;
|
||||
voice_select.age = (int) age;
|
||||
|
||||
const espeak_ERROR result = espeak_SetVoiceByProperties(&voice_select);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user