Browse Source

TtsService: support detecting SSML documents

master
Reece H. Dunn 12 years ago
parent
commit
4d44e88dd2

+ 3
- 2
android/jni/jni/eSpeakService.cpp View File



JNIEXPORT jboolean JNIEXPORT jboolean
JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeSynthesize( JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeSynthesize(
JNIEnv *env, jobject object, jstring text) {
JNIEnv *env, jobject object, jstring text, jboolean isSsml) {
if (DEBUG) LOGV("%s", __FUNCTION__); if (DEBUG) LOGV("%s", __FUNCTION__);
native_data_t *nat = getNativeData(env, object); native_data_t *nat = getNativeData(env, object);
const char *c_text = text ? env->GetStringUTFChars(text, NULL) : NULL; const char *c_text = text ? env->GetStringUTFChars(text, NULL) : NULL;
espeak_SetSynthCallback(SynthCallback); espeak_SetSynthCallback(SynthCallback);
const espeak_ERROR result = espeak_Synth(c_text, strlen(c_text), 0, // position const espeak_ERROR result = espeak_Synth(c_text, strlen(c_text), 0, // position
POS_CHARACTER, 0, // end position (0 means no end position) POS_CHARACTER, 0, // end position (0 means no end position)
espeakCHARS_UTF8, // text is UTF-8 encoded
isSsml ? espeakCHARS_UTF8 | espeakSSML // UTF-8 encoded SSML
: espeakCHARS_UTF8, // UTF-8 encoded text
&unique_identifier, nat); &unique_identifier, nat);
espeak_Synchronize(); espeak_Synchronize();



+ 3
- 3
android/src/com/reecedunn/espeak/SpeechSynthesis.java View File

nativeSetPitch(pitch); nativeSetPitch(pitch);
} }


public void synthesize(String text) {
nativeSynthesize(text);
public void synthesize(String text, boolean isSsml) {
nativeSynthesize(text, isSsml);
} }


public void stop() { public void stop() {


private native final boolean nativeSetPitch(int pitch); private native final boolean nativeSetPitch(int pitch);


private native final boolean nativeSynthesize(String text);
private native final boolean nativeSynthesize(String text, boolean isSsml);


private native final boolean nativeStop(); private native final boolean nativeStop();



+ 12
- 2
android/src/com/reecedunn/espeak/TtsService.java View File

return; return;
} }


final String text = request.getText();
String text = request.getText();
if (text == null)
return;

final int gender = getDefaultGender(); final int gender = getDefaultGender();
final int rate = scaleRate(request.getSpeechRate()); final int rate = scaleRate(request.getSpeechRate());
final int pitch = scalePitch(request.getPitch()); final int pitch = scalePitch(request.getPitch());
} }
} }


if (text.startsWith("<?xml"))
{
// eSpeak does not recognise/skip "<?...?>" preprocessing tags,
// so need to remove these before passing to synthesize.
text = text.substring(text.indexOf("?>") + 2).trim();
}

mCallback = callback; mCallback = callback;
mCallback.start(mEngine.getSampleRate(), mEngine.getAudioFormat(), mCallback.start(mEngine.getSampleRate(), mEngine.getAudioFormat(),
mEngine.getChannelCount()); mEngine.getChannelCount());
mEngine.setVoiceByProperties(null, mMatchingVoice.name, gender, 0, 0); mEngine.setVoiceByProperties(null, mMatchingVoice.name, gender, 0, 0);
mEngine.setRate(rate); mEngine.setRate(rate);
mEngine.setPitch(pitch); mEngine.setPitch(pitch);
mEngine.synthesize(text);
mEngine.synthesize(text, text.startsWith("<speak"));
} }


/** /**

Loading…
Cancel
Save