mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-10-31 13:38:47 +00:00
85 lines
3.0 KiB
Java
85 lines
3.0 KiB
Java
/*
|
|
* 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;
|
|
private final SpeechSynthesis mEngine;
|
|
|
|
public static final String PREF_DEFAULT_GENDER = "default_gender";
|
|
public static final String PREF_VARIANT = "espeak_variant";
|
|
public static final String PREF_DEFAULT_RATE = "default_rate";
|
|
public static final String PREF_RATE = "espeak_rate";
|
|
public static final String PREF_DEFAULT_PITCH = "default_pitch";
|
|
public static final String PREF_PITCH = "espeak_pitch";
|
|
|
|
public VoiceSettings(SharedPreferences preferences, SpeechSynthesis engine) {
|
|
mPreferences = preferences;
|
|
mEngine = engine;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public int getRate() {
|
|
int min = mEngine.Rate.getMinValue();
|
|
int max = mEngine.Rate.getMaxValue();
|
|
|
|
int rate = getPreferenceValue(PREF_RATE, Integer.MIN_VALUE);
|
|
if (rate == Integer.MIN_VALUE) {
|
|
rate = (int)((float)getPreferenceValue(PREF_DEFAULT_RATE, 100) / 100 * (float)mEngine.Rate.getDefaultValue());
|
|
}
|
|
|
|
if (rate > max) rate = max;
|
|
if (rate < min) rate = min;
|
|
return rate;
|
|
}
|
|
|
|
public int getPitch() {
|
|
int min = mEngine.Pitch.getMinValue();
|
|
int max = mEngine.Pitch.getMaxValue();
|
|
|
|
int pitch = getPreferenceValue(PREF_PITCH, Integer.MIN_VALUE);
|
|
if (pitch == Integer.MIN_VALUE) {
|
|
pitch = getPreferenceValue(PREF_DEFAULT_PITCH, 100) / 2;
|
|
}
|
|
|
|
if (pitch > max) pitch = max;
|
|
if (pitch < min) pitch = min;
|
|
return pitch;
|
|
}
|
|
|
|
private int getPreferenceValue(String preference, int defaultValue) {
|
|
String prefString = mPreferences.getString(preference, null);
|
|
if (prefString == null) {
|
|
return defaultValue;
|
|
}
|
|
return Integer.parseInt(prefString);
|
|
}
|
|
}
|