Home | History | Annotate | Download | only in tts
      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 
     23 import java.util.ArrayList;
     24 
     25 public class MockableTextToSpeechService extends TextToSpeechService {
     26 
     27     private static IDelegate sDelegate;
     28 
     29     public static void setMocker(IDelegate delegate) {
     30         sDelegate = delegate;
     31     }
     32 
     33     static IDelegate getMocker() {
     34         return sDelegate;
     35     }
     36 
     37     @Override
     38     protected int onIsLanguageAvailable(String lang, String country, String variant) {
     39         return sDelegate.onIsLanguageAvailable(lang, country, variant);
     40     }
     41 
     42     @Override
     43     protected String[] onGetLanguage() {
     44         return sDelegate.onGetLanguage();
     45     }
     46 
     47     @Override
     48     protected int onLoadLanguage(String lang, String country, String variant) {
     49         return sDelegate.onLoadLanguage(lang, country, variant);
     50     }
     51 
     52     @Override
     53     protected void onStop() {
     54         sDelegate.onStop();
     55     }
     56 
     57     @Override
     58     protected void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback) {
     59         sDelegate.onSynthesizeText(request, callback);
     60     }
     61 
     62     public static interface IDelegate {
     63         int onIsLanguageAvailable(String lang, String country, String variant);
     64 
     65         String[] onGetLanguage();
     66 
     67         int onLoadLanguage(String lang, String country, String variant);
     68 
     69         void onStop();
     70 
     71         void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback);
     72 
     73         ArrayList<String> getAvailableVoices();
     74 
     75         ArrayList<String> getUnavailableVoices();
     76     }
     77 
     78 }
     79