Commit Graph

177 Commits

Author SHA1 Message Date
Przemyslaw Szczepaniak
70574efd8f Fix threading issue in BlockingAudioTrack.
This fixes the issue where one thread calls .stop() on
mAudioTrack that was released (or being released) by other thread.

Bug: 7029291
Change-Id: Ia6db803e8ee40379b63327acf578466127cfabcb
2012-08-28 02:19:20 -07:00
Przemyslaw Szczepaniak
091d56cab8 Fix double call to TTS connection disconnect() on reconnect
- Sets the service connection to null when unbindService is called,
instead of in onServiceDisconnected. This avoids a double disconnect
if a call to onServiceConnected is received before a call to
onServiceDisconnected.

- Extended synchronize on runAction error handling and reconnection.
This prevents from reconnecting N times if N>1 threads enter this method
while there's issue with TTS service.

Bug:6993880
Change-Id: I5a387622c6032a18d17fc072029ae6be1a9b8e6c
2012-08-20 08:56:39 -07:00
Narayan Kamath
9c3d7a888d Fixes to TextToSpeechService#synthesizeToFile
- Fixes a strict mode violation, defers file validity checks
  to when the engine starts synthesizing audio.
- Fixes some log spam when done() is called twice.

bug:6215680
bug:5415258
Change-Id: I4001be848b5208422d4091b7398e94ed311c649f
2012-08-14 08:38:26 -07:00
Narayan Kamath
ed4e541a20 Fix bug in BlockingAudioTrack.
Will be seen when createStreamingAudioTrack() returns null,
which will happen if the audioflinger / audiomanager are unhealthy.

Also removes some confusing synchronization from this class.

bug:6636401
Change-Id: Iaf68a305665b7bc973898145e9cd1563e2569a2b
2012-08-14 08:36:27 -07:00
Jean-Michel Trivi
482c9bb390 New action and extra in RecognizerIntent for "hands free" voice search
New action and extra for android.speech.RecognizerIntent:
  ACTION_VOICE_SEARCH_HANDS_FREE
  EXTRA_SECURE

Change-Id: I1f390ede4f4087bae1781347bb211dc0a093e857
2012-05-17 15:43:40 -07:00
Narayan Kamath
c60aad2a8a Write unit tests for android.speech.tts.
Change-Id: Ie5b3b4cdd13be2babee9a44bae00da179b372d12
2012-01-09 13:38:55 +00:00
Narayan Kamath
af802c6831 Remove BlockingMediaPlayer.
No need to spawn a new thread for every audio item sent to
the TTS class.

Change-Id: Ia52b0951f4249b0da460a5ecaff5dd11a6e5d5fc
2011-12-06 16:19:05 +00:00
Narayan Kamath
67ae6bc83c Simplify the implementation of AudioPlaybackHandler.
Now uses a queue of runnables, one per synthesis. Also
introduce an abstraction that wraps AudioTrack that implements
the blocking semantics that we desire.

bug:5680699

Change-Id: I34a1248ff05766a7d9b3002055fb5b24aa9f230b
2011-12-01 16:30:26 +00:00
Narayan Kamath
4f9787d6f4 am 7dfb3e61: am cc084f1d: Fix superfluous onError callbacks.
* commit '7dfb3e611a9b4db4ffadcaa18a833de083647159':
  Fix superfluous onError callbacks.
2011-11-30 10:51:10 -08:00
Narayan Kamath
cc084f1d73 Fix superfluous onError callbacks.
When stop() is called twice or after done().This relates
to bug 5662598 because users using the old deprecated API
will see two calls to onUtteranceCompleted.

bug:5662598
Change-Id: I5d59cf66b4f4c8650d3f8f9e503ac3f33132c0d0
2011-11-30 12:32:15 +00:00
Narayan Kamath
492b7f0d51 Allow multiple TextToSpeech instances per calling app.
We now use an IBinder object as an identity token of the
caller instead of Context#getPackageName.

bug:5680696
Change-Id: I1ca29e7161f709d2a85218206f3f117dfa620282
2011-11-30 10:42:03 +00:00
Narayan Kamath
68e2af55d6 Fix TTS instantiation from webview accessibility handlers.
The TTS instantiated from here shouldn't clobber any
existing TTS objects opened within the same package context.

Ideally, the TTS API should work fine with multiple TTS object
instances within the same package context but making that happen
correctly is a larger change.

bug:5659758
Change-Id: Ia1f63c61b9f12ac92ff42a427a004d414e42a759
2011-11-28 17:49:01 +00:00
Narayan Kamath
40f71f0be3 Fix regressions in TTS completion callbacks.
(a) onUtteranceCompleted should be called on errors too. Also,
fix up the error handling so that onUtteranceCompleted is
always called.
(b) Don't treat empty utterances as errors, and let the engine
synthesize them, as before.

bug:5662598
Change-Id: I9223592bc6fe5f47d71103f4f02f046b54a655a8
2011-11-24 17:32:12 +00:00
Narayan Kamath
754c72ed9e Notifiy callers when a speech synthesis error occurs.
bug:5589877
Change-Id: Ideca8966ea1caa6789b3273e388dd1f25c1e2758
2011-11-11 14:21:43 +00:00
Narayan Kamath
6c07a20285 Fix a bug in the network TTS api.
bug:5284966
Change-Id: I460bd12c27671ed42681fd4ccad567c08cb8f70f
2011-11-07 16:19:02 +00:00
Narayan Kamath
748af66ca2 Add an API for querying / enabling network TTS support.
bug:5284966
Change-Id: I01708f40bf0e975449125320dbcd4842210ca168
2011-11-02 19:37:52 +00:00
Narayan Kamath
563fd3ae1b Widen permissions on synthesized files.
When synthesized files are written to app private data dirs,
they are written with owner/grp set to the TTS engine and
are inaccessible by the app itself. This is a reported regression
from gingerbread behaviour. Note that the dir in which the
engine writes files is itself already world writable.

bug:5523587
Change-Id: I2cb26c6f3c3d9cb3cedd60fab32c99a85a27f4b1
2011-10-27 15:00:36 +01:00
Narayan Kamath
39268ffcb7 Format default locale the same way as those stored in prefs.
Also explicitly disallow locales with empty countries. This
is required to match them against the set of engine supported
locales.

bug:5309930
Change-Id: Ie9714fdc09d3081081a2393d97c31e3a42bca294
2011-10-17 14:37:40 +01:00
Narayan Kamath
a57f23837a Allow listeners to be set before the service connects.
bug:5408876
Change-Id: Ib7b2ad56c74e24cc84b55ce748053b80eb0f66e8
2011-10-04 17:20:09 +01:00
Narayan Kamath
69bc1b2696 Don't wait indefinitely for audio tracks to finish playing.
If the track doesn't make progress for a fixed amount of time,
bail.

bug:5309562
Change-Id: I76966b8b3b2f05ba577892899791a09f50a70107
2011-09-14 16:51:05 +01:00
Narayan Kamath
a65c62acab Fix two TTS bugs.
(a) Fix a null pointer exception, caused by a race condition
between stop / start calls.
(b) Fix a deadlock observed when multiple apps call stop() when
an item from one of those apps is currently being processed.

bug:5253061

Change-Id: I78533aecfda028588ce6aedb041009bc0a6f4620
2011-09-07 11:38:18 +01:00
Narayan Kamath
97171243f8 Change the heuristics for waiting for audiotracks to finish.
This is made necessary by a bug when the utterance is smaller
than the audio buffer size. In that case, we call stop() to
flush the audio to the mixer, but that causes the playstate to
be set to stopped though some audio is still being mixed. This
breaks our waiting loop.

We now wait a fixed amount of time for such short utterances
and do not observe the playback head position.

bug:5220048
Change-Id: Ic81dec751c1faca0b14164caeda6305c8f9815fe
2011-08-30 18:34:51 +01:00
Narayan Kamath
2a0518cd1d Don't allow TTS engines to synthesize too for ahead.
For each synthesis request, we inspect the number of
bytes of audio that have not been written to the mixer yet
and if that is above a certain threshold (currently 500ms),
we block the synthesis thread.

bug:5214603
Change-Id: I24c64c48466bdb96ce47b34cee7da2523ee5f0eb
2011-08-26 15:40:11 +01:00
Narayan Kamath
e5b8c4dfc7 Framework changes to support new TTS settings features.
Locale is now stored per engine, instead of as a global
option.

bug:5149036
Change-Id: I9848172623fe8aea1dd8e6678bca008da6a4cfb1
2011-08-23 10:20:42 +01:00
Narayan Kamath
84deb60cf1 Reduce the priority of the TTS thread.
It's at a very high priority currently - and will trump
foreground processes (and UI threads) which it shouldnt.

bug:5076001
Change-Id: I0d71c2941950782491ae31526a47ea6f97c38ffb
2011-07-27 13:22:09 +01:00
Narayan Kamath
673f360b0e Fix some AudioTrack related issues.
(a) Call stop() when we've written less than the
AudioTrack buffer. This forces pending buffers to
get mixed.

(b) Introduce a minimum sleep time to avoid spinlocks
if they system is busy

Change-Id: If70937e8b4e8c5d02d7dadc0d3086f97a10eb7ef
2011-07-21 13:06:28 +01:00
Narayan Kamath
a36cce06a6 Fix a threading issue in AudioPlaybackHandler
Never allow the AudioTrack to be observed in a state where
it is release()d but non null.

Change-Id: I1e5b61355f30c2aafcd55ecdf83077d7a9d99c66
2011-07-19 12:43:17 +01:00
Narayan Kamath
90e5650f96 Few minor TTS clean ups.
(a) Remove unnecessary null check.
(b) Remove unused function.
(c) Clean up for TextToSpeech#shutdown.

Change-Id: I3ec5bccc327437064da130634a14aaf7d48eca4d
2011-07-18 16:00:49 +01:00
Narayan Kamath
be4ad4ac66 Fix a few threading issues in the AudioPlaybackHandler.
Also fixes a bug where PlaybackSynthesisCallback would
continue to pump audio to the audio playback thread after
being stopped.

Change-Id: I3233eb4858245b6e7c7df72e241a0708c668f1b4
2011-07-18 12:01:30 +01:00
Narayan Kamath
c34f76fe89 Improve TextToSpeech#isSpeaking()
Query the audio playback thread to check if it's busy.

bug:5033910
Change-Id: Ie57c7776bac27c2e712ddad4ec50fb7d78ea82e7
2011-07-15 11:29:06 +01:00
Narayan Kamath
37ccb4b55d Merge "Remove the completeAudioAvailable API." 2011-07-15 02:56:31 -07:00
Narayan Kamath
c3da8818f0 Remove the completeAudioAvailable API.
Measurements have shown that the audio track in streaming mode
is pretty efficient as is, thanks to dalvik's JNI implementation.

Also, in streaming mode write( ) blocks until all data has been
copied to the mixer, which is the kind of behaviour we want so
that we don't have to explicitly block in our code. Also,
the java AudioTrack is thread-safe with respect to stop( ) calls
during write, which means we can do everything completeAudioAvailable
did, just as efficiently without it.

Change-Id: I70a8a108d94c7260676673979b5ea29f37fa5db4
2011-07-14 17:04:28 +01:00
Narayan Kamath
b9db1fb9de Minor cleanups to TextToSpeech.
(a) Fix an NPE reported when no TTS engine is installed.
(b) Fix a bad link, and some javadoc typos.

bug: 5004015
Change-Id: I38b97dbb5d7d4065a5ee408fae9138638ed48f40
2011-07-14 15:40:13 +01:00
Narayan Kamath
47d6288541 Wait until the audio track finishes playing before releasing it.
Release calls stop, which causes truncation of playback.
bug:5021056

Change-Id: I8eadcbf5622dab83be3c4dabfcc06629398f27ab
2011-07-13 13:59:45 +01:00
Narayan Kamath
6dabb63307 Add event-log logging for TTS requests.
Change-Id: I5023194c469a602b85259088a2e59373c96a941e
2011-07-08 17:55:25 +01:00
Narayan Kamath
9637198699 Minor changes to AudioTrack handling
Based on a discussion with the media folks.

Change-Id: I290cec062fcb53fccae1fd92387439448a54e81c
2011-07-05 15:46:53 +01:00
Narayan Kamath
bd2492e14e Expose the currently used engine to bundled apps.
This is required to fix a couple of niggles and annoyances
in the Settings app.

Change-Id: I0ad0c41744282b552e844ba9a2157cea74c64234
2011-06-27 18:35:47 +01:00
Narayan Kamath
4d03462b37 New API for TTS settings.
Engines must declare a <meta-data> attribute in their
manifest with name "android.speech.tts". This must reference
an XML resource as per
com.android.internal.R.styleable.TextToSpeechEngine.

Change-Id: I56a6b9f1a360174f98c9f39da901ade83d0f38a7
2011-06-21 10:28:30 +01:00
Narayan Kamath
edd12149f0 Merge "Don't enforce defaults any more in the TextToSpeech API." 2011-06-16 03:05:07 -07:00
Narayan Kamath
c3edf2a01a Don't enforce defaults any more in the TextToSpeech API.
This has been discussed in an email thread. This brings the
text to speech API in line with other android APIs.

The user can set default speech rates / languages and
engine preferences, which the API obeys BUT these can be
overriden by individual apps (much like intent.setComponent
and intent.setClassName can be used to launch a specific
handler for a given intent).

Also, all installed engines are enabled by default. The
user is shown the "data privacy" warning every time an
installed engine is set to the default.

Change-Id: I24f5f331b3a7cc7ce1a62962192e3a452bdca9d4
2011-06-16 10:31:45 +01:00
Narayan Kamath
9ee8154e59 Increase the visibility of SynthesisRequest
This makes it a lot easier for engine implementers
to test their engine. This is a dumb data object, and
contains no logic whatsoever.

Change-Id: I2a8bea134a8ff6b962508cfed67ea6085a682b23
2011-06-15 18:50:23 +01:00
Narayan Kamath
d0648ed060 Fix a bug in TextToSpeech.
Check that the requested engine is enabled.

Change-Id: I8436b0b7b7f441fe3473601fb9c46181e90750e0
2011-06-15 12:35:51 +01:00
Narayan Kamath
9a67f26184 Merge "A few TTS bug fixes" 2011-06-14 07:05:42 -07:00
Narayan Kamath
0e20fe5bab A few TTS bug fixes
(a) ensure that onInit is called exactly once per call to initTts().
(b) TtsEngines should never return an engine that is not installed.

Change-Id: Ic1ef63a9339e6d1050e3302445ca40d3ae481f61
2011-06-14 13:29:20 +01:00
Narayan Kamath
3f0363bb4b Deprecate setEngineByPackageName
This function does not let callers know when the TTS engine has
been initialized.

Change-Id: I17fcf3f95ad5bbdb9b787ba0846e6e63d424cd23
2011-06-14 12:28:45 +01:00
Narayan Kamath
d3ee2fa184 Refactor some of TextToSpeech
required to let the Settings code to the same logic
and not have to roll it's own.

Change-Id: I2766b8562c940182a2954555fb1854889c3ac91a
2011-06-10 16:33:28 +01:00
Narayan Kamath
a5084e6389 Merge "Don't hardcode the default engine." 2011-06-10 07:53:56 -07:00
Narayan Kamath
22302fb7ba Don't hardcode the default engine.
One point to note is that no TTS engine will be selected
by default if there are no system TTS engines.

Change-Id: I397061e3cf29b8a1c66e7864262b43621ef5100d
2011-06-10 15:29:06 +01:00
Narayan Kamath
abc63fbdda Some TTS fixes.
(a) Document the undocumented queue mode (mode == 2)
(b) intern strings to fix a bug in removeCallbacksAndMessages
(c) remove an unnecessarly lock object, change the field it
guarded to volatile.

Change-Id: If46bbfe2afb047b3ba5b3cb9a90c292656379ec1
2011-06-10 13:01:46 +01:00
Narayan Kamath
4924fe3867 Implement QUEUE_FLUSH and QUEUE_DESTROY addition modes.
Note that this change is slightly more flexible, it defines
a priority for each playback request. We needn't really throw
away synthesis requests from other apps. We could just play
them after higher priority ones (for e.g from talkback).

Change-Id: I6c7dd9abe4871e87da08d9aaa4c55225a69078e5
2011-06-09 16:42:16 +01:00