简体   繁体   English

如何在python ..中生成声音输出?

[英]How to generate output as sound in python..?

I am generating random number in python as below, 我在python中生成随机数,如下所示,

print random.randrange(100, 1000, 2)

Is there any way to convert that output to sound(audio) format..? 有什么办法可以将输出转换为声音(音频)格式吗?

If you want to change the speed: 如果要更改速度:

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()

I am not sure what you are trying to achieve. 我不确定您要达到什么目标。 I assume you are trying to generate a random number and convert it into an audio stream. 我假设您正在尝试生成一个随机数并将其转换为音频流。 If so there is a module called PyTTSx which you need to install separately with pip. 如果是这样,则有一个名为PyTTSx的模块,您需要与pip分开安装。 Here is a quick example 这是一个简单的例子

import pyttsx
import random
data = pyttsx.init()
d = str(random.randrange(100, 1000, 2))
data.say(d)
data.runAndWait()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM