diff --git a/app/src/main/java/com/termux/api/TextToSpeechAPI.java b/app/src/main/java/com/termux/api/TextToSpeechAPI.java index de440d0e..a59db355 100644 --- a/app/src/main/java/com/termux/api/TextToSpeechAPI.java +++ b/app/src/main/java/com/termux/api/TextToSpeechAPI.java @@ -50,6 +50,20 @@ protected void onHandleIntent(final Intent intent) { final String speechEngine = intent.getStringExtra("engine"); final float speechPitch = intent.getFloatExtra("pitch", 1.0f); + int streamToUseInt = AudioManager.STREAM_NOTIFICATION; + String streamToUseString = intent.getStringExtra("stream"); + if (streamToUseString != null) { + switch (streamToUseString) { + case "NOTIFICATION": streamToUseInt = AudioManager.STREAM_NOTIFICATION; break; + case "ALARM": streamToUseInt = AudioManager.STREAM_ALARM; break; + case "MUSIC": streamToUseInt = AudioManager.STREAM_MUSIC; break; + case "RING": streamToUseInt = AudioManager.STREAM_RING; break; + case "SYSTEM": streamToUseInt = AudioManager.STREAM_SYSTEM; break; + case "VOICE_CALL": streamToUseInt = AudioManager.STREAM_VOICE_CALL; break; + } + } + final int streamToUse = streamToUseInt; + mTts = new TextToSpeech(this, new OnInitListener() { @Override public void onInit(int status) { @@ -133,7 +147,7 @@ public void onDone(String utteranceId) { String utteranceId = "utterance_id"; Bundle params = new Bundle(); - params.putInt(Engine.KEY_PARAM_STREAM, AudioManager.STREAM_NOTIFICATION); + params.putInt(Engine.KEY_PARAM_STREAM, streamToUse); params.putString(Engine.KEY_PARAM_UTTERANCE_ID, utteranceId); int submittedUtterances = 0;