How could I use subprocess
instead of os
to run in Bash a command such as the following?:
import os
text = "~|||-:this is text:-|||~"
fileName = "sound.wav"
command =\
"IFS= read -d \'\' text <<EOF\n" +\
text + "\n" +\
"EOF\n" +\
"echo \"${text}\" | sed -e 's/\([[:punct:]]\)//g' | text2wave -scale 1 -o " + fileName
os.system(command)
Ideally, this would evaluate to the following in Bash:
IFS= read -d '' text <<EOF
~|||-:this is text:-|||~
EOF
echo "${text}" | sed -e 's/\([[:punct:]]\)//g' | text2wave -scale 1 -o sound.wav
Note that I am using both a here-document and multiple pipes in the command. I know that I don't need to have, say, the sed processing within the command, but I am trying specifically to see how such a command would be run in Bash using subprocess
.
At present, I have seen some implementations of 'pipes' in subprocess
command procedures, but these are very lengthy when compared to a simple vertical bar symbol. I could imagine the scenario becoming nightmarish with multiple pipes. As for here-documents, I have no idea how to implement them with subprocess
. I would value any guidance on implementing this that you might have.
The program text2wave is part of Festival, in case you're interested.