0

I am trying to use the python offline text to speech library pyttsx3. When I run the following script:

import pyttsx3
engine = pyttsx3.init('sapi')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.say("hello friends")

I get this error:

C:\Users\Hp\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/Hp/PycharmProjects/miniproject/demo12.py
  Traceback (most recent call last):
File "C:\Users\Hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
 File "C:\Users\Hp\AppData\Local\Programs\Python\Python38-32\lib\weakref.py", line 131, in __getitem__
o = self.data[key]()
KeyError: 'sapi'

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
 File "C:/Users/Hp/PycharmProjects/miniproject/demo12.py", line 4, in <module>
 engine = pyttsx3.init('sapi')
 File "C:\Users\Hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 22, in init
 eng = Engine(driverName, debug)
 File "C:\Users\Hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\Hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "C:\Users\Hp\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pyttsx3.drivers.sapi'
CDJB
  • 14,043
  • 5
  • 29
  • 55
Kayshika
  • 9
  • 4

1 Answers1

1
engine = pyttsx3.init('sapi5')

type this instead of what you typed Ihope it will work and afteer engine.say() you have to type

engine.runAndWait()
David Buck
  • 3,752
  • 35
  • 31
  • 35