Search code examples
androidaudiospeech-to-textgoogle-text-to-speech

Manually activate all audio playback


I have developed an app that uses text-to-speech and speech-to text functionality. Upon testing on different devices, I discovered that some devices had audio playback preferences that were not activated, and even though the main sound levels were on, the artificial speech engine was not being played back outloud. I went in and turned on all audio levels, and the problem was solved. So, I'm wondering if its possible to manually activate all sound levels on a device upon launching my application. Thanks!


Solution

  • try to do something like this, under onCreate method, at the beginning:

    AudioManager am = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    if(am.getStreamVolume(AudioManager.STREAM_MUSIC)==0)
    for(int i=0;i<5;i++) am.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
    

    This will raise the music volume from 0 to 5 segments (100% volume is 15 segments, unless in any particular ROM) for STREAM_MUSIC, the audio channel of every classic app!