Refine search
TextToSpeech tts = new TextToSpeech(this, this); tts.setLanguage(Locale.US); tts.speak("Text to say aloud", TextToSpeech.QUEUE_ADD, null);
@Test public void threeArgumentSpeak_withUtteranceId_shouldGetCallbackUtteranceId() throws Exception { textToSpeech.setOnUtteranceProgressListener(mockListener); HashMap<String, String> paramsMap = new HashMap<>(); paramsMap.put(Engine.KEY_PARAM_UTTERANCE_ID, "ThreeArgument"); textToSpeech.speak("Hello", TextToSpeech.QUEUE_FLUSH, paramsMap); Robolectric.flushForegroundThreadScheduler(); verify(mockListener).onStart("ThreeArgument"); verify(mockListener).onDone("ThreeArgument"); }
public class TTSActivity extends Activity implements OnInitListener, OnUtteranceCompletedListener, ... { private TextToSpeech mTts; ........... private void speak(String text) { if(text != null) { HashMap<String, String> myHashAlarm = new HashMap<String, String>(); myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM)); myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "SOME MESSAGE"); mTts.speak(text, TextToSpeech.QUEUE_FLUSH, myHashAlarm); } } // Fired after TTS initialization public void onInit(int status) { if(status == TextToSpeech.SUCCESS) { mTts.setOnUtteranceCompletedListener(this); } } // It's callback public void onUtteranceCompleted(String utteranceId) { Log.i(TAG, utteranceId); //utteranceId == "SOME MESSAGE" } ........... }
Intent checkTTSIntent = new Intent(); checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE); myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null); if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { myTTS = new TextToSpeech(this, this); Intent installTTSIntent = new Intent(); installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installTTSIntent); if(myTTS.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE) myTTS.setLanguage(Locale.US);
myTTS.setLanguage(Locale.US); readyToSpeak = true; Intent installIntent = new Intent(); installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); context.startActivity(installIntent); myTTS.speak(text, TextToSpeech.QUEUE_FLUSH, null);
if (text!=null && text.length()>0) { Toast.makeText(TtsActivity.this, "Saying: " + text, Toast.LENGTH_LONG).show(); tts.speak(text, TextToSpeech.QUEUE_ADD, null); Intent checkIntent = new Intent(); checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); startActivityForResult(checkIntent, MY_DATA_CHECK_CODE); if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { tts = new TextToSpeech(this, this); Intent installIntent = new Intent(); installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installIntent);
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_pt_br) { Locale locale = new Locale("pt","BR"); tts.setLanguage(locale); return true; } else if(id == R.id.action_en_us) { Locale locale = Locale.ENGLISH; tts.setLanguage(locale); return true; }else if (id == R.id.action_check_data) { // Verifica se o pacote de dados do TTS está instalado Intent checkIntent = new Intent(); checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); startActivityForResult(checkIntent, ACTION_CHECK_DATA_CODE); return true; } else if(id == R.id.action_install_data) { // Instala o pacote de dados Intent installIntent = new Intent(); installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installIntent); return true; } return super.onOptionsItemSelected(item); }
@Override public void onStatusChanged() { if (isSuspended && mTts != null) { synchronized (ttsQueue) { for (NotificationInfo info : ttsQueue.values()) { info.addIgnoreReason(IgnoreReason.SUSPENDED); } } mTts.stop(); } sendBroadcast(new Intent(getApplicationContext(), WidgetProvider.class) .setAction(WidgetProvider.ACTION_UPDATE)); } };
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == TTS_DATA_CHECK) { if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() { public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { ttsIsInit = true; if (tts.isLanguageAvailable(Locale.UK) >= 0) tts.setLanguage(Locale.UK); tts.setPitch(0.8f); tts.setSpeechRate(1.1f); speak(); } } }); } else { Intent installVoice = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installVoice); } } // Listing 14-3: Finding the results of a speech recognition request if (requestCode == VOICE_RECOGNITION && resultCode == RESULT_OK) { ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); float[] confidence = data.getFloatArrayExtra(RecognizerIntent.EXTRA_CONFIDENCE_SCORES); // TODO Do something with the recognized voice strings } }
textToSpeech = new TextToSpeech(this,this); HashMap<String, String> myHashRender = new HashMap<String, String>(); myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "completed"); textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, myHashRender); textToSpeech.stop(); textToSpeech.shutdown(); int result = textToSpeech.setLanguage(Locale.getDefault()); textToSpeech.setOnUtteranceCompletedListener(this); public void onUtteranceCompleted(String utteranceId){ Intent displayGuestMessageView = new Intent(InfoGreetView.this, GuestMessageView.class); startActivity(displayGuestMessageView);
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set up the text to speech to read the memos readMemo = new TextToSpeech(this, new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { /* Do nothing */ } }); // grab the memo index and memo text from the intent scrollPosition = getIntent().getIntExtra("scrollposition", -1); memoText = getIntent().getStringExtra("memotext"); }
super.onCreate(savedInstanceState); Intent startingIntent = this.getIntent(); msg = startingIntent.getStringExtra("MESSAGE"); tts = new TextToSpeech(this,this); super.onDestroy(); if (tts!=null) { tts.shutdown(); tts.speak(msg, TextToSpeech.QUEUE_FLUSH, null); tts.shutdown(); tts = null; finish();
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mFromAddress = getIntent().getExtras().getString(SMS_FROM_ADDRESS_EXTRA); mFromDisplayName = getIntent().getExtras().getString(SMS_FROM_DISPLAY_NAME_EXTRA); mMessage = getIntent().getExtras().getString(SMS_MESSAGE_EXTRA); mFullBodyString = String.format( getResources().getString(R.string.sms_speak_string_format), mFromDisplayName, mMessage); showDialog(DIALOG_SHOW_MESSAGE); mTts = new TextToSpeech(this, this); }
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(TextToSpeech.ACTION_TTS_QUEUE_PROCESSING_COMPLETED) && mTts != null) isSpeaking = true; if (delay > 0) { mTts.playSilence(delay, intQueueType, null); intQueueType = TextToSpeech.QUEUE_ADD; mTts.speak(sMessage, intQueueType, null); mTts.stop(); mTts.shutdown();
/** * Called by the system every time a client explicitly starts the service by calling startService(Intent), * providing the arguments it supplied and a unique integer token representing the start request. * Do not call this method directly. Starts the tts engine and grabs the string to speak. * * @param intent The Intent supplied to startService(Intent), as given. * @param flags Additional data about this start request. Currently either 0, START_FLAG_REDELIVERY, or * START_FLAG_RETRY. * @param startId A unique integer representing this specific request to start. Use with stopSelfResult(int). * @return START_NOT_STICKY since this service does a little work and then stops itself */ @Override public int onStartCommand(Intent intent, int flags, int startId) { mTts = new TextToSpeech(this, this); mTts.setOnUtteranceCompletedListener(this); mTextToSpeak = getString(intent.getIntExtra(TEXT_TO_SPEAK, 0)); assert getApplicationContext() != null; mAudioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); return START_NOT_STICKY; }
mTts = new TextToSpeech(this, this); public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { int result = mTts.setLanguage(Locale.US); if (result != TextToSpeech.LANG_MISSING_DATA && result != TextToSpeech.LANG_NOT_SUPPORTED) { mTts.speak(spokenText, TextToSpeech.QUEUE_FLUSH, null); public void onDestroy() { if (mTts != null) { mTts.stop(); mTts.shutdown();
try (JsonWriter writer = new JsonWriter(out)) { writer.setIndent(" "); String defaultEngineName = mTts.getDefaultEngine(); writer.beginArray(); for (EngineInfo info : mTts.getEngines()) { writer.beginObject(); writer.name("name").value(info.name); mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onStart(String utteranceId) { int setLanguageResult = mTts.setLanguage(getLocale(speechLanguage, speechRegion, speechVariant)); if (setLanguageResult != TextToSpeech.LANG_AVAILABLE) { TermuxApiLogger.error("tts.setLanguage('" + speechLanguage + "') returned " + setLanguageResult); mTts.setPitch(speechPitch); mTts.setSpeechRate(intent.getFloatExtra("rate", 1.0f)); if (!line.isEmpty()) { submittedUtterances++; mTts.speak(line, TextToSpeech.QUEUE_ADD, params, utteranceId);
TextToSpeech tts= new TextToSpeech(context, new OnInitListener() { @Override public void onInit(int status) { mTts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() { @Override public void onUtteranceCompleted(String utteranceId) { runOnUiThread(new Runnable() { @Override public void run() { //UI changes } }); } }); } }); HashMap<String, String> params = new HashMap<String, String>(); params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"stringId"); tts.speak("Text to Speak",TextToSpeech.QUEUE_FLUSH, params);