需要在os.system中使用带有espeak和aplay命令的变量

时间:2017-12-11 11:26:03

标签: python raspberry-pi subprocess os.system espeak

我希望我的覆盆子pi能说出这个打印命令

print label + " is " + spos + " and the distance is " + str(distance) + "cm"

里面有三个变量。 这是我在shell中使用的命令,我需要在python中使用

$espeak -s110  "label + " is " + spos + " and the distance is " + str(distance) + "cm"" --stdout | aplay -D sysdefault:CARD=2

我已经尝试使用os.system,因为我不熟悉subprocess命令。

os.system('espeak -s110  "'label' + is + 'spos' +  and the distance is  + 'str(distance)' + cm" --stdout | aplay -D sysdefault:CARD=2')

我收到了无效的sytax错误。我已经尝试了它的每个版本,但无法使其正常工作。

1 个答案:

答案 0 :(得分:1)

这可以为您提供所需的信息:

cmd = 'espeak -s110 "{0} is {1} and the distance is {2} cm" --stdout | aplay -D sysdefault:CARD=2'.format(label, spos, str(distance))

os.system(cmd)