Merge change 6271 into donut
* changes: Propagating the error codes through the TtsService
This commit is contained in:
@@ -27,15 +27,15 @@ import android.content.Intent;
|
|||||||
* {@hide}
|
* {@hide}
|
||||||
*/
|
*/
|
||||||
interface ITts {
|
interface ITts {
|
||||||
void setSpeechRate(in int speechRate);
|
int setSpeechRate(in int speechRate);
|
||||||
|
|
||||||
void setPitch(in int pitch);
|
int setPitch(in int pitch);
|
||||||
|
|
||||||
void speak(in String text, in int queueMode, in String[] params);
|
int speak(in String text, in int queueMode, in String[] params);
|
||||||
|
|
||||||
boolean isSpeaking();
|
boolean isSpeaking();
|
||||||
|
|
||||||
void stop();
|
int stop();
|
||||||
|
|
||||||
void addSpeech(in String text, in String packageName, in int resId);
|
void addSpeech(in String text, in String packageName, in int resId);
|
||||||
|
|
||||||
@@ -45,11 +45,11 @@ interface ITts {
|
|||||||
|
|
||||||
int isLanguageAvailable(in String language, in String country, in String variant);
|
int isLanguageAvailable(in String language, in String country, in String variant);
|
||||||
|
|
||||||
void setLanguage(in String language, in String country, in String variant);
|
int setLanguage(in String language, in String country, in String variant);
|
||||||
|
|
||||||
boolean synthesizeToFile(in String text, in String[] params, in String outputDirectory);
|
boolean synthesizeToFile(in String text, in String[] params, in String outputDirectory);
|
||||||
|
|
||||||
void playEarcon(in String earcon, in int queueMode, in String[] params);
|
int playEarcon(in String earcon, in int queueMode, in String[] params);
|
||||||
|
|
||||||
void addEarcon(in String earcon, in String packageName, in int resId);
|
void addEarcon(in String earcon, in String packageName, in int resId);
|
||||||
|
|
||||||
@@ -59,5 +59,5 @@ interface ITts {
|
|||||||
|
|
||||||
void unregisterCallback(ITtsCallback cb);
|
void unregisterCallback(ITtsCallback cb);
|
||||||
|
|
||||||
void playSilence(in long duration, in int queueMode, in String[] params);
|
int playSilence(in long duration, in int queueMode, in String[] params);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,15 +45,15 @@ public class SynthProxy {
|
|||||||
/**
|
/**
|
||||||
* Stops and clears the AudioTrack.
|
* Stops and clears the AudioTrack.
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public int stop() {
|
||||||
native_stop(mJniData);
|
return native_stop(mJniData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synthesize speech and speak it directly using AudioTrack.
|
* Synthesize speech and speak it directly using AudioTrack.
|
||||||
*/
|
*/
|
||||||
public void speak(String text) {
|
public int speak(String text) {
|
||||||
native_speak(mJniData, text);
|
return native_speak(mJniData, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,12 +61,10 @@ public class SynthProxy {
|
|||||||
* WAV file to the given path, assuming it is writable. Something like
|
* WAV file to the given path, assuming it is writable. Something like
|
||||||
* "/sdcard/???.wav" is recommended.
|
* "/sdcard/???.wav" is recommended.
|
||||||
*/
|
*/
|
||||||
public void synthesizeToFile(String text, String filename) {
|
public int synthesizeToFile(String text, String filename) {
|
||||||
native_synthesizeToFile(mJniData, text, filename);
|
return native_synthesizeToFile(mJniData, text, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add IPA methods
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries for language support.
|
* Queries for language support.
|
||||||
* Return codes are defined in android.speech.tts.TextToSpeech
|
* Return codes are defined in android.speech.tts.TextToSpeech
|
||||||
@@ -78,29 +76,29 @@ public class SynthProxy {
|
|||||||
/**
|
/**
|
||||||
* Sets the language.
|
* Sets the language.
|
||||||
*/
|
*/
|
||||||
public void setLanguage(String language, String country, String variant) {
|
public int setLanguage(String language, String country, String variant) {
|
||||||
native_setLanguage(mJniData, language, country, variant);
|
return native_setLanguage(mJniData, language, country, variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the language: it's not set, but prepared for use later.
|
* Loads the language: it's not set, but prepared for use later.
|
||||||
*/
|
*/
|
||||||
public void loadLanguage(String language, String country, String variant) {
|
public int loadLanguage(String language, String country, String variant) {
|
||||||
native_loadLanguage(mJniData, language, country, variant);
|
return native_loadLanguage(mJniData, language, country, variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the speech rate.
|
* Sets the speech rate.
|
||||||
*/
|
*/
|
||||||
public final void setSpeechRate(int speechRate) {
|
public final int setSpeechRate(int speechRate) {
|
||||||
native_setSpeechRate(mJniData, speechRate);
|
return native_setSpeechRate(mJniData, speechRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the pitch of the synthesized voice.
|
* Sets the pitch of the synthesized voice.
|
||||||
*/
|
*/
|
||||||
public final void setPitch(int pitch) {
|
public final int setPitch(int pitch) {
|
||||||
native_setPitch(mJniData, pitch);
|
return native_setPitch(mJniData, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -212,17 +212,17 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setSpeechRate(int rate) {
|
private int setSpeechRate(int rate) {
|
||||||
if (isDefaultEnforced()) {
|
if (isDefaultEnforced()) {
|
||||||
nativeSynth.setSpeechRate(getDefaultRate());
|
return nativeSynth.setSpeechRate(getDefaultRate());
|
||||||
} else {
|
} else {
|
||||||
nativeSynth.setSpeechRate(rate);
|
return nativeSynth.setSpeechRate(rate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setPitch(int pitch) {
|
private int setPitch(int pitch) {
|
||||||
nativeSynth.setPitch(pitch);
|
return nativeSynth.setPitch(pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -237,13 +237,13 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setLanguage(String lang, String country, String variant) {
|
private int setLanguage(String lang, String country, String variant) {
|
||||||
Log.v("TTS", "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")");
|
Log.v("TTS", "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")");
|
||||||
if (isDefaultEnforced()) {
|
if (isDefaultEnforced()) {
|
||||||
nativeSynth.setLanguage(getDefaultLanguage(), getDefaultCountry(),
|
return nativeSynth.setLanguage(getDefaultLanguage(), getDefaultCountry(),
|
||||||
getDefaultLocVariant());
|
getDefaultLocVariant());
|
||||||
} else {
|
} else {
|
||||||
nativeSynth.setLanguage(lang, country, variant);
|
return nativeSynth.setLanguage(lang, country, variant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,7 +314,7 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
* An ArrayList of parameters. This is not implemented for all
|
* An ArrayList of parameters. This is not implemented for all
|
||||||
* engines.
|
* engines.
|
||||||
*/
|
*/
|
||||||
private void speak(String text, int queueMode, ArrayList<String> params) {
|
private int speak(String text, int queueMode, ArrayList<String> params) {
|
||||||
if (queueMode == 0) {
|
if (queueMode == 0) {
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
@@ -322,6 +322,7 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
if (!mIsSpeaking) {
|
if (!mIsSpeaking) {
|
||||||
processSpeechQueue();
|
processSpeechQueue();
|
||||||
}
|
}
|
||||||
|
return TextToSpeech.TTS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -336,7 +337,7 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
* An ArrayList of parameters. This is not implemented for all
|
* An ArrayList of parameters. This is not implemented for all
|
||||||
* engines.
|
* engines.
|
||||||
*/
|
*/
|
||||||
private void playEarcon(String earcon, int queueMode,
|
private int playEarcon(String earcon, int queueMode,
|
||||||
ArrayList<String> params) {
|
ArrayList<String> params) {
|
||||||
if (queueMode == 0) {
|
if (queueMode == 0) {
|
||||||
stop();
|
stop();
|
||||||
@@ -345,16 +346,17 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
if (!mIsSpeaking) {
|
if (!mIsSpeaking) {
|
||||||
processSpeechQueue();
|
processSpeechQueue();
|
||||||
}
|
}
|
||||||
|
return TextToSpeech.TTS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops all speech output and removes any utterances still in the queue.
|
* Stops all speech output and removes any utterances still in the queue.
|
||||||
*/
|
*/
|
||||||
private void stop() {
|
private int stop() {
|
||||||
Log.i("TTS", "Stopping");
|
Log.i("TTS", "Stopping");
|
||||||
mSpeechQueue.clear();
|
mSpeechQueue.clear();
|
||||||
|
|
||||||
nativeSynth.stop();
|
int result = nativeSynth.stop();
|
||||||
mIsSpeaking = false;
|
mIsSpeaking = false;
|
||||||
if (mPlayer != null) {
|
if (mPlayer != null) {
|
||||||
try {
|
try {
|
||||||
@@ -364,13 +366,14 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.i("TTS", "Stopped");
|
Log.i("TTS", "Stopped");
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCompletion(MediaPlayer arg0) {
|
public void onCompletion(MediaPlayer arg0) {
|
||||||
processSpeechQueue();
|
processSpeechQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void playSilence(long duration, int queueMode,
|
private int playSilence(long duration, int queueMode,
|
||||||
ArrayList<String> params) {
|
ArrayList<String> params) {
|
||||||
if (queueMode == 0) {
|
if (queueMode == 0) {
|
||||||
stop();
|
stop();
|
||||||
@@ -379,6 +382,7 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
if (!mIsSpeaking) {
|
if (!mIsSpeaking) {
|
||||||
processSpeechQueue();
|
processSpeechQueue();
|
||||||
}
|
}
|
||||||
|
return TextToSpeech.TTS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void silence(final long duration) {
|
private void silence(final long duration) {
|
||||||
@@ -725,12 +729,12 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
* An ArrayList of parameters. The first element of this
|
* An ArrayList of parameters. The first element of this
|
||||||
* array controls the type of voice to use.
|
* array controls the type of voice to use.
|
||||||
*/
|
*/
|
||||||
public void speak(String text, int queueMode, String[] params) {
|
public int speak(String text, int queueMode, String[] params) {
|
||||||
ArrayList<String> speakingParams = new ArrayList<String>();
|
ArrayList<String> speakingParams = new ArrayList<String>();
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
speakingParams = new ArrayList<String>(Arrays.asList(params));
|
speakingParams = new ArrayList<String>(Arrays.asList(params));
|
||||||
}
|
}
|
||||||
mSelf.speak(text, queueMode, speakingParams);
|
return mSelf.speak(text, queueMode, speakingParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -744,12 +748,12 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
* @param params
|
* @param params
|
||||||
* An ArrayList of parameters.
|
* An ArrayList of parameters.
|
||||||
*/
|
*/
|
||||||
public void playEarcon(String earcon, int queueMode, String[] params) {
|
public int playEarcon(String earcon, int queueMode, String[] params) {
|
||||||
ArrayList<String> speakingParams = new ArrayList<String>();
|
ArrayList<String> speakingParams = new ArrayList<String>();
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
speakingParams = new ArrayList<String>(Arrays.asList(params));
|
speakingParams = new ArrayList<String>(Arrays.asList(params));
|
||||||
}
|
}
|
||||||
mSelf.playEarcon(earcon, queueMode, speakingParams);
|
return mSelf.playEarcon(earcon, queueMode, speakingParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -763,20 +767,20 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
* @param params
|
* @param params
|
||||||
* An ArrayList of parameters.
|
* An ArrayList of parameters.
|
||||||
*/
|
*/
|
||||||
public void playSilence(long duration, int queueMode, String[] params) {
|
public int playSilence(long duration, int queueMode, String[] params) {
|
||||||
ArrayList<String> speakingParams = new ArrayList<String>();
|
ArrayList<String> speakingParams = new ArrayList<String>();
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
speakingParams = new ArrayList<String>(Arrays.asList(params));
|
speakingParams = new ArrayList<String>(Arrays.asList(params));
|
||||||
}
|
}
|
||||||
mSelf.playSilence(duration, queueMode, speakingParams);
|
return mSelf.playSilence(duration, queueMode, speakingParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops all speech output and removes any utterances still in the
|
* Stops all speech output and removes any utterances still in the
|
||||||
* queue.
|
* queue.
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public int stop() {
|
||||||
mSelf.stop();
|
return mSelf.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -849,8 +853,8 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
* @param speechRate
|
* @param speechRate
|
||||||
* The speech rate that should be used
|
* The speech rate that should be used
|
||||||
*/
|
*/
|
||||||
public void setSpeechRate(int speechRate) {
|
public int setSpeechRate(int speechRate) {
|
||||||
mSelf.setSpeechRate(speechRate);
|
return mSelf.setSpeechRate(speechRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -860,8 +864,8 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
* @param pitch
|
* @param pitch
|
||||||
* The pitch that should be used for the synthesized voice
|
* The pitch that should be used for the synthesized voice
|
||||||
*/
|
*/
|
||||||
public void setPitch(int pitch) {
|
public int setPitch(int pitch) {
|
||||||
mSelf.setPitch(pitch);
|
return mSelf.setPitch(pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -895,8 +899,8 @@ public class TtsService extends Service implements OnCompletionListener {
|
|||||||
* @param country the three letter ISO country code.
|
* @param country the three letter ISO country code.
|
||||||
* @param variant the variant code associated with the country and language pair.
|
* @param variant the variant code associated with the country and language pair.
|
||||||
*/
|
*/
|
||||||
public void setLanguage(String lang, String country, String variant) {
|
public int setLanguage(String lang, String country, String variant) {
|
||||||
mSelf.setLanguage(lang, country, variant);
|
return mSelf.setLanguage(lang, country, variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user