【问题标题】:Speech text-to-speech with python 3.5使用 python 3.5 进行语音文本到语音转换
【发布时间】:2016-09-07 17:20:01
【问题描述】:

是否有可能以某种方式在 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 有疑问,也许这里有一些建议:

gTTS HTTPError: 403 Client Error: Forbidden for url

【问题讨论】:

标签: python-3.x speech-recognition speech


【解决方案1】:

Traceback 显示已安装的 speech 模块中的代码导致 在调用 print 时缺少括号 错误。这表明该模块已被编写为在 Python 2 中工作,但不是 Python 3。

两种选择是:

  1. 找到兼容 Python 3 的包;这可能是prove to be difficult

  2. 在 Python 2 中重写您的代码。

【讨论】:

  • 你好再次感谢你的支持也许你有一些建议,如何解决 espeak 安装在这里:espeak
  • @Ai_ve 恐怕不会——尽管我打算在不久的将来尝试 espeak。顺便说一句,我注意到您没有accepted 任何问题的答案。如果您还不知道,接受会将问题标记为已回答,并且(带有赞成票)是 Stack Exchange 网站上表达感谢的方式。
【解决方案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")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-15
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多