Browse Source

Implement SpeechSynthesis.getSampleRate in Java.

master
Reece H. Dunn 9 years ago
parent
commit
66cfe9af2b

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

@@ -112,12 +112,10 @@ enum synthesis_result {
struct native_data_t {
JNIEnv *env;
jobject object;
int sampleRate;

native_data_t() {
env = NULL;
object = NULL;
sampleRate = 0;
}
};

@@ -172,7 +170,7 @@ JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeClassInit(
return JNI_TRUE;
}

JNIEXPORT jboolean
JNIEXPORT jint
JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeCreate(
JNIEnv *env, jobject object, jstring path, jint bufferSizeInMillis) {
if (DEBUG) LOGV("%s [env=%p, object=%p]", __FUNCTION__, env, object);
@@ -180,7 +178,7 @@ JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeCreate(

if (nat == NULL) {
LOGE("%s: out of memory!", __FUNCTION__);
return JNI_FALSE;
return 0;
}

env->SetIntField(object, FIELD_mNativeData, (jint) nat);
@@ -189,11 +187,11 @@ 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, bufferSizeInMillis, c_path, 0);
int sampleRate = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, bufferSizeInMillis, c_path, 0);

if (c_path) env->ReleaseStringUTFChars(path, c_path);

return (nat->sampleRate > 0) ? JNI_TRUE : JNI_FALSE;
return sampleRate;
}

JNIEXPORT jboolean
@@ -217,14 +215,6 @@ JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeGetVersion(
return env->NewStringUTF(espeak_Info(NULL));
}

JNIEXPORT jint
JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeGetSampleRate(
JNIEnv *env, jobject object) {
if (DEBUG) LOGV("%s", __FUNCTION__);
const native_data_t *nat = getNativeData(env, object);
return (jint)(nat ? nat->sampleRate : 0);
}

JNIEXPORT jobjectArray
JNICALL Java_com_reecedunn_espeak_SpeechSynthesis_nativeGetAvailableVoices(
JNIEnv *env, jobject object) {

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

@@ -65,6 +65,7 @@ public class SpeechSynthesis {

private boolean mInitialized = false;
private static int mVoiceCount = 0;
private int mSampleRate = 0;

public SpeechSynthesis(Context context, SynthReadyCallback callback) {
// First, ensure the data directory exists, otherwise init will crash.
@@ -96,7 +97,7 @@ public class SpeechSynthesis {
}

public int getSampleRate() {
return nativeGetSampleRate();
return mSampleRate;
}

public int getChannelCount() {
@@ -108,9 +109,7 @@ public class SpeechSynthesis {
}

public int getBufferSizeInBytes() {
final int bufferSizeInMillis = BUFFER_SIZE_IN_MILLIS;
final int sampleRate = nativeGetSampleRate();
return (bufferSizeInMillis * sampleRate) / 1000;
return (BUFFER_SIZE_IN_MILLIS * mSampleRate) / 1000;
}

public List<Voice> getAvailableVoices() {
@@ -311,7 +310,8 @@ public class SpeechSynthesis {
return;
}

if (!nativeCreate(mDatapath, BUFFER_SIZE_IN_MILLIS)) {
mSampleRate = nativeCreate(mDatapath, BUFFER_SIZE_IN_MILLIS);
if (mSampleRate == 0) {
Log.e(TAG, "Failed to initialize speech synthesis library");
return;
}
@@ -337,14 +337,12 @@ public class SpeechSynthesis {

private static native final boolean nativeClassInit();

private native final boolean nativeCreate(String path, int bufferSizeInMillis);
private native final int nativeCreate(String path, int bufferSizeInMillis);

private native final boolean nativeDestroy();

private native final static String nativeGetVersion();

private native final int nativeGetSampleRate();

private native final String[] nativeGetAvailableVoices();

private native final boolean nativeSetVoiceByName(String name);

Loading…
Cancel
Save