Merge change 5119 into donut

* changes:
  Adding support for pitch changes of the synthesized text in Text-To-Speech.
This commit is contained in:
Android (Google) Code Review
2009-06-23 15:50:43 -07:00
5 changed files with 85 additions and 3 deletions

View File

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

View File

@@ -450,7 +450,6 @@ public class TextToSpeech {
}
/**
* Sets the speech rate for the TTS engine.
*
@@ -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.
*

View File

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

View File

@@ -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
@@ -145,6 +151,8 @@ public class SynthProxy {
String variant);
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);

View File

@@ -152,7 +152,6 @@ public class TtsService extends Service implements OnCompletionListener {
// speech rate
setSpeechRate(getDefaultRate());
// TODO handle default pitch
}
@@ -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()) {
@@ -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.
*