我正在使用espeak库进行文本到语音转换。我可以从字符串中生成一个动态声音来实现这一点。
os.system('espeak "hello"')
这工作。但是我需要的是从字符串中生成声音。这就是我所做的
string='hello'
os.system('espeak string')
只需在命令中插入您想要输入的字符串。
>>> string = "Hello"
>>> os.system('espeak "{}"'.format(string))
如果您接受用户输入字符串,则可以使用subprocess.Popen
函数。
>>> import subprocess
>>> p = subprocess.Popen(['espeak', string])
为什么不使用commands.getoutput()呢?
import commands
def espeak(string):
output = 'espeak "%s"' % string
a = commands.getoutput(output)
espeak("Mario Balotelli")