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 19 /** 20 * Defines additional methods the synthesis callback must implement that 21 * are private to the TTS service implementation. 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. 27 */ 28 abstract class AbstractSynthesisCallback implements SynthesisCallback { 29 /** If true, request comes from V2 TTS interface */ 30 protected final boolean mClientIsUsingV2; 31 32 /** 33 * Constructor. 34 * @param clientIsUsingV2 If true, this callback will be used inside 35 * {@link TextToSpeechService#onSynthesizeTextV2} method. 36 */ AbstractSynthesisCallback(boolean clientIsUsingV2)37 AbstractSynthesisCallback(boolean clientIsUsingV2) { 38 mClientIsUsingV2 = clientIsUsingV2; 39 } 40 41 /** 42 * Aborts the speech request. 43 * 44 * Can be called from multiple threads. 45 */ stop()46 abstract void stop(); 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 */ errorCodeOnStop()56 int errorCodeOnStop() { 57 return mClientIsUsingV2 ? TextToSpeech.STOPPED : TextToSpeech.ERROR; 58 } 59 } 60