Android TTS Volume Control

Is there a way to control the TTS engine capacity when sending a request for a TTS engine? Can I use AudioManager here?

Thank.

+3
source share
5 answers

Yes, as your question asks a question, you can use AudioManager for audio TTS.

If you want to set the volume in your code, you will want to use the getStreamVolume()and methods setStreamVolume().

If you want to give the user control over the volume (this may depend on how / when your program sets the volume), this question indicates what you should call setVolumeControlStream()in time OnCreate().

EDIT: , TTS (.. Speak() ).

+2

TTS speak(), API 11.

, api ( min sdk) "@TargetApi (api_level)" sdk.

/**  speak the single word, at a lower volume if possible */
protected void speakOneWord(String text) {
    int apiVer = android.os.Build.VERSION.SDK_INT;
    if (apiVer >= 11){
        speakApi13(text);
    } else {
        // compatibility mode
        HashMap<String, String> params = new HashMap<String, String>();
        mTts.speak(text, TextToSpeech.QUEUE_ADD, params);
    }
}   

/**  speak at a lower volume, for platform >= 13 */
@TargetApi(13)
protected void speakApi13(String text) {
    HashMap<String, String> params = new HashMap<String, String>();
    params.put(TextToSpeech.Engine.KEY_PARAM_VOLUME, "0.1");
    mTts.speak(text, TextToSpeech.QUEUE_ADD, params);
}   
+8

int iAlertVolume 0% 100%, .

setVolumeControlStream(AudioManager.STREAM_MUSIC);
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
int amStreamMusicMaxVol = am.getStreamMaxVolume(am.STREAM_MUSIC);
am.getStreamVolume(am.STREAM_MUSIC);

:

am.setStreamVolume(am.STREAM_MUSIC, (iAlertVolume*amStreamMusicMaxVol)/100,0 );

0 , , 1, ctrl

+1
source

speak() can now control the pace of TTS

added to API level 21

int speak (CharSequence text, 
                int queueMode, 
                Bundle: KEY_PARAM_VOLUME;..., 
                String utteranceId)

Parameter KEY_PARAM_VOLUMEto indicate the volume of speech relative to the current volume of the stream used when pronouncing the text.
The volume is set as a float from 0 to 1, where 0 is silence and 1 is the maximum volume (default behavior).

+1
source

Try this to manage your settings:

AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
sb2value =am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
am.setStreamVolume(AudioManager.STREAM_MUSIC, sb2value, 0);
0
source

Source: https://habr.com/ru/post/1782438/


All Articles