1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of 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, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.speech.tts; 18 19 import android.speech.tts.SynthesisCallback; 20 import android.speech.tts.SynthesisRequest; 21 import android.speech.tts.TextToSpeechService; 22 import android.util.Log; 23 24 import java.util.ArrayList; 25 import java.util.logging.Logger; 26 27 public class MockableTextToSpeechService extends TextToSpeechService { 28 29 private static IDelegate sDelegate; 30 setMocker(IDelegate delegate)31 public static void setMocker(IDelegate delegate) { 32 sDelegate = delegate; 33 } 34 getMocker()35 static IDelegate getMocker() { 36 return sDelegate; 37 } 38 39 @Override onIsLanguageAvailable(String lang, String country, String variant)40 protected int onIsLanguageAvailable(String lang, String country, String variant) { 41 return sDelegate.onIsLanguageAvailable(lang, country, variant); 42 } 43 44 @Override onGetLanguage()45 protected String[] onGetLanguage() { 46 return sDelegate.onGetLanguage(); 47 } 48 49 @Override onLoadLanguage(String lang, String country, String variant)50 protected int onLoadLanguage(String lang, String country, String variant) { 51 return sDelegate.onLoadLanguage(lang, country, variant); 52 } 53 54 @Override onStop()55 protected void onStop() { 56 sDelegate.onStop(); 57 } 58 59 @Override onSynthesizeText(SynthesisRequest request, SynthesisCallback callback)60 protected void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback) { 61 sDelegate.onSynthesizeText(request, callback); 62 } 63 64 public static interface IDelegate { onIsLanguageAvailable(String lang, String country, String variant)65 int onIsLanguageAvailable(String lang, String country, String variant); 66 onGetLanguage()67 String[] onGetLanguage(); 68 onLoadLanguage(String lang, String country, String variant)69 int onLoadLanguage(String lang, String country, String variant); 70 onStop()71 void onStop(); 72 onSynthesizeText(SynthesisRequest request, SynthesisCallback callback)73 void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback); 74 getAvailableVoices()75 ArrayList<String> getAvailableVoices(); 76 getUnavailableVoices()77 ArrayList<String> getUnavailableVoices(); 78 } 79 80 } 81