VoiceSettings.java: Support reading the default_gender and espeak_variant preferences.

This commit is contained in:
Reece H. Dunn
2013-09-04 13:43:53 +01:00
parent 00bc5f2c6c
commit 6c5631d810
2 changed files with 148 additions and 0 deletions
@@ -0,0 +1,50 @@
/*
* 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;
import android.content.SharedPreferences;
public class VoiceSettings {
private final SharedPreferences mPreferences;
public static final String PREF_DEFAULT_GENDER = "default_gender";
public static final String PREF_VARIANT = "espeak_variant";
public VoiceSettings(SharedPreferences preferences) {
mPreferences = preferences;
}
public VoiceVariant getVoiceVariant() {
String variant = mPreferences.getString(PREF_VARIANT, null);
if (variant == null) {
int gender = getPreferenceValue(PREF_DEFAULT_GENDER, SpeechSynthesis.GENDER_MALE);
if (gender == SpeechSynthesis.GENDER_FEMALE) {
return VoiceVariant.parseVoiceVariant(VoiceVariant.FEMALE);
}
return VoiceVariant.parseVoiceVariant(VoiceVariant.MALE);
}
return VoiceVariant.parseVoiceVariant(variant);
}
private int getPreferenceValue(String preference, int defaultValue) {
String prefString = mPreferences.getString(preference, null);
if (prefString == null) {
return defaultValue;
}
return Integer.parseInt(prefString);
}
}