Narayan Kamath | e22b69a | 2011-06-08 11:41:47 +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 | |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 18 | |
Narayan Kamath | e22b69a | 2011-06-08 11:41:47 +0100 | [diff] [blame] | 19 | /** |
| 20 | * Defines additional methods the synthesis callback must implement that |
| 21 | * are private to the TTS service implementation. |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 22 | * |
| 23 | * All of these class methods (with the exception of {@link #stop()}) can be only called on the |
| 24 | * synthesis thread, while inside |
| 25 | * {@link TextToSpeechService#onSynthesizeText} or {@link TextToSpeechService#onSynthesizeTextV2}. |
| 26 | * {@link #stop()} is the exception, it may be called from multiple threads. |
Narayan Kamath | e22b69a | 2011-06-08 11:41:47 +0100 | [diff] [blame] | 27 | */ |
| 28 | abstract class AbstractSynthesisCallback implements SynthesisCallback { |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 29 | /** If true, request comes from V2 TTS interface */ |
| 30 | protected final boolean mClientIsUsingV2; |
| 31 | |
Narayan Kamath | e22b69a | 2011-06-08 11:41:47 +0100 | [diff] [blame] | 32 | /** |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 33 | * Constructor. |
| 34 | * @param clientIsUsingV2 If true, this callback will be used inside |
| 35 | * {@link TextToSpeechService#onSynthesizeTextV2} method. |
Narayan Kamath | e22b69a | 2011-06-08 11:41:47 +0100 | [diff] [blame] | 36 | */ |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 37 | AbstractSynthesisCallback(boolean clientIsUsingV2) { |
| 38 | mClientIsUsingV2 = clientIsUsingV2; |
| 39 | } |
Narayan Kamath | e22b69a | 2011-06-08 11:41:47 +0100 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Aborts the speech request. |
| 43 | * |
| 44 | * Can be called from multiple threads. |
| 45 | */ |
| 46 | abstract void stop(); |
Przemyslaw Szczepaniak | 90d15d2 | 2013-06-14 12:02:53 +0100 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Get status code for a "stop". |
| 50 | * |
| 51 | * V2 Clients will receive special status, V1 clients will receive standard error. |
| 52 | * |
| 53 | * This method should only be called on the synthesis thread, |
| 54 | * while in {@link TextToSpeechService#onSynthesizeText}. |
| 55 | */ |
| 56 | int errorCodeOnStop() { |
| 57 | return mClientIsUsingV2 ? TextToSpeechClient.Status.STOPPED : TextToSpeech.ERROR; |
| 58 | } |
Narayan Kamath | e22b69a | 2011-06-08 11:41:47 +0100 | [diff] [blame] | 59 | } |