user6185396
user6185396

Reputation:

Speech text-to-speech with python 3.5

is that possible somehow to use text to speech for 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)

error:

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'

I have problem with gTTS maybe some advice here:

gTTS HTTPError: 403 Client Error: Forbidden for url

Upvotes: 0

Views: 1371

Answers (2)

Josh Pachner
Josh Pachner

Reputation: 521

I know this is late, but in case someone stumbles on this might be useful. This converts text to speech but also threads it so that the process can continue without having to wait for python to stop talking. For Windows only due to needing 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()

Throughout my application i will then call talk and pass in the text i want it to say. for example

talk("Hello, my name is Josh")
input('Just waiting for this to stop talking before closing")

Upvotes: 0

Anthony Geoghegan
Anthony Geoghegan

Reputation: 12003

The Traceback shows that code from the installed speech module is causing the Missing parentheses in call to print error. This shows that the module has been written to work in Python 2 – but not Python 3.

The two alternatives are:

  1. Find a Python 3 compatible package; this may prove to be difficult

  2. Rewrite your code in Python 2.

Upvotes: 2

Related Questions