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 android.speech.tts;
     18 
     19 import android.net.Uri;
     20 import android.os.Bundle;
     21 import android.os.ParcelFileDescriptor;
     22 import android.speech.tts.ITextToSpeechCallback;
     23 
     24 /**
     25  * Interface for TextToSpeech to talk to TextToSpeechService.
     26  *
     27  * {@hide}
     28  */
     29 interface ITextToSpeechService {
     30 
     31     /**
     32      * Tells the engine to synthesize some speech and play it back.
     33      *
     34      * @param callingInstance a binder representing the identity of the calling
     35      *        TextToSpeech object.
     36      * @param text The text to synthesize.
     37      * @param queueMode Determines what to do to requests already in the queue.
     38      * @param param Request parameters.
     39      */
     40     int speak(in IBinder callingInstance, in String text, in int queueMode, in Bundle params);
     41 
     42     /**
     43      * Tells the engine to synthesize some speech and write it to a file.
     44      *
     45      * @param callingInstance a binder representing the identity of the calling
     46      *        TextToSpeech object.
     47      * @param text The text to synthesize.
     48      * @param fileDescriptor The file descriptor to write the synthesized audio to. Has to be
     49               writable.
     50      * @param param Request parameters.
     51      */
     52     int synthesizeToFileDescriptor(in IBinder callingInstance, in String text,
     53         in ParcelFileDescriptor fileDescriptor, in Bundle params);
     54 
     55     /**
     56      * Plays an existing audio resource.
     57      *
     58      * @param callingInstance a binder representing the identity of the calling
     59      *        TextToSpeech object.
     60      * @param audioUri URI for the audio resource (a file or android.resource URI)
     61      * @param queueMode Determines what to do to requests already in the queue.
     62      * @param param Request parameters.
     63      */
     64     int playAudio(in IBinder callingInstance, in Uri audioUri, in int queueMode, in Bundle params);
     65 
     66     /**
     67      * Plays silence.
     68      *
     69      * @param callingInstance a binder representing the identity of the calling
     70      *        TextToSpeech object.
     71      * @param duration Number of milliseconds of silence to play.
     72      * @param queueMode Determines what to do to requests already in the queue.
     73      * @param param Request parameters.
     74      */
     75     int playSilence(in IBinder callingInstance, in long duration, in int queueMode, in Bundle params);
     76 
     77     /**
     78      * Checks whether the service is currently playing some audio.
     79      */
     80     boolean isSpeaking();
     81 
     82     /**
     83      * Interrupts the current utterance (if from the given app) and removes any utterances
     84      * in the queue that are from the given app.
     85      *
     86      * @param callingInstance a binder representing the identity of the calling
     87      *        TextToSpeech object.
     88      */
     89     int stop(in IBinder callingInstance);
     90 
     91     /**
     92      * Returns the language, country and variant currently being used by the TTS engine.
     93      *
     94      * Can be called from multiple threads.
     95      *
     96      * @return A 3-element array, containing language (ISO 3-letter code),
     97      *         country (ISO 3-letter code) and variant used by the engine.
     98      *         The country and variant may be {@code ""}. If country is empty, then variant must
     99      *         be empty too.
    100      */
    101     String[] getLanguage();
    102 
    103     /**
    104      * Returns a default TTS language, country and variant as set by the user.
    105      *
    106      * Can be called from multiple threads.
    107      *
    108      * @return A 3-element array, containing language (ISO 3-letter code),
    109      *         country (ISO 3-letter code) and variant used by the engine.
    110      *         The country and variant may be {@code ""}. If country is empty, then variant must
    111      *         be empty too.
    112      */
    113     String[] getClientDefaultLanguage();
    114 
    115     /**
    116      * Checks whether the engine supports a given language.
    117      *
    118      * @param lang ISO-3 language code.
    119      * @param country ISO-3 country code. May be empty or null.
    120      * @param variant Language variant. May be empty or null.
    121      * @return Code indicating the support status for the locale.
    122      *         One of {@link TextToSpeech#LANG_AVAILABLE},
    123      *         {@link TextToSpeech#LANG_COUNTRY_AVAILABLE},
    124      *         {@link TextToSpeech#LANG_COUNTRY_VAR_AVAILABLE},
    125      *         {@link TextToSpeech#LANG_MISSING_DATA}
    126      *         {@link TextToSpeech#LANG_NOT_SUPPORTED}.
    127      */
    128     int isLanguageAvailable(in String lang, in String country, in String variant);
    129 
    130     /**
    131      * Returns a list of features available for a given language. Elements of the returned
    132      * string array can be passed in as keys to {@link TextToSpeech#speak} and
    133      * {@link TextToSpeech#synthesizeToFile} to select a given feature or features to be
    134      * used during synthesis.
    135      *
    136      * @param lang ISO-3 language code.
    137      * @param country ISO-3 country code. May be empty or null.
    138      * @param variant Language variant. May be empty or null.
    139      * @return An array of strings containing the set of features supported for
    140      *         the supplied locale. The array of strings must not contain
    141      *         duplicates.
    142      */
    143     String[] getFeaturesForLanguage(in String lang, in String country, in String variant);
    144 
    145     /**
    146      * Notifies the engine that it should load a speech synthesis language.
    147      *
    148      * @param caller a binder representing the identity of the calling
    149      *        TextToSpeech object.
    150      * @param lang ISO-3 language code.
    151      * @param country ISO-3 country code. May be empty or null.
    152      * @param variant Language variant. May be empty or null.
    153      * @return Code indicating the support status for the locale.
    154      *         One of {@link TextToSpeech#LANG_AVAILABLE},
    155      *         {@link TextToSpeech#LANG_COUNTRY_AVAILABLE},
    156      *         {@link TextToSpeech#LANG_COUNTRY_VAR_AVAILABLE},
    157      *         {@link TextToSpeech#LANG_MISSING_DATA}
    158      *         {@link TextToSpeech#LANG_NOT_SUPPORTED}.
    159      */
    160     int loadLanguage(in IBinder caller, in String lang, in String country, in String variant);
    161 
    162     /**
    163      * Sets the callback that will be notified when playback of utterance from the
    164      * given app are completed.
    165      *
    166      * @param caller Instance a binder representing the identity of the calling
    167      *        TextToSpeech object.
    168      * @param cb The callback.
    169      */
    170     void setCallback(in IBinder caller, ITextToSpeechCallback cb);
    171 
    172 }
    173