使用win32com将Python中的文本转换为语音。客户

在python中,有几种API可用于将文本转换为语音。python库(通常称为win32com库)中提供的此类API之一。它提供了一系列让人兴奋的方法,其中之一就是库的分派方法。当与的参数一起传递时的Dispatch方法 萨皮。间谍之声 它与Microsoft Speech SDK交互,说出您从键盘输入的内容。 例如:

null
Input : Hello World
Output : 

Input : 121
Output : 

安装 安装win32com。客户端模块,打开终端并写入

pip install pypiwin32

这在Windows平台上运行。现在我们都准备编写一个将文本转换为语音的示例程序。

# Python program to convert
# text to speech
# import the required module from text to speech conversion
import win32com.client
# Calling the Disptach method of the module which
# interact with Microsoft Speech SDK to speak
# the given input from the keyboard
speaker = win32com.client.Dispatch( "SAPI.SpVoice" )
while 1 :
print ( "Enter the word you want to speak it out by computer" )
s = input ()
speaker.Speak(s)
# To stop the program press
# CTRL + Z


输入:

 Welcome to geeks for geeks

输出:


本文由 Subhajit Saha .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享