From 46c5f88c6f0db695eec483cc49846a3addc0085b Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Wed, 7 Oct 2015 20:57:51 +0100 Subject: [PATCH] Implement SpeechSynthesis.getBufferSizeInMillis in Java. --- android/jni/jni/eSpeakService.cpp | 16 ++-------------- .../com/reecedunn/espeak/SpeechSynthesis.java | 9 ++++----- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/android/jni/jni/eSpeakService.cpp b/android/jni/jni/eSpeakService.cpp index d14a997e..8525faee 100644 --- a/android/jni/jni/eSpeakService.cpp +++ b/android/jni/jni/eSpeakService.cpp @@ -109,19 +109,15 @@ enum synthesis_result { SYNTH_ABORT = 1 }; -const int DEFAULT_BUFFER_SIZE = 1000; - struct native_data_t { JNIEnv *env; jobject object; int sampleRate; - int bufferSizeInMillis; native_data_t() { env = NULL; object = NULL; sampleRate = 0; - bufferSizeInMillis = DEFAULT_BUFFER_SIZE; } }; @@ -178,7 +174,7 @@ JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeClassInit( JNIEXPORT jboolean JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeCreate( - JNIEnv *env, jobject object, jstring path) { + JNIEnv *env, jobject object, jstring path, jint bufferSizeInMillis) { if (DEBUG) LOGV("%s [env=%p, object=%p]", __FUNCTION__, env, object); native_data_t *nat = new native_data_t; @@ -193,7 +189,7 @@ JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeCreate( nat->object = env->NewWeakGlobalRef(object); if (DEBUG) LOGV("Initializing with path %s", c_path); - nat->sampleRate = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, nat->bufferSizeInMillis, c_path, 0); + nat->sampleRate = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, bufferSizeInMillis, c_path, 0); if (c_path) env->ReleaseStringUTFChars(path, c_path); @@ -229,14 +225,6 @@ JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeGetSampleRate( return (jint)(nat ? nat->sampleRate : 0); } -JNIEXPORT jint -JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeGetBufferSizeInMillis( - JNIEnv *env, jobject object) { - if (DEBUG) LOGV("%s", __FUNCTION__); - const native_data_t *nat = getNativeData(env, object); - return (jint) nat->bufferSizeInMillis; -} - JNIEXPORT jobjectArray JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeGetAvailableVoices( JNIEnv *env, jobject object) { diff --git a/android/src/com/reecedunn/espeak/SpeechSynthesis.java b/android/src/com/reecedunn/espeak/SpeechSynthesis.java index 15dd5d5b..0d461b84 100644 --- a/android/src/com/reecedunn/espeak/SpeechSynthesis.java +++ b/android/src/com/reecedunn/espeak/SpeechSynthesis.java @@ -51,6 +51,7 @@ public class SpeechSynthesis { public static final int CHANNEL_COUNT_MONO = 1; public static final int FORMAT_PCM_S16 = 2; + public static final int BUFFER_SIZE_IN_MILLIS = 1000; static { System.loadLibrary("ttsespeak"); @@ -107,7 +108,7 @@ public class SpeechSynthesis { } public int getBufferSizeInBytes() { - final int bufferSizeInMillis = nativeGetBufferSizeInMillis(); + final int bufferSizeInMillis = BUFFER_SIZE_IN_MILLIS; final int sampleRate = nativeGetSampleRate(); return (bufferSizeInMillis * sampleRate) / 1000; } @@ -310,7 +311,7 @@ public class SpeechSynthesis { return; } - if (!nativeCreate(mDatapath)) { + if (!nativeCreate(mDatapath, BUFFER_SIZE_IN_MILLIS)) { Log.e(TAG, "Failed to initialize speech synthesis library"); return; } @@ -336,7 +337,7 @@ public class SpeechSynthesis { private static native final boolean nativeClassInit(); - private native final boolean nativeCreate(String path); + private native final boolean nativeCreate(String path, int bufferSizeInMillis); private native final boolean nativeDestroy(); @@ -344,8 +345,6 @@ public class SpeechSynthesis { private native final int nativeGetSampleRate(); - private native final int nativeGetBufferSizeInMillis(); - private native final String[] nativeGetAvailableVoices(); private native final boolean nativeSetVoiceByName(String name);