2

I am using the espeak library for text to speech conversion.I am able to generate a dynmic sound from a string to do this.

os.system('espeak "hello"')

This works. But what i need is to generate sound from a string. This is what i did

string='hello'
os.system('espeak string')
slaveCoder
  • 519
  • 2
  • 17
  • 46

2 Answers2

2

Just interpolate the string that you want to speak into your command.

>>> string = "Hello"
>>> os.system('espeak "{}"'.format(string))

You could use the subprocess.Popen function if you are accepting user input for the string.

>>> import subprocess
>>> p = subprocess.Popen(['espeak', string])
Sukrit Kalra
  • 33,167
  • 7
  • 69
  • 71
1

Why not use commands.getoutput() instead?

import commands

def espeak(string):
    output = 'espeak "%s"' % string
    a = commands.getoutput(output)


espeak("Mario Balotelli")