Auf Basis des pico2wave Sprachsynthesizers ist ein kleines Script entstanden mit dem markierte Texte, Textdateien, direkte Eingaben oder Terminalausgaben akustisch ausgeben werden können. Eine Standardkonfiguration wird beim ersten Scriptaufruf erstellt, sodass statische Parameter nicht immer wieder eingeben werden müssen. Die Ausgabe ist direkt als Audioausgabe oder als Datei möglich.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | #!/bin/bash # # name : tts.sh # desciption : text to speech syntheziser # req. packets : xsel libttspico-utils alsa-utils screen # autor : Speefak ( itoss@gmx.de ) # licence : (CC) BY-NC-SA # version : 2.0 # infosource : http://espeak.sourceforge.net/languages.html // # TODO set default tmpdir via script in config # TODO install missing packets via autoinstall request # TODO check tmpdir via parametecheck # TODO set option to clear selected text after output or cancel output # ############################################################################################################ ####################################### define global variables ######################################## ############################################################################################################ #------------------------------------------------------------------------------------------------------------ VERSION=2.0 RequiredPackets="xsel libttspico-utils alsa-utils screen" ConfigFile=$HOME/.tts.cfg TempDir="/tmp" TempFile="$TempDir/tts_audio_$(date +%F_%H:%M:%S).wav" LangInput=$(echo $@ | awk -F "-l=" '{printf $2}' | awk -F "-.=" '{printf $1}') AudioOutputModeInput=$(echo $@ | awk -F "-a=" '{printf $2}' | awk -F "-.=" '{printf $1}') Text=$(echo $@ | awk -F "-t=" '{printf $2}' | awk -F "-.=" '{printf $1}') #------------------------------------------------------------------------------------------------------------------------------------------------ ############################################################################################################ ########################################### define functions ########################################### ############################################################################################################ #------------------------------------------------------------------------------------------------------------------------------------------------ usage () { cat << USAGE text to speech version : $VERSION | script location $basename $0 Usage: $(basename $0) <options> ... ( $(basename $0) -l=us -a=direct -t="This is a test") Options are: -h, --help display help -v, --version display version -l, --listconfig show configuration -c, --configure create new default configuration -r, --reconfigure reconfigure default configuration -q, --quit audiooutput quit all audio output proccesses -l=<XX>, language languages: us,gb,de,es,fr,it -a=<XX>, audiooutput output modes: direct,file -t=<XX>, text input text input modes: file,select,"<text>" USAGE printf "\e[0;31m $1\e[0m\n\n"$(tput sgr0) exit } # echo -e " available options: -l=? => select language ( list languages ??-?? )" # echo -e " -d => audio output direct" # echo -e " -f => audio output file ( $HOME/$(date +%F)_pico2.wav)" # echo -e " -s => input text via text selection (select text for output)" # echo -e " -t => input text via file (-t/path/to/text/file)" # echo -e " -w => input text via direct input (-w='write some words')" # echo -e " -q => quit audio output" #------------------------------------------------------------------------------------------------------------------------------------------------ check_for_required_packets () { for Packet in $RequiredPackets ; do if [[ -z $(dpkg -l | grep ii | grep $Packet) ]] ;then usage "packet $Packet not found" MissingPackets=$(echo $MissingPackets) fi done printf " all required packets detected\n" } #------------------------------------------------------------------------------------------------------------------------------------------------ configure_dialog () { # create config file ConfigParameterList=$(cat $0 | grep -A25 "configure_dialog () {" | grep "read -e -p \" Enter" | awk -F " " '{print $NF}') # display Var input prompt and default value, enter/edit value printf "\n" read -e -p " Enter default language: " -i "de" Lang read -e -p " Enter default text input mode <select|file|direct>: " -i "direct" TextInput read -e -p " Enter default audio output mode <file|direct>: " -i "direct" AudioOutputMode read -e -p " Enter default audio output directory: " -i "$HOME/" AudioOutputDirectory read -e -p " Enter ramdisk usgae <yes|no>: " -i "yes" UseRamdisk # print new Vars printf "\n new configuration values: \n\n" for i in $ConfigParameterList; do echo " $i=\""$(eval echo $(echo "$"$i))\" done # check for existing config file if [[ -s $ConfigFile ]]; then printf "\n" read -e -p " overwrite existing configuration (y/n) " -i "y" OverwriteConfig if [[ $OverwriteConfig == [yY] ]]; then rm $ConfigFile else sed -i '/Reconfigure=true/d' $ConfigFile sed -i '/CreateNewConfig=true/d' $ConfigFile printf "\n existing configuration :\n\n" cat $ConfigFile exit fi fi # write vars to config file for i in $ConfigParameterList; do echo "$i=\""$(eval echo $(echo "$"$i))\" >> $ConfigFile done printf "\n configuration saved in: $ConfigFile\n" $0 exit } #------------------------------------------------------------------------------------------------------------ #create ramdisk create_ramdisk () { sudo mkdir /mnt/ramdisk sudo mount -t ramfs ramfs /mnt/ramdisk sudo chown -R $USER.$USER /mnt/ramdisk } #------------------------------------------------------------------------------------------------------------------------------------------------------- substitute_proccessing_vars () { # overwrite default values with input vars if defined Lang=${LangInput:-$Lang} AudioOutputMode=${AudioOutputModeInput:-$AudioOutputMode} # language vars Lang=${Lang/us/en-US} Lang=${Lang/gb/en-GB} Lang=${Lang/de/de-DE} Lang=${Lang/es/es-ES} Lang=${Lang/fr/fr-FR} Lang=${Lang/it/it-IT} } #------------------------------------------------------------------------------------------------------------------------------------------------------- ############################################################################################################ ############################################# start script ############################################# ############################################################################################################ #------------------------------------------------------------------------------------------------------------------------------------------------------- ############################################################################################################ ############################################# check config ############################################# ############################################################################################################ #------------------------------------------------------------------------------------------------------------------------------------------------------- if [[ -s $ConfigFile ]] && [[ -z $(cat $ConfigFile | grep "Reconfigure=true\|CreateNewConfig=true") ]]; then # read config file source $ConfigFile elif [[ -s $ConfigFile ]] && [[ -n $(cat $ConfigFile | grep "Reconfigure=true") ]]; then # read config and reconfigure source $ConfigFile configure_dialog elif [[ ! -s $ConfigFile ]] || [[ -n $(cat $ConfigFile | grep "CreateNewConfig=true") ]]; then # first run => check for dependencies ans create new config file check_for_required_packets configure_dialog fi #------------------------------------------------------------------------------------------------------------------------------------------------------- # processing options case "$1" in -[hv]) usage exit;; -l) cat $ConfigFile exit ;; -c) echo "CreateNewConfig=true" >> $ConfigFile $0 exit;; -r) echo "Reconfigure=true" >> $ConfigFile $0 exit;; -q) killall aplay exit;; esac #------------------------------------------------------------------------------------------------------------------------------------------------------- substitute_proccessing_vars "$@" #------------------------------------------------------------------------------------------------------------------------------------------------------- # check for ramdisk if [[ $UseRamdisk == OFFyes ]]; then create_ramdisk fi #------------------------------------------------------------------------------------------------------------------------------------------------------- # text input mode if [[ -f $Text ]];then Text=$(cat $Text) if [[ -z $Text ]];then usage "textfile empty" fi elif [[ $Text == select ]]; then Text=`xsel` if [[ -z $Text ]];then usage "please select text" fi fi #------------------------------------------------------------------------------------------------------------------------------------------------------- # parameter check if [[ -z $Text ]]; then usage "please enter text" elif [[ -z $Lang ]]; then usage "please enter language" elif [[ -z $TempFile ]]; then usage "please enter tempfile" fi #------------------------------------------------------------------------------------------------------------------------------------------------------- # proccesing text to audiooutput if [[ $AudioOutputMode == direct ]]; then pico2wave -l=$Lang -w$TempFile "$Text" && screen -dm aplay $TempFile # clear vars and files while [[ -n $(pgrep aplay) ]]; do sleep 1; done && xsel -c && rm $TempFile 2>/dev/null & elif [[ $AudioOutputMode == file ]]; then pico2wave -l=$Lang -w$TempFile "$Text" mv $TempFile $AudioOutputDirectory 2>/dev/null & printf "Audiofile created: $AudioOutputDirectory$(echo $TempFile | awk -F "/" '{print $NF}')\n" fi exit 0 |