Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [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 | |
| 18 | import android.os.ConditionVariable; |
Narayan Kamath | 754c72e | 2011-11-09 14:22:32 +0000 | [diff] [blame] | 19 | import android.speech.tts.TextToSpeechService.UtteranceProgressDispatcher; |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 20 | import android.util.Log; |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 21 | |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 22 | class SilencePlaybackQueueItem extends PlaybackQueueItem { |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 23 | private final ConditionVariable mCondVar = new ConditionVariable(); |
| 24 | private final long mSilenceDurationMs; |
| 25 | |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 26 | SilencePlaybackQueueItem(UtteranceProgressDispatcher dispatcher, |
Narayan Kamath | 492b7f0 | 2011-11-29 17:02:06 +0000 | [diff] [blame] | 27 | Object callerIdentity, long silenceDurationMs) { |
| 28 | super(dispatcher, callerIdentity); |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 29 | mSilenceDurationMs = silenceDurationMs; |
| 30 | } |
| 31 | |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 32 | @Override |
| 33 | public void run() { |
| 34 | getDispatcher().dispatchOnStart(); |
| 35 | if (mSilenceDurationMs > 0) { |
| 36 | mCondVar.block(mSilenceDurationMs); |
| 37 | } |
| 38 | getDispatcher().dispatchOnDone(); |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | @Override |
Narayan Kamath | 67ae6bc | 2011-11-30 14:51:00 +0000 | [diff] [blame] | 42 | void stop(boolean isError) { |
| 43 | mCondVar.open(); |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 44 | } |
Narayan Kamath | 8d1fc24 | 2011-06-03 18:11:54 +0100 | [diff] [blame] | 45 | } |