Reputation: 537
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')
Upvotes: 2
Views: 3030
Reputation: 39
Why not use commands.getoutput() instead?
import commands
def espeak(string):
output = 'espeak "%s"' % string
a = commands.getoutput(output)
espeak("Mario Balotelli")
Upvotes: 1
Reputation: 34543
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])
Upvotes: 2