Narayan Kamath | c60aad2 | 2011-12-06 16:40:03 +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"); |
| 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; |
Przemyslaw Szczepaniak | 4b73867 | 2014-11-19 17:36:57 +0000 | [diff] [blame] | 22 | import android.util.Log; |
Narayan Kamath | c60aad2 | 2011-12-06 16:40:03 +0000 | [diff] [blame] | 23 | |
| 24 | import java.util.ArrayList; |
Przemyslaw Szczepaniak | 4b73867 | 2014-11-19 17:36:57 +0000 | [diff] [blame] | 25 | import java.util.logging.Logger; |
Narayan Kamath | c60aad2 | 2011-12-06 16:40:03 +0000 | [diff] [blame] | 26 | |
| 27 | public class MockableTextToSpeechService extends TextToSpeechService { |
| 28 | |
| 29 | private static IDelegate sDelegate; |
| 30 | |
| 31 | public static void setMocker(IDelegate delegate) { |
| 32 | sDelegate = delegate; |
| 33 | } |
| 34 | |
| 35 | static IDelegate getMocker() { |
| 36 | return sDelegate; |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | protected int onIsLanguageAvailable(String lang, String country, String variant) { |
| 41 | return sDelegate.onIsLanguageAvailable(lang, country, variant); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | protected String[] onGetLanguage() { |
| 46 | return sDelegate.onGetLanguage(); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | protected int onLoadLanguage(String lang, String country, String variant) { |
| 51 | return sDelegate.onLoadLanguage(lang, country, variant); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | protected void onStop() { |
| 56 | sDelegate.onStop(); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | protected void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback) { |
| 61 | sDelegate.onSynthesizeText(request, callback); |
| 62 | } |
| 63 | |
| 64 | public static interface IDelegate { |
| 65 | int onIsLanguageAvailable(String lang, String country, String variant); |
| 66 | |
| 67 | String[] onGetLanguage(); |
| 68 | |
| 69 | int onLoadLanguage(String lang, String country, String variant); |
| 70 | |
| 71 | void onStop(); |
| 72 | |
| 73 | void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback); |
| 74 | |
| 75 | ArrayList<String> getAvailableVoices(); |
| 76 | |
| 77 | ArrayList<String> getUnavailableVoices(); |
| 78 | } |
| 79 | |
| 80 | } |