'Pyttsx3 Voice KeyError: 'sapi5'

Getting unknown voice id error. I tried with ( Pyttsx3 2.6 and python 3.6 ), ( pyttsx3==2.9 & python 3.10)

Traceback (most recent call last):
      File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\__init__.py", line 44, in init
        eng = _activeEngines[driverName]
      File "E:\anaconda3\envs\dummy\lib\weakref.py", line 137, in __getitem__
        o = self.data[key]()
    KeyError: None
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:/Users/Dnyanesh/PycharmProjects/dummy/main.py", line 5, in <module>
        engine = pyttsx3.init()
      File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\__init__.py", line 46, in init
        eng = Engine(driverName, debug)
      File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\engine.py", line 52, in __init__
        self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
      File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\driver.py", line 77, in __init__
        self._driver = self._module.buildDriver(weakref.proxy(self))
      File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\drivers\sapi5.py", line 22, in buildDriver
        return SAPI5Driver(proxy)
      File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\drivers\sapi5.py", line 41, in __init__
        self.setProperty('voice', self.getProperty('voice'))
      File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\drivers\sapi5.py", line 82, in setProperty
        token = self._tokenFromId(value)
      File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\drivers\sapi5.py", line 66, in _tokenFromId
        raise ValueError('unknown voice id %s', id_)
    ValueError: ('unknown voice id %s', 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech_OneCore\\Voices\\Tokens\\MSTTS_V110_enUS_DavidM')


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source