@@ -345,59 +345,6 @@ public class SpeechSynthesis { | |||
void onSynthDataComplete(); | |||
} | |||
public static class VoiceVariant { | |||
public final String variant; | |||
public final int gender; | |||
public final int age; | |||
protected VoiceVariant(String variant, int age) { | |||
if (variant.equals("male")) { | |||
this.variant = null; | |||
this.gender = GENDER_MALE; | |||
} else if (variant.equals("female")) { | |||
this.variant = null; | |||
this.gender = GENDER_FEMALE; | |||
} else { | |||
this.variant = variant; | |||
this.gender = GENDER_UNSPECIFIED; | |||
} | |||
this.age = age; | |||
} | |||
@Override | |||
public String toString() { | |||
final String ret; | |||
if (gender == GENDER_MALE) { | |||
ret = "male"; | |||
} else if (gender == GENDER_FEMALE) { | |||
ret = "female"; | |||
} else { | |||
ret = variant; | |||
} | |||
if (age == AGE_YOUNG) { | |||
return ret + "-young"; | |||
} else if (age == AGE_OLD) { | |||
return ret + "-old"; | |||
} | |||
return ret; | |||
} | |||
} | |||
public static VoiceVariant parseVoiceVariant(String value) { | |||
String[] parts = value.split("-"); | |||
int age = AGE_ANY; | |||
switch (parts.length) { | |||
case 1: // variant | |||
break; | |||
case 2: // variant-age | |||
age = parts[1].equals("young") ? AGE_YOUNG : AGE_OLD; | |||
break; | |||
default: | |||
return null; | |||
} | |||
return new VoiceVariant(parts[0], age); | |||
} | |||
public class Voice { | |||
public final String name; | |||
public final String identifier; |
@@ -217,16 +217,16 @@ public class TtsService extends TextToSpeechService { | |||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); | |||
final String variantString = prefs.getString("espeak_variant", null); | |||
final SpeechSynthesis.VoiceVariant variant; | |||
final VoiceVariant variant; | |||
if (variantString == null) { | |||
final int gender = getPreferenceValue(prefs, "default_gender", SpeechSynthesis.GENDER_MALE); | |||
if (gender == SpeechSynthesis.GENDER_FEMALE) { | |||
variant = SpeechSynthesis.parseVoiceVariant("default-female"); | |||
variant = VoiceVariant.parseVoiceVariant("default-female"); | |||
} else { | |||
variant = SpeechSynthesis.parseVoiceVariant("default-male"); | |||
variant = VoiceVariant.parseVoiceVariant("default-male"); | |||
} | |||
} else { | |||
variant = SpeechSynthesis.parseVoiceVariant(variantString); | |||
variant = VoiceVariant.parseVoiceVariant(variantString); | |||
} | |||
int rate = getPreferenceValue(prefs, "espeak_rate", Integer.MIN_VALUE); |
@@ -0,0 +1,70 @@ | |||
/* | |||
* Copyright (C) 2013 Reece H. Dunn | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package com.reecedunn.espeak; | |||
public class VoiceVariant { | |||
public final String variant; | |||
public final int gender; | |||
public final int age; | |||
protected VoiceVariant(String variant, int age) { | |||
if (variant.equals("male")) { | |||
this.variant = null; | |||
this.gender = SpeechSynthesis.GENDER_MALE; | |||
} else if (variant.equals("female")) { | |||
this.variant = null; | |||
this.gender = SpeechSynthesis.GENDER_FEMALE; | |||
} else { | |||
this.variant = variant; | |||
this.gender = SpeechSynthesis.GENDER_UNSPECIFIED; | |||
} | |||
this.age = age; | |||
} | |||
@Override | |||
public String toString() { | |||
final String ret; | |||
if (gender == SpeechSynthesis.GENDER_MALE) { | |||
ret = "male"; | |||
} else if (gender == SpeechSynthesis.GENDER_FEMALE) { | |||
ret = "female"; | |||
} else { | |||
ret = variant; | |||
} | |||
if (age == SpeechSynthesis.AGE_YOUNG) { | |||
return ret + "-young"; | |||
} else if (age == SpeechSynthesis.AGE_OLD) { | |||
return ret + "-old"; | |||
} | |||
return ret; | |||
} | |||
public static VoiceVariant parseVoiceVariant(String value) { | |||
String[] parts = value.split("-"); | |||
int age = SpeechSynthesis.AGE_ANY; | |||
switch (parts.length) { | |||
case 1: // variant | |||
break; | |||
case 2: // variant-age | |||
age = parts[1].equals("young") ? SpeechSynthesis.AGE_YOUNG : SpeechSynthesis.AGE_OLD; | |||
break; | |||
default: | |||
return null; | |||
} | |||
return new VoiceVariant(parts[0], age); | |||
} | |||
} |