public abstract class TextToSpeechService extends Service
onIsLanguageAvailable(java.lang.String, java.lang.String, java.lang.String)
onLoadLanguage(java.lang.String, java.lang.String, java.lang.String)
onGetLanguage()
onSynthesizeText(android.speech.tts.SynthesisRequest, android.speech.tts.SynthesisCallback)
onStop()
onSynthesizeText(android.speech.tts.SynthesisRequest, android.speech.tts.SynthesisCallback)
is central to the engine implementation. The
implementation should synthesize text as per the request parameters and
return synthesized data via the supplied callback. This class and its helpers
will then consume that data, which might mean queuing it for playback or writing
it to a file or similar. All calls to this method will be on a single thread,
which will be different from the main thread of the service. Synthesis must be
synchronous which means the engine must NOT hold on to the callback or call any
methods on it after the method returns.
onStop()
tells the engine that it should stop
all ongoing synthesis, if any. Any pending data from the current synthesis
will be discarded.
onGetLanguage()
is not required as of JELLYBEAN_MR2 (API 18) and later, it is only
called on earlier versions of Android.
API Level 20 adds support for Voice objects. Voices are an abstraction that allow the TTS
service to expose multiple backends for a single locale. Each one of them can have a different
features set. In order to fully take advantage of voices, an engine should implement
the following methods:
onGetVoices()
onIsValidVoiceName(String)
onLoadVoice(String)
onGetDefaultVoiceNameFor(String, String, String)
onGetLanguage()
,
onIsLanguageAvailable(java.lang.String, java.lang.String, java.lang.String)
and onLoadLanguage(java.lang.String, java.lang.String, java.lang.String)
methods. The last one,
onGetDefaultVoiceNameFor(String, String, String)
is a link between locale and voice
based methods. Since API level 21 TextToSpeech.setLanguage(java.util.Locale)
is implemented by
calling TextToSpeech.setVoice(android.speech.tts.Voice)
with the voice returned by
onGetDefaultVoiceNameFor(String, String, String)
.
If the client uses a voice instead of a locale, SynthesisRequest
will contain the
requested voice name.
The default implementations of Voice-related methods implement them using the
pre-existing locale-based implementation.Service.StartArgFlags, Service.StartResult, Service.StopForegroundFlags
Context.BindServiceFlags, Context.CreatePackageOptions, Context.ServiceName
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY, START_TASK_REMOVED_COMPLETE, STOP_FOREGROUND_DETACH, STOP_FOREGROUND_REMOVE
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BACKUP_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_ALLOW_WHITELIST_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_FOREGROUND_SERVICE, BIND_FOREGROUND_SERVICE_WHILE_AWAKE, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_NOT_VISIBLE, BIND_SHOWING_UI, BIND_TREAT_LIKE_ACTIVITY, BIND_VISIBLE, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_CREDENTIAL_PROTECTED_STORAGE, CONTEXT_DEVICE_PROTECTED_STORAGE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_REGISTER_PACKAGE, CONTEXT_RESTRICTED, CONTEXTHUB_SERVICE, COUNTRY_DETECTOR, DEVICE_IDLE_CONTROLLER, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, ETHERNET_SERVICE, FINGERPRINT_SERVICE, GATEKEEPER_SERVICE, HARDWARE_PROPERTIES_SERVICE, HDMI_CONTROL_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_POLICY_SERVICE, NETWORK_SCORE_SERVICE, NETWORK_STATS_SERVICE, NETWORKMANAGEMENT_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, PERSISTENT_DATA_BLOCK_SERVICE, POWER_SERVICE, PRINT_SERVICE, RADIO_SERVICE, RECOVERY_SERVICE, RESTRICTIONS_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SERIAL_SERVICE, SHORTCUT_SERVICE, SIP_SERVICE, SOUND_TRIGGER_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TRUST_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, UPDATE_LOCK_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, VOICE_INTERACTION_MANAGER_SERVICE, WALLPAPER_SERVICE, WIFI_NAN_SERVICE, WIFI_P2P_SERVICE, WIFI_RTT_SERVICE, WIFI_SCANNING_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
Constructor and Description |
---|
TextToSpeechService() |
Modifier and Type | Method and Description |
---|---|
IBinder |
onBind(Intent intent)
Return the communication channel to the service.
|
void |
onCreate()
Called by the system when the service is first created.
|
void |
onDestroy()
Called by the system to notify a Service that it is no longer used and is being removed.
|
String |
onGetDefaultVoiceNameFor(String lang,
String country,
String variant)
Return a name of the default voice for a given locale.
|
protected Set<String> |
onGetFeaturesForLanguage(String lang,
String country,
String variant)
Queries the service for a set of features supported for a given language.
|
protected abstract String[] |
onGetLanguage()
Returns the language, country and variant currently being used by the TTS engine.
|
List<Voice> |
onGetVoices()
Queries the service for a set of supported voices.
|
protected abstract int |
onIsLanguageAvailable(String lang,
String country,
String variant)
Checks whether the engine supports a given language.
|
int |
onIsValidVoiceName(String voiceName)
Checks whether the engine supports a voice with a given name.
|
protected abstract int |
onLoadLanguage(String lang,
String country,
String variant)
Notifies the engine that it should load a speech synthesis language.
|
int |
onLoadVoice(String voiceName)
Notifies the engine that it should load a speech synthesis voice.
|
protected abstract void |
onStop()
Notifies the service that it should stop any in-progress speech synthesis.
|
protected abstract void |
onSynthesizeText(SynthesisRequest request,
SynthesisCallback callback)
Tells the service to synthesize speech from the given text.
|
attach, dump, getApplication, onConfigurationChanged, onLowMemory, onRebind, onStart, onStartCommand, onTaskRemoved, onTrimMemory, onUnbind, setForeground, startForeground, stopForeground, stopForeground, stopSelf, stopSelf, stopSelfResult
attachBaseContext, bindService, bindServiceAsUser, canStartActivityForResult, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, checkUriPermission, clearWallpaper, createApplicationContext, createConfigurationContext, createCredentialProtectedStorageContext, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createPackageContextAsUser, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getBasePackageName, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDir, getDisplay, getDisplayAdjustments, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSharedPreferences, getSharedPreferencesPath, getSystemService, getSystemServiceName, getTheme, getThemeResId, getUserId, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isCredentialProtectedStorage, isDeviceProtectedStorage, isRestricted, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiverAsUser, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendBroadcastAsUser, sendBroadcastMultiplePermissions, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendOrderedBroadcastAsUser, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivitiesAsUser, startActivity, startActivity, startActivityAsUser, startActivityAsUser, startActivityForResult, startInstrumentation, startIntentSender, startIntentSender, startService, startServiceAsUser, stopService, stopServiceAsUser, unbindService, unregisterReceiver
bindServiceAsUser, createCredentialEncryptedStorageContext, createDeviceEncryptedStorageContext, getColor, getColorStateList, getDrawable, getSharedPrefsFile, getString, getString, getSystemService, getText, isCredentialEncryptedStorage, isDeviceEncryptedStorage, migrateDatabaseFrom, migrateSharedPreferencesFrom, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
public void onCreate()
Service
public void onDestroy()
Service
protected abstract int onIsLanguageAvailable(String lang, String country, String variant)
lang
- ISO-3 language code.country
- ISO-3 country code. May be empty or null.variant
- Language variant. May be empty or null.TextToSpeech.LANG_AVAILABLE
,
TextToSpeech.LANG_COUNTRY_AVAILABLE
,
TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE
,
TextToSpeech.LANG_MISSING_DATA
TextToSpeech.LANG_NOT_SUPPORTED
.protected abstract String[] onGetLanguage()
""
. If country is empty, then variant must
be empty too.Locale.getISO3Language()
,
Locale.getISO3Country()
,
Locale.getVariant()
protected abstract int onLoadLanguage(String lang, String country, String variant)
lang
- ISO-3 language code.country
- ISO-3 country code. May be empty or null.variant
- Language variant. May be empty or null.TextToSpeech.LANG_AVAILABLE
,
TextToSpeech.LANG_COUNTRY_AVAILABLE
,
TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE
,
TextToSpeech.LANG_MISSING_DATA
TextToSpeech.LANG_NOT_SUPPORTED
.protected abstract void onStop()
protected abstract void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback)
TextToSpeech
). Called on the synthesis
thread.request
- The synthesis request.callback
- The callback that the engine must use to make data
available for playback or for writing to a file.protected Set<String> onGetFeaturesForLanguage(String lang, String country, String variant)
lang
- ISO-3 language code.country
- ISO-3 country code. May be empty or null.variant
- Language variant. May be empty or null.public List<Voice> onGetVoices()
onIsLanguageAvailable(String, String, String)
and create Voice instances (using
the locale's BCP-47 language tag as the voice name) for the ones that are supported.
Note, that this implementation is suitable only for engines that don't have multiple voices
for a single locale. Also, this implementation won't work with Locales not listed in the
set returned by the Locale.getAvailableLocales()
method.public String onGetDefaultVoiceNameFor(String lang, String country, String variant)
TextToSpeech.setLanguage(java.util.Locale)
, which calls this method and then calls
TextToSpeech.setVoice(android.speech.tts.Voice)
with the voice returned by this method.
Also, it's used by TextToSpeech.getDefaultVoice()
to find a default voice for
the default locale.lang
- ISO-3 language code.country
- ISO-3 country code. May be empty or null.variant
- Language variant. May be empty or null.public int onLoadVoice(String voiceName)
onLoadLanguage(String, String, String)
.voiceName
- Name of the voice.TextToSpeech.ERROR
or TextToSpeech.SUCCESS
.public int onIsValidVoiceName(String voiceName)
onIsLanguageAvailable(String, String, String)
.voiceName
- Name of the voice.TextToSpeech.ERROR
or TextToSpeech.SUCCESS
.public IBinder onBind(Intent intent)
Service
IBinder
is usually for a complex interface
that has been described using
aidl.
Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.
onBind
in class Service
intent
- The Intent that was used to bind to this service,
as given to Context.bindService
. Note that any extras that were included with
the Intent at that point will not be seen here.