Search code examples
bashespeak

capture bash script with espeak commands in audio file


I have a script that reads out text using espeak. the scripts reads out a line of text and then sleeps for a predefined time and the reads again and so on.

I would like to capture the output in an audiofile. However when using:

./script_name.sh -- stdout > audio

no audio goes into the file.

The script looks like this:

#!/bin/bash                                     
sleep   19                                      
        espeak  '   14  Pylon                       '
sleep   20                                      
        espeak  '   15  Gateway                     '
sleep   8                                       
        espeak  '   16  Assimilator                     '
sleep   38                                      
        espeak  '   20  Nexus   

What can I do to capture the espeak sound into a file?


Solution

  • you need to do it like this.

    sleep   19                                      
            espeak --stdout '   14  Pylon                       '
    sleep   20                                      
            espeak --stdout '   15  Gateway                     '
    sleep   8                                       
            espeak --stdout '   16  Assimilator                     '
    sleep   38                                      
            espeak --stdout '   20  Nexus   
    

    If you want stdout printing to be optional you can do:

    if [[ -n "$1" ]] && [[ "$1" == "--stdout" ]]; then
    sleep   19                                      
            espeak --stdout '   14  Pylon                       '
    sleep   20                                      
            espeak --stdout '   15  Gateway                     '
    sleep   8                                       
            espeak --stdout '   16  Assimilator                     '
    sleep   38                                      
            espeak --stdout '   20  Nexus  '
    else 
    sleep   19                                      
            espeak '   14  Pylon                       '
    sleep   20                                      
            espeak  '   15  Gateway                     '
    sleep   8                                       
            espeak  '   16  Assimilator                     '
    sleep   38                                      
            espeak  '   20  Nexus  '
    fi
    
    

    Then if you pass script.sh --stdout it will work.