Commit Graph

152 Commits

Author SHA1 Message Date
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
Narayan Kamath
e22b69a7de Make changes to the TTS api suggested by the API review.
This ended up making the implementation a lot cleaner
as well. See the bug listed below for some background.

bug:4553470
Change-Id: If16476a57e389c2f9b228f6548e426642d292b49
2011-06-08 16:46:00 +01:00
Narayan Kamath
8d1fc2403b Fix the threading behaviour of TTS audio requests.
All audio is played back on a separate thread.

Change-Id: I2bbb7b3140f6a04ef705cadb2bd1ae88951e3c48
2011-06-07 16:27:18 +01:00
Narayan Kamath
7a3af86dc0 Language loading / availablity should repsect defaults enforcement.
There is no point loading a language that will never be used.
It is in fact harmful, because the engine might load it and
then receive a request for the default voice and have to load
the default voice again.

Change-Id: I8082f28d15b6e325d6a39d439b66753711a2c244
2011-06-02 17:28:57 +01:00
Narayan Kamath
c90f1c815d Add a separate thread for writing to audiotracks.
Now, SynthesisRequest.audioAvailable( ) will not block
until all data has been written to the audiotrack.

Change-Id: Ie24c0b6873ae44659e88646fb7ef821750dc314e
2011-05-25 15:31:06 +01:00
Narayan Kamath
b956f37e37 Pass synthesis request params through to the TTS service.
Change-Id: I1ffd617d8dfa0814382643e3cf6b3ab7417c742a
2011-05-17 09:47:59 +01:00
Bjorn Bringert
4bbca889df Expose TTS engine API
This is a new API for writing text-to-speech engines.
The existing API for apps that use TTS remains the same,
with some minor additions.

Change-Id: Id577db449ae0e5baec40621d4a08387dbd755342
2011-04-27 08:25:24 +01:00
Narayan Kamath
53f6f95308 Fix onCompleteAudioAvailable
(a) Don't check that the audiotrack is initialized (will
not be true in static mode until the first write call)
(b) Block until it completes playing.

Change-Id: I50eb6cece00f3d12f3b75102d62014c360ac0346
2011-04-19 16:39:20 +01:00
Bjorn Bringert
a210e15c89 Merge "TTS: SynthesisRequest.error() instead of return value" 2011-04-19 03:06:13 -07:00
Bjorn Bringert
360eb168d6 TTS: SynthesisRequest.error() instead of return value
Change-Id: I02fe8ca1070a4e7c62ad30fd84c82bd6ecc2ecfa
2011-04-19 09:23:23 +01:00
Bjorn Bringert
fe6ea01602 Only return default TTS engines from TTS.getEngines()
Change-Id: I31a716a33c895d2a3349889046dce83c90704a2d
2011-04-18 20:27:40 +01:00
Bjorn Bringert
71e0b48077 Improve TTS engine audio buffer API
This adds two methods:
SynthesisRequest.getMaxBufferSize()
SynthesisRequest.completeAudioAvailable()

Change-Id: I1186eed45997ee9a7e51212c8d6706dd324ca949
2011-04-15 15:27:30 +01:00
Bjorn Bringert
50e657bb2d Add Java API for writing TTS engines
This removes the old non-public C++ API for TTS
engines and replaces it with a Java API.

The new API is still @hidden, until it has been approved.

Bug: 4148636
Change-Id: I7614ff788e11f897e87052f684f1b4938d539fb7
2011-04-15 10:04:31 +01:00
Joe Onorato
43a17654cf Remove the deprecated things from Config.java. These haven't been working since before 1.0.
Change-Id: Ic2e8fa68797ea9d486f4117f3d82c98233cdab1e
2011-04-07 19:23:05 -07:00
Mike LeBeau
216ce0f16e Add EXTRA_ORIGIN to RecognizerIntent.
This is for passing the http referer of a request, e.g., for speech
input from within a browser.

Bug: 4161306
Change-Id: I56fdb7466edd985aab6df8364be1f1619a11a00d
2011-04-05 16:38:24 -04:00
Mike LeBeau
bb7cf916b2 Support speech recognizer confidence values.
Pass speech recognizer confidence values in the SpeechRecognizer and
RecognizerIntent APIs through to the caller. This change defines new
API constants for keys to these values.

The corresponding change is being made to Google Voice Search, and should be
made to any other implementations.

Bug: 3267513
Bug: 4163206

Change-Id: I294553f2eb9eb3be21298b8434117c8c5309558d
2011-04-05 10:54:18 -04:00
Valentin Kravtsov
b18a047de5 am d35f9390: am 000466d7: am 125be9c8: Merge "Fixing a race condition in RecognitionService" into gingerbread
* commit 'd35f939010cb889d0e5d757f2e3f76c5b50b419a':
  Fixing a race condition in RecognitionService
2011-03-18 09:27:56 -07:00
Valentin Kravtsov
d35f939010 am 000466d7: am 125be9c8: Merge "Fixing a race condition in RecognitionService" into gingerbread
* commit '000466d79d33fa302c6c8d20d2db45faca7c31e0':
  Fixing a race condition in RecognitionService
2011-03-18 09:15:49 -07:00
Bjorn Bringert
2cad2cc153 Exception handling clean-up in TextToSpeech.java
This is just a code clean-up change. It should have no effects
on behavior.

- The exception clean-up code was copied in lots of places,
  added a restart() method for it.

- Use Log.e to print exception stack trace instead of doing
  it manually.

- Moved return statements outside finally-blocks. Having them
  in the finally-block makes no difference, but can be misleading.
  Also, Eclipse complains about it.

Change-Id: Ibfb18ca89d81d1fd8d212f29b6f8ab305b52ec49
2011-03-08 11:53:12 +00:00
Jean-Michel Trivi
708b47d1ec Fix bug 3511256 invalid TTS parameter cache size
The NB_CACHED_PARAMS is the number of cached parameters, not
 the size of the array for cached parameters.

Change-Id: I3d3053bbf247f3f89ae1ea07a931d33df7857a7c
2011-03-03 18:55:19 -08:00
Valentin Kravtsov
483701eb9f Fixing a race condition in RecognitionService
Bug #3458256

If an error occurs and simultaneously user cancels the recognition, here is what happens:
1. dispatchCancel() is called since the user requested cancel. It passes the first "if" successfully.

private void dispatchCancel(IRecognitionListener listener) {
       if (mCurrentCallback == null) {
           if (DBG) Log.d(TAG, "cancel called with no preceding startListening - ignoring");
       } else if (mCurrentCallback.mListener.asBinder() != listener.asBinder()) {
           Log.w(TAG, "cancel called by client who did not call startListening - ignoring");
       } else { // the correct state
           RecognitionService.this.onCancel(mCurrentCallback);
           mCurrentCallback = null;
           if (DBG) Log.d(TAG, "canceling - setting mCurrentCallback to null");
       }
   }

2. Error occurs in the app, which sets the mCurrentCallback to null:
       public void error(int error) throws RemoteException {
           mCurrentCallback = null;
           mListener.onError(error);
       }

3. the second "if" is reached in dispatchCancel()
4. boom

Change-Id: I54cdcc98b495d820a2caead1709d8dee968c461e
2011-03-02 10:16:28 +00:00
Jean-Michel Trivi
dc871fd870 resolved conflicts for merge of 3ebade5d to honeycomb-plus-aosp
Change-Id: Ifd5f88f75feeb2dad1131e6a262dff3b979bdf8d
2011-01-24 09:35:57 -08:00
Jean-Michel Trivi
1e13a02320 Bug 3365937 notify TTS initialization listener of binding errors
The creation of a TextToSpeech object causes the TTS service to
 start, and the initialization listener to be called when the
 service is connected. But the listener is never called when
 the service binding failed to be notified of this error.
The fix consists in checking the result of the bind to service
 operation, and notify the listener in case of an error.

More log was added in case speak() and synthesizeToFile() are
 called but the service is not known to have started.

Change-Id: I7dcc1fa44be31fee3177ec6215fca3306377b934
2011-01-20 17:25:48 -08:00
Jean-Michel Trivi
9011ec832d Fix bug 2084122: enable application control over text synth volume
This CL unhides two "keys" an application can use to specify for
 an utterance its playback volume and pan. Those two new keys
 use the same mechanism already in place for an application to
 specify stream type and utterance ID.

Change-Id: I020363487d7a0f471fb8d3ed739c561d2ab4b0a9
2011-01-11 13:42:44 -08:00
Jean-Michel Trivi
9d2d26af2e Add support in TTS for volume and panning control of the synth output
Add two new parameters that are used when synthesizing text and
 playing it back directly to control the volume and left-right
 panning of the output.
Panning is applied using a balance law, which is not energy-preserving
 but which doesn't lower the volume when not panning / panning to
 center (legacy behavior).

Reduced amount of logs, and removed spoken text.

In TextToSpeech.java: added convenience method to handle the setting
 of the cached synthesis parameters.

Change-Id: I235d3d3193283ccc1891e2065d43787e3f63304d
2011-01-05 16:24:30 -08:00
Mike LeBeau
19e353e722 am 0655b31d: am 12b82c8d: Merge "Unhide RecognizerResultsIntent. This API was reviewed for Froyo, but we didn\'t want to make it public then because it wasn\'t until our first Market release of Voice Search that the APIs would be in use by our app." into gingerbread
* commit '0655b31d758ce8fe054c98c6d288e424f2d273e2':
  Unhide RecognizerResultsIntent. This API was reviewed for Froyo, but we didn't want to make it public then because it wasn't until our first Market release of Voice Search that the APIs would be in use by our app.
2010-12-20 12:00:06 -08:00