Browse Source

Display the formatted units on the volume setting.

master
Reece H. Dunn 12 years ago
parent
commit
b60ed6c9ae

+ 2
- 0
android/res/values/strings.xml View File

@@ -133,5 +133,7 @@
<string name="ssml">Load SSML Template</string>
<string name="synthesis_demo">Enter text to speak:</string>
<string name="espeak_volume">Volume</string>
<string name="formatter_wpm">%s WPM</string>
<string name="formatter_percentage">%s%%</string>

</resources>

+ 24
- 11
android/src/com/reecedunn/espeak/SpeechSynthesis.java View File

@@ -192,15 +192,24 @@ public class SpeechSynthesis {
/** Announce some of the punctuation characters. */
public static int PUNCT_SOME = 2;

public enum UnitType {
Percentage,
WordsPerMinute,
/** One of the PUNCT_* constants. */
Punctuation,
}

public class Parameter {
private final int id;
private final int min;
private final int max;
private final UnitType unitType;

private Parameter(int id, int min, int max) {
private Parameter(int id, int min, int max, UnitType unitType) {
this.id = id;
this.min = min;
this.max = max;
this.unitType = unitType;
}

public int getMinValue() {
@@ -226,22 +235,26 @@ public class SpeechSynthesis {
public void setValue(int value) {
nativeSetParameter(id, value);
}

public UnitType getUnitType() {
return unitType;
}
}

/** Speech rate in words per minute. */
public final Parameter Rate = new Parameter(1, 80, 450);
/** Speech rate. */
public final Parameter Rate = new Parameter(1, 80, 450, UnitType.WordsPerMinute);

/** Audio volume in percent. */
public final Parameter Volume = new Parameter(2, 0, 200);
/** Audio volume. */
public final Parameter Volume = new Parameter(2, 0, 200, UnitType.Percentage);

/** Base pitch in percent. */
public final Parameter Pitch = new Parameter(3, 0, 100);
/** Base pitch. */
public final Parameter Pitch = new Parameter(3, 0, 100, UnitType.Percentage);

/** Pitch range in percent (monotone = 0). */
public final Parameter PitchRange = new Parameter(4, 0, 100);
/** Pitch range (monotone = 0). */
public final Parameter PitchRange = new Parameter(4, 0, 100, UnitType.Percentage);

/** Which punctuation characters to announce; see the PUNCT_* constants. */
public final Parameter Punctuation = new Parameter(5, 0, 2);
/** Which punctuation characters to announce. */
public final Parameter Punctuation = new Parameter(5, 0, 2, UnitType.Punctuation);

public void synthesize(String text, boolean isSsml) {
nativeSynthesize(text, isSsml);

+ 15
- 2
android/src/com/reecedunn/espeak/TtsSettingsActivity.java View File

@@ -68,6 +68,18 @@ public class TtsSettingsActivity extends PreferenceActivity {
pref.setOnPreferenceChangeListener(mOnPreferenceChanged);
pref.setPersistent(true);

switch (parameter.getUnitType())
{
case Percentage:
pref.getExtras().putString("formatter", context.getString(R.string.formatter_percentage));
break;
case WordsPerMinute:
pref.getExtras().putString("formatter", context.getString(R.string.formatter_wpm));
break;
default:
throw new IllegalStateException("Unsupported unit type for the parameter.");
}

pref.setMin(parameter.getMinValue());
pref.setMax(parameter.getMaxValue());

@@ -128,9 +140,10 @@ public class TtsSettingsActivity extends PreferenceActivity {
summary = entries[index].toString();
}
} else if (preference instanceof SeekBarPreference) {
summary = (String)newValue;
String formatter = preference.getExtras().getString("formatter");
summary = String.format(formatter, (String)newValue);
}
preference.setSummary(summary.replaceAll("%", "%%"));
preference.setSummary(summary);
}
return true;
}

Loading…
Cancel
Save