Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | * use this file except in compliance with the License. You may obtain a copy of |
| 6 | * the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations under |
| 14 | * the License. |
| 15 | */ |
| 16 | package android.speech.tts; |
| 17 | |
Narayan Kamath | 754c72e | 2011-11-09 14:22:32 +0000 | [diff] [blame] | 18 | import android.speech.tts.TextToSpeechService.UtteranceProgressDispatcher; |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 19 | import android.util.Log; |
| 20 | |
| 21 | /** |
| 22 | * Speech synthesis request that plays the audio as it is received. |
| 23 | */ |
Narayan Kamath | e22b69a | 2011-06-08 11:41:47 +0100 | [diff] [blame] | 24 | class PlaybackSynthesisCallback extends AbstractSynthesisCallback { |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 25 | |
| 26 | private static final String TAG = "PlaybackSynthesisRequest"; |
| 27 | private static final boolean DBG = false; |
| 28 | |
| 29 | private static final int MIN_AUDIO_BUFFER_SIZE = 8192; |
| 30 | |
| 31 | /** |
| 32 | * Audio stream type. Must be one of the STREAM_ contants defined in |
| 33 | * {@link android.media.AudioManager}. |
| 34 | */ |
| 35 | private final int mStreamType; |
| 36 | |
| 37 | /** |
| 38 | * Volume, in the range [0.0f, 1.0f]. The default value is |
| 39 | * {@link TextToSpeech.Engine#DEFAULT_VOLUME} (1.0f). |
| 40 | */ |
| 41 | private final float mVolume; |
| 42 | |
| 43 | /** |
| 44 | * Left/right position of the audio, in the range [-1.0f, 1.0f]. |
| 45 | * The default value is {@link TextToSpeech.Engine#DEFAULT_PAN} (0.0f). |
| 46 | */ |
| 47 | private final float mPan; |
| 48 | |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 49 | /** |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 50 | * Guards {@link #mAudioTrackHandler}, {@link #mItem} and {@link #mStopped}. |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 51 | */ |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 52 | private final Object mStateLock = new Object(); |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 53 | |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 54 | // Handler associated with a thread that plays back audio requests. |
| 55 | private final AudioPlaybackHandler mAudioTrackHandler; |
Narayan Kamath | c3da881 | 2011-07-01 10:13:54 +0100 | [diff] [blame] | 56 | // A request "token", which will be non null after start() has been called. |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 57 | private SynthesisPlaybackQueueItem mItem = null; |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 58 | |
| 59 | private volatile boolean mDone = false; |
| 60 | |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 61 | /** Status code of synthesis */ |
| 62 | protected int mStatusCode; |
| 63 | |
Narayan Kamath | 754c72e | 2011-11-09 14:22:32 +0000 | [diff] [blame] | 64 | private final UtteranceProgressDispatcher mDispatcher; |
Narayan Kamath | 492b7f0 | 2011-11-29 17:02:06 +0000 | [diff] [blame] | 65 | private final Object mCallerIdentity; |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 66 | private final AbstractEventLogger mLogger; |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 67 | |
Narayan Kamath | e22b69a | 2011-06-08 11:41:47 +0100 | [diff] [blame] | 68 | PlaybackSynthesisCallback(int streamType, float volume, float pan, |
Narayan Kamath | 754c72e | 2011-11-09 14:22:32 +0000 | [diff] [blame] | 69 | AudioPlaybackHandler audioTrackHandler, UtteranceProgressDispatcher dispatcher, |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 70 | Object callerIdentity, AbstractEventLogger logger, boolean clientIsUsingV2) { |
| 71 | super(clientIsUsingV2); |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 72 | mStreamType = streamType; |
| 73 | mVolume = volume; |
| 74 | mPan = pan; |
Narayan Kamath | c90f1c8 | 2011-05-24 11:39:43 +0100 | [diff] [blame] | 75 | mAudioTrackHandler = audioTrackHandler; |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 76 | mDispatcher = dispatcher; |
Narayan Kamath | 492b7f0 | 2011-11-29 17:02:06 +0000 | [diff] [blame] | 77 | mCallerIdentity = callerIdentity; |
Narayan Kamath | 6dabb63 | 2011-07-08 12:13:03 +0100 | [diff] [blame] | 78 | mLogger = logger; |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 79 | mStatusCode = TextToSpeechClient.Status.SUCCESS; |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | void stop() { |
| 84 | if (DBG) Log.d(TAG, "stop()"); |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 85 | |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 86 | SynthesisPlaybackQueueItem item; |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 87 | synchronized (mStateLock) { |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 88 | if (mDone) { |
| 89 | return; |
| 90 | } |
| 91 | if (mStatusCode == TextToSpeechClient.Status.STOPPED) { |
Narayan Kamath | 6dabb63 | 2011-07-08 12:13:03 +0100 | [diff] [blame] | 92 | Log.w(TAG, "stop() called twice"); |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 93 | return; |
Narayan Kamath | c90f1c8 | 2011-05-24 11:39:43 +0100 | [diff] [blame] | 94 | } |
Narayan Kamath | be4ad4a | 2011-07-15 13:01:09 +0100 | [diff] [blame] | 95 | |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 96 | item = mItem; |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 97 | mStatusCode = TextToSpeechClient.Status.STOPPED; |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 98 | } |
Narayan Kamath | 2a0518c | 2011-08-26 11:43:03 +0100 | [diff] [blame] | 99 | |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 100 | if (item != null) { |
Narayan Kamath | 2a0518c | 2011-08-26 11:43:03 +0100 | [diff] [blame] | 101 | // This might result in the synthesis thread being woken up, at which |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 102 | // point it will write an additional buffer to the item - but we |
Narayan Kamath | 2a0518c | 2011-08-26 11:43:03 +0100 | [diff] [blame] | 103 | // won't worry about that because the audio playback queue will be cleared |
| 104 | // soon after (see SynthHandler#stop(String). |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 105 | item.stop(TextToSpeechClient.Status.STOPPED); |
Narayan Kamath | 40f71f0 | 2011-11-23 16:42:53 +0000 | [diff] [blame] | 106 | } else { |
| 107 | // This happens when stop() or error() were called before start() was. |
| 108 | |
| 109 | // In all other cases, mAudioTrackHandler.stop() will |
| 110 | // result in onSynthesisDone being called, and we will |
| 111 | // write data there. |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 112 | mLogger.onCompleted(TextToSpeechClient.Status.STOPPED); |
| 113 | mDispatcher.dispatchOnStop(); |
Narayan Kamath | 2a0518c | 2011-08-26 11:43:03 +0100 | [diff] [blame] | 114 | } |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Bjorn Bringert | 71e0b48 | 2011-04-15 14:37:05 +0100 | [diff] [blame] | 117 | @Override |
| 118 | public int getMaxBufferSize() { |
| 119 | // The AudioTrack buffer will be at least MIN_AUDIO_BUFFER_SIZE, so that should always be |
| 120 | // a safe buffer size to pass in. |
| 121 | return MIN_AUDIO_BUFFER_SIZE; |
| 122 | } |
| 123 | |
Bjorn Bringert | 360eb16 | 2011-04-19 09:20:35 +0100 | [diff] [blame] | 124 | @Override |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 125 | public boolean hasStarted() { |
| 126 | synchronized (mStateLock) { |
| 127 | return mItem != null; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public boolean hasFinished() { |
| 133 | synchronized (mStateLock) { |
| 134 | return mDone; |
| 135 | } |
Bjorn Bringert | 360eb16 | 2011-04-19 09:20:35 +0100 | [diff] [blame] | 136 | } |
| 137 | |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 138 | @Override |
| 139 | public int start(int sampleRateInHz, int audioFormat, int channelCount) { |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 140 | if (DBG) Log.d(TAG, "start(" + sampleRateInHz + "," + audioFormat + "," + channelCount |
| 141 | + ")"); |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 142 | |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 143 | int channelConfig = BlockingAudioTrack.getChannelConfig(channelCount); |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 144 | |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 145 | synchronized (mStateLock) { |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 146 | if (channelConfig == 0) { |
| 147 | Log.e(TAG, "Unsupported number of channels :" + channelCount); |
| 148 | mStatusCode = TextToSpeechClient.Status.ERROR_OUTPUT; |
| 149 | return TextToSpeech.ERROR; |
| 150 | } |
| 151 | if (mStatusCode == TextToSpeechClient.Status.STOPPED) { |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 152 | if (DBG) Log.d(TAG, "stop() called before start(), returning."); |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 153 | return errorCodeOnStop(); |
| 154 | } |
| 155 | if (mStatusCode != TextToSpeechClient.Status.SUCCESS) { |
| 156 | if (DBG) Log.d(TAG, "Error was raised"); |
| 157 | return TextToSpeech.ERROR; |
| 158 | } |
| 159 | if (mItem != null) { |
| 160 | Log.e(TAG, "Start called twice"); |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 161 | return TextToSpeech.ERROR; |
| 162 | } |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 163 | SynthesisPlaybackQueueItem item = new SynthesisPlaybackQueueItem( |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 164 | mStreamType, sampleRateInHz, audioFormat, channelCount, mVolume, mPan, |
Narayan Kamath | 492b7f0 | 2011-11-29 17:02:06 +0000 | [diff] [blame] | 165 | mDispatcher, mCallerIdentity, mLogger); |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 166 | mAudioTrackHandler.enqueue(item); |
| 167 | mItem = item; |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | return TextToSpeech.SUCCESS; |
| 171 | } |
| 172 | |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 173 | @Override |
| 174 | public int audioAvailable(byte[] buffer, int offset, int length) { |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 175 | if (DBG) Log.d(TAG, "audioAvailable(byte[" + buffer.length + "]," + offset + "," + length |
| 176 | + ")"); |
| 177 | |
Narayan Kamath | c90f1c8 | 2011-05-24 11:39:43 +0100 | [diff] [blame] | 178 | if (length > getMaxBufferSize() || length <= 0) { |
| 179 | throw new IllegalArgumentException("buffer is too large or of zero length (" + |
| 180 | + length + " bytes)"); |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 181 | } |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 182 | |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 183 | SynthesisPlaybackQueueItem item = null; |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 184 | synchronized (mStateLock) { |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 185 | if (mItem == null) { |
| 186 | mStatusCode = TextToSpeechClient.Status.ERROR_OUTPUT; |
Narayan Kamath | c90f1c8 | 2011-05-24 11:39:43 +0100 | [diff] [blame] | 187 | return TextToSpeech.ERROR; |
| 188 | } |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 189 | if (mStatusCode != TextToSpeechClient.Status.SUCCESS) { |
| 190 | if (DBG) Log.d(TAG, "Error was raised"); |
| 191 | return TextToSpeech.ERROR; |
| 192 | } |
| 193 | if (mStatusCode == TextToSpeechClient.Status.STOPPED) { |
| 194 | return errorCodeOnStop(); |
| 195 | } |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 196 | item = mItem; |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 197 | } |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 198 | |
Narayan Kamath | 2a0518c | 2011-08-26 11:43:03 +0100 | [diff] [blame] | 199 | // Sigh, another copy. |
| 200 | final byte[] bufferCopy = new byte[length]; |
| 201 | System.arraycopy(buffer, offset, bufferCopy, 0, length); |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 202 | |
| 203 | // Might block on mItem.this, if there are too many buffers waiting to |
Narayan Kamath | 2a0518c | 2011-08-26 11:43:03 +0100 | [diff] [blame] | 204 | // be consumed. |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 205 | try { |
| 206 | item.put(bufferCopy); |
| 207 | } catch (InterruptedException ie) { |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 208 | synchronized (mStateLock) { |
| 209 | mStatusCode = TextToSpeechClient.Status.ERROR_OUTPUT; |
| 210 | return TextToSpeech.ERROR; |
| 211 | } |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 212 | } |
Narayan Kamath | 2a0518c | 2011-08-26 11:43:03 +0100 | [diff] [blame] | 213 | |
Narayan Kamath | 6dabb63 | 2011-07-08 12:13:03 +0100 | [diff] [blame] | 214 | mLogger.onEngineDataReceived(); |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 215 | return TextToSpeech.SUCCESS; |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public int done() { |
| 220 | if (DBG) Log.d(TAG, "done()"); |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 221 | |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 222 | int statusCode = 0; |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 223 | SynthesisPlaybackQueueItem item = null; |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 224 | synchronized (mStateLock) { |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 225 | if (mDone) { |
| 226 | Log.w(TAG, "Duplicate call to done()"); |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 227 | // Not an error that would prevent synthesis. Hence no |
| 228 | // setStatusCode |
Narayan Kamath | c90f1c8 | 2011-05-24 11:39:43 +0100 | [diff] [blame] | 229 | return TextToSpeech.ERROR; |
| 230 | } |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 231 | if (mStatusCode == TextToSpeechClient.Status.STOPPED) { |
| 232 | if (DBG) Log.d(TAG, "Request has been aborted."); |
| 233 | return errorCodeOnStop(); |
| 234 | } |
Bjorn Bringert | 360eb16 | 2011-04-19 09:20:35 +0100 | [diff] [blame] | 235 | mDone = true; |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 236 | |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 237 | if (mItem == null) { |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 238 | // .done() was called before .start. Treat it as successful synthesis |
| 239 | // for a client, despite service bad implementation. |
| 240 | Log.w(TAG, "done() was called before start() call"); |
| 241 | if (mStatusCode == TextToSpeechClient.Status.SUCCESS) { |
| 242 | mDispatcher.dispatchOnSuccess(); |
| 243 | } else { |
| 244 | mDispatcher.dispatchOnError(mStatusCode); |
| 245 | } |
| 246 | mLogger.onEngineComplete(); |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 247 | return TextToSpeech.ERROR; |
| 248 | } |
| 249 | |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 250 | item = mItem; |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 251 | statusCode = mStatusCode; |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 252 | } |
Narayan Kamath | 2a0518c | 2011-08-26 11:43:03 +0100 | [diff] [blame] | 253 | |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 254 | // Signal done or error to item |
| 255 | if (statusCode == TextToSpeechClient.Status.SUCCESS) { |
| 256 | item.done(); |
| 257 | } else { |
| 258 | item.stop(statusCode); |
| 259 | } |
Narayan Kamath | 2a0518c | 2011-08-26 11:43:03 +0100 | [diff] [blame] | 260 | mLogger.onEngineComplete(); |
Bjorn Bringert | 50e657b | 2011-03-08 16:00:40 +0000 | [diff] [blame] | 261 | return TextToSpeech.SUCCESS; |
| 262 | } |
Bjorn Bringert | 71e0b48 | 2011-04-15 14:37:05 +0100 | [diff] [blame] | 263 | |
| 264 | @Override |
Bjorn Bringert | 360eb16 | 2011-04-19 09:20:35 +0100 | [diff] [blame] | 265 | public void error() { |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 266 | error(TextToSpeechClient.Status.ERROR_SYNTHESIS); |
Bjorn Bringert | 360eb16 | 2011-04-19 09:20:35 +0100 | [diff] [blame] | 267 | } |
| 268 | |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 269 | @Override |
| 270 | public void error(int errorCode) { |
| 271 | if (DBG) Log.d(TAG, "error() [will call stop]"); |
| 272 | synchronized (mStateLock) { |
| 273 | if (mDone) { |
| 274 | return; |
| 275 | } |
| 276 | mStatusCode = errorCode; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | @Override |
| 281 | public int fallback() { |
| 282 | synchronized (mStateLock) { |
| 283 | if (hasStarted() || hasFinished()) { |
| 284 | return TextToSpeech.ERROR; |
| 285 | } |
| 286 | |
| 287 | mDispatcher.dispatchOnFallback(); |
| 288 | mStatusCode = TextToSpeechClient.Status.SUCCESS; |
| 289 | return TextToSpeechClient.Status.SUCCESS; |
| 290 | } |
| 291 | } |
Narayan Kamath | 53f6f95 | 2011-04-19 16:39:20 +0100 | [diff] [blame] | 292 | } |