是否有可能以某种方式使用 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 有疑问,也许这里有一些建议:
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")
Pyt2s 库。它有如此多的声音和语言。只需要连接互联网即可使用。
安装库:
pip install pyt2s
示例代码:
from pyt2s.services import stream_elements
obj = stream_elements.StreamElements()
data = obj.requestTTS('Lorem Ipsum is simply dummy text.')
with open('output.mp3', '+wb') as file:
file.write(data)