-1

I'm quite a beginner when it comes to programming so sorry if I get any of the terminology wrong.

I am trying to get text to speech to work for my AI programmed in python. At the moment I have got to a point where in python I have a text output, chosen from the user input. I have a sound output from CMD too which says what the user enters. However I want a way to connect the two... so I want to pass on the python text output to CMD where it will convert it to a sound output.

cmd:

   aws polly synthesize-speech ^
   --text-type text ^
   --text "**Hello World**" ^
   --output-format mp3 ^
   --voice-id Joey ^
   speech.mp3

python:

output = "Hello World"

essentially I want to pass that block of code from python to CMD, the output will change depending on the function run and user input.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
J Nowak
  • 17
  • 1
  • forgot to mention that I tried to use the subprocess module but struggled with entering commands from python. – J Nowak Mar 07 '17 at 17:37

1 Answers1

-1
cmd_start = '''aws polly synthesize-speech ^
   --text-type text ^
   --text "**'''
cmd_end = '''**" ^
   --output-format mp3 ^
   --voice-id Joey ^
   speech.mp3'''
cmd = cmd_start + output + cmd_end

That builds the command you want, neh?

Prune
  • 76,765
  • 14
  • 60
  • 81
  • I know how to do that. I want to forward that command you just typed in python to cmd. – J Nowak Mar 07 '17 at 18:05
  • Your question was specific to including the variable in the command. How do you forward anything else to this "CMD" entity in your work environment? Are you using the **os** or **subprocess** package? There is a variety of things called "CMD"; the ones *I* know best are the Linux and Windows command-line shells -- either is served with the same Python package. See [here](http://stackoverflow.com/questions/89228/calling-an-external-command-in-python) for more discussion. – Prune Mar 07 '17 at 18:10