1 /* 2 * Copyright (C) 2019 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.car.assist.client.tts; 18 19 import android.content.Context; 20 import android.media.AudioAttributes; 21 import android.os.Bundle; 22 import android.speech.tts.TextToSpeech; 23 import android.speech.tts.UtteranceProgressListener; 24 25 /** 26 * Interface for TTS Engine that closely matches {@link TextToSpeech}; facilitates mocking/faking. 27 */ 28 public interface TextToSpeechEngine { 29 /** 30 * Initializes the TTS engine. 31 * 32 * @param context the context to use 33 * @param initListener listener to monitor initialization result 34 */ initialize(Context context, TextToSpeech.OnInitListener initListener)35 void initialize(Context context, TextToSpeech.OnInitListener initListener); 36 37 /** 38 * Returns true if the engine is initialized. 39 */ isInitialized()40 boolean isInitialized(); 41 42 /** 43 * Sets the UtteranceProgressListener. 44 * 45 * @see TextToSpeech#setOnUtteranceProgressListener(UtteranceProgressListener) 46 */ setOnUtteranceProgressListener(UtteranceProgressListener progressListener)47 void setOnUtteranceProgressListener(UtteranceProgressListener progressListener); 48 49 /** 50 * Sets the audio attributes to be used when speaking text or playing 51 * back a file. 52 * 53 * @see TextToSpeech#setAudioAttributes(AudioAttributes) 54 */ setAudioAttributes(AudioAttributes audioAttributes)55 void setAudioAttributes(AudioAttributes audioAttributes); 56 57 /** 58 * Speaks out the provided text. 59 * 60 * @see TextToSpeech#speak(CharSequence, int, Bundle, String) 61 */ speak(CharSequence text, int queueMode, Bundle params, String utteranceId)62 int speak(CharSequence text, int queueMode, Bundle params, String utteranceId); 63 64 /** 65 * Stops play-out. 66 * 67 * @see TextToSpeech#stop() 68 */ stop()69 void stop(); 70 71 /** 72 * Returns true if the TTS engine is currently playing out. 73 */ isSpeaking()74 boolean isSpeaking(); 75 76 /** 77 * Shuts down the engine and releases resources. 78 * {@link #initialize(Context, TextToSpeech.OnInitListener)} will need to be called again before 79 * using this engine. 80 */ shutdown()81 void shutdown(); 82 83 /** 84 * Returns the stream used by this TTS engine. 85 * <p/> 86 * The streams are defined in {@link android.media.AudioManager}. 87 */ getStream()88 int getStream(); 89 } 90