我在python中生成随机数,如下所示,
print random.randrange(100, 1000, 2)
有没有办法将该输出转换为声音(音频)格式..?
答案 0 :(得分:4)
如果你想改变速度:
import pyttsx
engine = pyttsx.init()
engine.setProperty('rate', 70)
voices = engine.getProperty('voices')
for voice in voices:
print "Using voice:", repr(voice)
engine.setProperty('voice', voice.id)
engine.say("Hi there, how's you ?")
engine.say("A B C D E F G H I J K L M")
engine.say("N O P Q R S T U V W X Y Z")
engine.say("0 1 2 3 4 5 6 7 8 9")
engine.say("Sunday Monday Tuesday Wednesday Thursday Friday Saturday")
engine.say("Violet Indigo Blue Green Yellow Orange Red")
engine.say("Apple Banana Cherry Date Guava")
engine.runAndWait()
答案 1 :(得分:2)
我不确定你想要实现的目标。我假设您正在尝试生成随机数并将其转换为音频流。如果是这样,有一个名为PyTTSx
的模块,您需要使用pip单独安装。这是一个简单的例子
import pyttsx
import random
data = pyttsx.init()
d = str(random.randrange(100, 1000, 2))
data.say(d)
data.runAndWait()