Browse Source

Replace SpeechSynthesis.getBufferSizeInBytes with a constant in the C++ source, specified in the correct units (milliseconds).

master
Reece H. Dunn 9 years ago
parent
commit
3b6c327756

+ 0
- 1
android/eSpeakTests/src/com/reecedunn/espeak/test/SpeechSynthesisTest.java View File

assertThat(synth.getSampleRate(), is(22050)); assertThat(synth.getSampleRate(), is(22050));
assertThat(synth.getChannelCount(), is(1)); assertThat(synth.getChannelCount(), is(1));
assertThat(synth.getAudioFormat(), is(AudioFormat.ENCODING_PCM_16BIT)); assertThat(synth.getAudioFormat(), is(AudioFormat.ENCODING_PCM_16BIT));
assertThat(synth.getBufferSizeInBytes(), is(22050));
} }


public void testJavaToIanaLanguageCode() public void testJavaToIanaLanguageCode()

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

#include <speak_lib.h> #include <speak_lib.h>
#include <Log.h> #include <Log.h>


#define BUFFER_SIZE_IN_MILLISECONDS 1000

/** @name Java to Wide String Helpers /** @name Java to Wide String Helpers
* @brief These are helpers for converting a jstring to wchar_t*. * @brief These are helpers for converting a jstring to wchar_t*.
* *


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


const char *c_path = path ? env->GetStringUTFChars(path, NULL) : NULL; const char *c_path = path ? env->GetStringUTFChars(path, NULL) : NULL;


if (DEBUG) LOGV("Initializing with path %s", c_path); if (DEBUG) LOGV("Initializing with path %s", c_path);
int sampleRate = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, bufferSizeInMillis, c_path, 0);
int sampleRate = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, BUFFER_SIZE_IN_MILLISECONDS, c_path, 0);


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



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



public static final int CHANNEL_COUNT_MONO = 1; public static final int CHANNEL_COUNT_MONO = 1;
public static final int FORMAT_PCM_S16 = 2; public static final int FORMAT_PCM_S16 = 2;
public static final int BUFFER_SIZE_IN_MILLIS = 1000;


static { static {
System.loadLibrary("ttsespeak"); System.loadLibrary("ttsespeak");
return FORMAT_PCM_S16; return FORMAT_PCM_S16;
} }


public int getBufferSizeInBytes() {
return (BUFFER_SIZE_IN_MILLIS * mSampleRate) / 1000;
}

private Locale getLocaleFromLanguageName(String name) { private Locale getLocaleFromLanguageName(String name) {
if (mLocaleFixes.containsKey(name)) { if (mLocaleFixes.containsKey(name)) {
return mLocaleFixes.get(name); return mLocaleFixes.get(name);
return; return;
} }


mSampleRate = nativeCreate(mDatapath, BUFFER_SIZE_IN_MILLIS);
mSampleRate = nativeCreate(mDatapath);
if (mSampleRate == 0) { if (mSampleRate == 0) {
Log.e(TAG, "Failed to initialize speech synthesis library"); Log.e(TAG, "Failed to initialize speech synthesis library");
return; return;


private static native final boolean nativeClassInit(); private static native final boolean nativeClassInit();


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


private native final static String nativeGetVersion(); private native final static String nativeGetVersion();



Loading…
Cancel
Save