Loading core/java/android/speech/tts/ITts.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ import android.content.Intent; interface ITts { void setSpeechRate(in int speechRate); void setPitch(in int pitch); void speak(in String text, in int queueMode, in String[] params); boolean isSpeaking(); Loading core/java/android/speech/tts/TextToSpeech.java +31 −1 Original line number Diff line number Diff line Loading @@ -450,7 +450,6 @@ public class TextToSpeech { } /** * Sets the speech rate for the TTS engine. * Loading Loading @@ -482,6 +481,37 @@ public class TextToSpeech { } /** * Sets the speech pitch for the TTS engine. * * Note that the pitch is not universally supported by all engines and * will be treated as a hint. The TTS library will try to use the specified * pitch, but there is no guarantee. * This has no effect on any pre-recorded speech. * * @param pitch * The pitch for the TTS engine. 1 is the normal pitch, * lower values lower the tone of the synthesized voice, * greater values increase it. */ public void setPitch(float pitch) { synchronized (mStartLock) { if (!mStarted) { return; } try { if (pitch > 0) { mITts.setPitch((int)(pitch*100)); } } catch (RemoteException e) { // TTS died; restart it. mStarted = false; initTts(); } } } /** * Sets the language for the TTS engine. * Loading packages/TtsService/jni/android_tts_SynthProxy.cpp +27 −1 Original line number Diff line number Diff line Loading @@ -296,7 +296,7 @@ android_tts_SynthProxy_setLanguage(JNIEnv *env, jobject thiz, jint jniData, static void android_tts_SynthProxy_setSpeechRate(JNIEnv *env, jobject thiz, jint jniData, int speechRate) jint speechRate) { if (jniData == 0) { LOGE("android_tts_SynthProxy_setSpeechRate(): invalid JNI data"); Loading @@ -316,6 +316,28 @@ android_tts_SynthProxy_setSpeechRate(JNIEnv *env, jobject thiz, jint jniData, } static void android_tts_SynthProxy_setPitch(JNIEnv *env, jobject thiz, jint jniData, jint pitch) { if (jniData == 0) { LOGE("android_tts_SynthProxy_setPitch(): invalid JNI data"); return; } int bufSize = 10; char buffer [bufSize]; sprintf(buffer, "%d", pitch); SynthProxyJniStorage* pSynthData = (SynthProxyJniStorage*)jniData; LOGI("setting pitch to %d", pitch); // TODO check return codes if (pSynthData->mNativeSynthInterface) { pSynthData->mNativeSynthInterface->setProperty("pitch", buffer, bufSize); } } // TODO: Refactor this to get rid of any assumptions about sample rate, etc. static void android_tts_SynthProxy_synthesizeToFile(JNIEnv *env, jobject thiz, jint jniData, Loading Loading @@ -541,6 +563,10 @@ static JNINativeMethod gMethods[] = { "(II)V", (void*)android_tts_SynthProxy_setSpeechRate }, { "native_setPitch", "(II)V", (void*)android_tts_SynthProxy_setPitch }, { "native_playAudioBuffer", "(III)V", (void*)android_tts_SynthProxy_playAudioBuffer Loading packages/TtsService/src/android/tts/SynthProxy.java +8 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,12 @@ public class SynthProxy { native_setSpeechRate(mJniData, speechRate); } /** * Sets the pitch of the synthesized voice */ public final void setPitch(int pitch) { native_setPitch(mJniData, pitch); } /** * Plays the given audio buffer Loading Loading @@ -146,6 +152,8 @@ public class SynthProxy { private native final void native_setSpeechRate(int jniData, int speechRate); private native final void native_setPitch(int jniData, int speechRate); // TODO add buffer format private native final void native_playAudioBuffer(int jniData, int bufferPointer, int bufferSize); Loading packages/TtsService/src/android/tts/TtsService.java +17 −1 Original line number Diff line number Diff line Loading @@ -152,7 +152,6 @@ public class TtsService extends Service implements OnCompletionListener { // speech rate setSpeechRate(getDefaultRate()); // TODO handle default pitch } Loading @@ -179,6 +178,12 @@ public class TtsService extends Service implements OnCompletionListener { } } private void setPitch(int pitch) { nativeSynth.setPitch(pitch); } private void setLanguage(String lang, String country, String variant) { Log.v("TTS", "TtsService.setLanguage("+lang+", "+country+", "+variant+")"); if (isDefaultEnforced()) { Loading Loading @@ -705,6 +710,17 @@ public class TtsService extends Service implements OnCompletionListener { mSelf.setSpeechRate(speechRate); } /** * Sets the pitch for the TTS. Note that this will only have an * effect on synthesized speech; it will not affect pre-recorded speech. * * @param pitch * The pitch that should be used for the synthesized voice */ public void setPitch(int pitch) { mSelf.setPitch(pitch); } /** * Sets the speech rate for the TTS, which affects the synthesized voice. * Loading Loading
core/java/android/speech/tts/ITts.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ import android.content.Intent; interface ITts { void setSpeechRate(in int speechRate); void setPitch(in int pitch); void speak(in String text, in int queueMode, in String[] params); boolean isSpeaking(); Loading
core/java/android/speech/tts/TextToSpeech.java +31 −1 Original line number Diff line number Diff line Loading @@ -450,7 +450,6 @@ public class TextToSpeech { } /** * Sets the speech rate for the TTS engine. * Loading Loading @@ -482,6 +481,37 @@ public class TextToSpeech { } /** * Sets the speech pitch for the TTS engine. * * Note that the pitch is not universally supported by all engines and * will be treated as a hint. The TTS library will try to use the specified * pitch, but there is no guarantee. * This has no effect on any pre-recorded speech. * * @param pitch * The pitch for the TTS engine. 1 is the normal pitch, * lower values lower the tone of the synthesized voice, * greater values increase it. */ public void setPitch(float pitch) { synchronized (mStartLock) { if (!mStarted) { return; } try { if (pitch > 0) { mITts.setPitch((int)(pitch*100)); } } catch (RemoteException e) { // TTS died; restart it. mStarted = false; initTts(); } } } /** * Sets the language for the TTS engine. * Loading
packages/TtsService/jni/android_tts_SynthProxy.cpp +27 −1 Original line number Diff line number Diff line Loading @@ -296,7 +296,7 @@ android_tts_SynthProxy_setLanguage(JNIEnv *env, jobject thiz, jint jniData, static void android_tts_SynthProxy_setSpeechRate(JNIEnv *env, jobject thiz, jint jniData, int speechRate) jint speechRate) { if (jniData == 0) { LOGE("android_tts_SynthProxy_setSpeechRate(): invalid JNI data"); Loading @@ -316,6 +316,28 @@ android_tts_SynthProxy_setSpeechRate(JNIEnv *env, jobject thiz, jint jniData, } static void android_tts_SynthProxy_setPitch(JNIEnv *env, jobject thiz, jint jniData, jint pitch) { if (jniData == 0) { LOGE("android_tts_SynthProxy_setPitch(): invalid JNI data"); return; } int bufSize = 10; char buffer [bufSize]; sprintf(buffer, "%d", pitch); SynthProxyJniStorage* pSynthData = (SynthProxyJniStorage*)jniData; LOGI("setting pitch to %d", pitch); // TODO check return codes if (pSynthData->mNativeSynthInterface) { pSynthData->mNativeSynthInterface->setProperty("pitch", buffer, bufSize); } } // TODO: Refactor this to get rid of any assumptions about sample rate, etc. static void android_tts_SynthProxy_synthesizeToFile(JNIEnv *env, jobject thiz, jint jniData, Loading Loading @@ -541,6 +563,10 @@ static JNINativeMethod gMethods[] = { "(II)V", (void*)android_tts_SynthProxy_setSpeechRate }, { "native_setPitch", "(II)V", (void*)android_tts_SynthProxy_setPitch }, { "native_playAudioBuffer", "(III)V", (void*)android_tts_SynthProxy_playAudioBuffer Loading
packages/TtsService/src/android/tts/SynthProxy.java +8 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,12 @@ public class SynthProxy { native_setSpeechRate(mJniData, speechRate); } /** * Sets the pitch of the synthesized voice */ public final void setPitch(int pitch) { native_setPitch(mJniData, pitch); } /** * Plays the given audio buffer Loading Loading @@ -146,6 +152,8 @@ public class SynthProxy { private native final void native_setSpeechRate(int jniData, int speechRate); private native final void native_setPitch(int jniData, int speechRate); // TODO add buffer format private native final void native_playAudioBuffer(int jniData, int bufferPointer, int bufferSize); Loading
packages/TtsService/src/android/tts/TtsService.java +17 −1 Original line number Diff line number Diff line Loading @@ -152,7 +152,6 @@ public class TtsService extends Service implements OnCompletionListener { // speech rate setSpeechRate(getDefaultRate()); // TODO handle default pitch } Loading @@ -179,6 +178,12 @@ public class TtsService extends Service implements OnCompletionListener { } } private void setPitch(int pitch) { nativeSynth.setPitch(pitch); } private void setLanguage(String lang, String country, String variant) { Log.v("TTS", "TtsService.setLanguage("+lang+", "+country+", "+variant+")"); if (isDefaultEnforced()) { Loading Loading @@ -705,6 +710,17 @@ public class TtsService extends Service implements OnCompletionListener { mSelf.setSpeechRate(speechRate); } /** * Sets the pitch for the TTS. Note that this will only have an * effect on synthesized speech; it will not affect pre-recorded speech. * * @param pitch * The pitch that should be used for the synthesized voice */ public void setPitch(int pitch) { mSelf.setPitch(pitch); } /** * Sets the speech rate for the TTS, which affects the synthesized voice. * Loading