0

Whenever I try to run my text to speech program in python 3.8.6

it gives me error

My Code

import pyttsx3

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices[0].id)
print(voices)
engine.setProperty('voices', voices[0].id)

engine.say("hello")
engine.runAndWait()

Error

Traceback (most recent call last):
  File "C:/Users/Admin/PycharmProjects/automating_Practices/Chat_Bot_PRogram/Voice_chatbot.py", line 20, in <module>
    voices = engine.getProperty('voices')

  File "C:\Python\Python386\lib\site-packages\pyttsx3\engine.py", line 146, in getProperty
    return self.proxy.getProperty(name)

  File "C:\Python\Python386\lib\site-packages\pyttsx3\driver.py", line 173, in getProperty
    return self._driver.getProperty(name)

  File "C:\Python\Python386\lib\site-packages\pyttsx3\drivers\sapi5.py", line 88, in getProperty
    return [self._toVoice(attr) for attr in self._tts.GetVoices()]

  File "C:\Python\Python386\lib\site-packages\pyttsx3\drivers\sapi5.py", line 88, in <listcomp>
    return [self._toVoice(attr) for attr in self._tts.GetVoices()]

  File "C:\Python\Python386\lib\site-packages\pyttsx3\drivers\sapi5.py", line 77, in _toVoice
    return Voice(attr.Id, attr.GetDescription())
_ctypes.COMError: (-2147200966, None, (None, None, None, 0, None))

Please can anyone help me with this

Bijay Regmi
  • 1,187
  • 2
  • 11
  • 25
Prathamesh Bhatkar
  • 291
  • 1
  • 4
  • 15
  • The code runs just fine on my end, maybe you need to reinstall pyttsx3. – Bijay Regmi Mar 04 '21 at 09:20
  • 1
    I tried but still the problem is there – Prathamesh Bhatkar Mar 04 '21 at 10:22
  • I see nothing wrong with the code and it has worked for me across multiple devices on windows platform. You might want to file an issue on github so the developers see it. https://github.com/nateshmbhat/pyttsx3/issues – Bijay Regmi Mar 04 '21 at 10:44
  • 1
    I think there is some problem with my sapi5 installation I Tried by not using *engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') print(voices[0].id) print(voices) engine.setProperty('voices', voices[0].id)* for now it worked for me – Prathamesh Bhatkar Mar 04 '21 at 14:12

0 Answers0