diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 150e27deda4..f9758f33a21 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -259,6 +259,13 @@ + + + + + + + diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 72f56e7a5b6..1c480a834ff 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -81,6 +81,42 @@ -1 + + + + + Very slow + Slow + Normal + Fast + Very fast + + + + 60 + 100 + 140 + 180 + 220 + + + + + Very low + Low + Normal + High + Very high + + + + 50 + 80 + 100 + 120 + 150 + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 07bfe2ff812..9119edcc03d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1673,6 +1673,30 @@ found in the list of installed applications. Usage totals Refresh + + + + Speech synthesis + + Set text-to-speech options + + Speech synthesizer controls + + Always use my settings + + Default settings below override application settings + + Default settings + + Speech rate + + Speed at which the text is spoken + + Pitch + + Affects the tone of the spoken text + + Available speech synthesizers Power Control diff --git a/res/xml/settings.xml b/res/xml/settings.xml index 10712ebc7d1..9ca581ae019 100644 --- a/res/xml/settings.xml +++ b/res/xml/settings.xml @@ -141,6 +141,17 @@ android:targetClass="com.android.settings.AccessibilitySettings" /> + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/android/settings/TextToSpeechSettings.java b/src/com/android/settings/TextToSpeechSettings.java new file mode 100644 index 00000000000..02fc06d1af7 --- /dev/null +++ b/src/com/android/settings/TextToSpeechSettings.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * 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.android.settings; + +import static android.provider.Settings.Secure.TTS_USE_DEFAULTS; +import static android.provider.Settings.Secure.TTS_DEFAULT_RATE; +import static android.provider.Settings.Secure.TTS_DEFAULT_PITCH; + +import android.content.ContentResolver; +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.preference.CheckBoxPreference; +import android.provider.Settings; +import android.util.Log; + +public class TextToSpeechSettings extends PreferenceActivity implements + Preference.OnPreferenceChangeListener { + + private static final String TAG = "TextToSpeechSettings"; + + /** If there is no setting in the provider, use this. */ + private static final int FALLBACK_TTS_DEFAULT_RATE = 100; // 1x + private static final int FALLBACK_TTS_DEFAULT_PITCH = 100;// 1x + private static final int FALLBACK_TTS_USE_DEFAULTS = 1; + + private static final String KEY_TTS_USE_DEFAULT = + "toggle_use_default_tts_settings"; + private static final String KEY_TTS_DEFAULT_RATE = "tts_default_rate"; + private static final String KEY_TTS_DEFAULT_PITCH = "tts_default_pitch"; + + private CheckBoxPreference mUseDefaultPref = null; + private ListPreference mDefaultRatePref = null; + private ListPreference mDefaultPitchPref = null; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.tts_settings); + + initDefaultSettings(); + } + + + private void initDefaultSettings() { + ContentResolver resolver = getContentResolver(); + + // "Use Defaults" + mUseDefaultPref = + (CheckBoxPreference) findPreference(KEY_TTS_USE_DEFAULT); + mUseDefaultPref.setChecked(Settings.System.getInt(resolver, + TTS_USE_DEFAULTS, + FALLBACK_TTS_USE_DEFAULTS) == 1 ? true : false); + mUseDefaultPref.setOnPreferenceChangeListener(this); + + // Default rate + mDefaultRatePref = + (ListPreference) findPreference(KEY_TTS_DEFAULT_RATE); + mDefaultRatePref.setValue(String.valueOf(Settings.System.getInt( + resolver, TTS_DEFAULT_RATE, FALLBACK_TTS_DEFAULT_RATE))); + mDefaultRatePref.setOnPreferenceChangeListener(this); + + // Default pitch + mDefaultPitchPref = + (ListPreference) findPreference(KEY_TTS_DEFAULT_PITCH); + mDefaultPitchPref.setValue(String.valueOf(Settings.System.getInt( + resolver, TTS_DEFAULT_PITCH, FALLBACK_TTS_DEFAULT_PITCH))); + mDefaultPitchPref.setOnPreferenceChangeListener(this); + + } + + + public boolean onPreferenceChange(Preference preference, Object objValue) { + if (KEY_TTS_USE_DEFAULT.equals(preference.getKey())) { + // "Use Defaults" + int value = (Boolean)objValue ? 1 : 0; + Settings.System.putInt(getContentResolver(), TTS_USE_DEFAULTS, + value); + Log.i(TAG, "TTS use default settings is "+objValue.toString()); + } else if (KEY_TTS_DEFAULT_RATE.equals(preference.getKey())) { + // Default rate + int value = Integer.parseInt((String) objValue); + try { + Settings.System.putInt(getContentResolver(), + TTS_DEFAULT_RATE, value); + Log.i(TAG, "TTS default rate is "+value); + } catch (NumberFormatException e) { + Log.e(TAG, "could not persist default TTS rate setting", e); + } + } else if (KEY_TTS_DEFAULT_PITCH.equals(preference.getKey())) { + // Default pitch + int value = Integer.parseInt((String) objValue); + try { + Settings.System.putInt(getContentResolver(), + TTS_DEFAULT_PITCH, value); + Log.i(TAG, "TTS default pitch is "+value); + } catch (NumberFormatException e) { + Log.e(TAG, "could not persist default TTS pitch setting", e); + } + } + + return true; + } + +}