Browse Source

Implement SpeechSynthesis.getBufferSizeInMillis in Java.

master
Reece H. Dunn 9 years ago
parent
commit
46c5f88c6f

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

@@ -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) {

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

@@ -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);

Loading…
Cancel
Save