Browse Source

TextToSpeechService: support SynthesisRequest.getVoiceName

master
Reece H. Dunn 10 years ago
parent
commit
736986d609
1 changed files with 24 additions and 7 deletions
  1. 24
    7
      android/src/com/reecedunn/espeak/TtsService.java

+ 24
- 7
android/src/com/reecedunn/espeak/TtsService.java View File



@Override @Override
public int onLoadVoice(String name) { public int onLoadVoice(String name) {
return super.onLoadVoice(name);
Voice voice = mAvailableVoices.get(name);
if (voice == null) {
return TextToSpeech.ERROR;
}
mMatchingVoice = voice;
return TextToSpeech.SUCCESS;
} }


@Override @Override
} }
} }


@Override
protected synchronized void onSynthesizeText(
SynthesisRequest request, SynthesisCallback callback) {
private int selectVoice(SynthesisRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final String name = request.getVoiceName();
if (name != null && !name.isEmpty()) {
return onLoadVoice(name);
}
}

final int result = onLoadLanguage(request.getLanguage(), request.getCountry(), request.getVariant()); final int result = onLoadLanguage(request.getLanguage(), request.getCountry(), request.getVariant());
switch (result) { switch (result) {
case TextToSpeech.LANG_MISSING_DATA:
case TextToSpeech.LANG_NOT_SUPPORTED:
return;
case TextToSpeech.LANG_MISSING_DATA:
case TextToSpeech.LANG_NOT_SUPPORTED:
return TextToSpeech.ERROR;
} }
return TextToSpeech.SUCCESS;
}

@Override
protected synchronized void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback) {
if (selectVoice(request) == TextToSpeech.ERROR)
return;


String text = getRequestString(request); String text = getRequestString(request);
if (text == null) if (text == null)

Loading…
Cancel
Save