语音文本转语音 python 3.5
Speech text-to-speech with python 3.5
是否有可能以某种方式为 python 3.5
使用文本到语音
import speech
import time
response = speech.input("Say something, please.")
speech.say("You said " + response)
def callback(phrase, listener):
if phrase == "goodbye":
listener.stoplistening()
speech.say(phrase)
listener = speech.listenforanything(callback)
while listener.islistening():
time.sleep(.5)
错误:
Traceback (most recent call last):
File "D:/project/prog_2.py", line 1, in <module>
import speech
File "C:\Users\User\AppData\Roaming\Python\Python35\site-packages\speech.py", line 157
print prompt
^
SyntaxError: Missing parentheses in call to 'print'
我对 gTTS 有疑问,也许这里有一些建议:
Traceback 显示已安装的 speech
模块中的代码导致 Missing parentheses in call to print
错误。这表明该模块已被编写为在 Python 2 中工作 – 但不是 Python 3.
两个备选方案是:
找一个Python3兼容包;这可能 prove to be difficult
重写您在 Python 中的代码 2.
我知道这已经晚了,但万一有人无意中发现这可能会有用。这会将文本转换为语音,但也会对其进行线程化,以便该过程可以继续进行,而不必等待 python 停止说话。对于 Windows 只是因为需要 win32com
import threading
import win32com
def talk(wordsToSay):
def thread_speak(wordsToSay):
import pythoncom
pythoncom.CoInitialize()
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak(wordsToSay)
talk_thread = threading.Thread(target=thread_speak, args=[
wordsToSay], daemon=True)
talk_thread.start()
在我的整个应用程序中,我将调用 talk 并传递我想要它说的文本。例如
talk("Hello, my name is Josh")
input('Just waiting for this to stop talking before closing")
是否有可能以某种方式为 python 3.5
使用文本到语音import speech
import time
response = speech.input("Say something, please.")
speech.say("You said " + response)
def callback(phrase, listener):
if phrase == "goodbye":
listener.stoplistening()
speech.say(phrase)
listener = speech.listenforanything(callback)
while listener.islistening():
time.sleep(.5)
错误:
Traceback (most recent call last):
File "D:/project/prog_2.py", line 1, in <module>
import speech
File "C:\Users\User\AppData\Roaming\Python\Python35\site-packages\speech.py", line 157
print prompt
^
SyntaxError: Missing parentheses in call to 'print'
我对 gTTS 有疑问,也许这里有一些建议:
Traceback 显示已安装的 speech
模块中的代码导致 Missing parentheses in call to print
错误。这表明该模块已被编写为在 Python 2 中工作 – 但不是 Python 3.
两个备选方案是:
找一个Python3兼容包;这可能 prove to be difficult
重写您在 Python 中的代码 2.
我知道这已经晚了,但万一有人无意中发现这可能会有用。这会将文本转换为语音,但也会对其进行线程化,以便该过程可以继续进行,而不必等待 python 停止说话。对于 Windows 只是因为需要 win32com
import threading
import win32com
def talk(wordsToSay):
def thread_speak(wordsToSay):
import pythoncom
pythoncom.CoInitialize()
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak(wordsToSay)
talk_thread = threading.Thread(target=thread_speak, args=[
wordsToSay], daemon=True)
talk_thread.start()
在我的整个应用程序中,我将调用 talk 并传递我想要它说的文本。例如
talk("Hello, my name is Josh")
input('Just waiting for this to stop talking before closing")