-1

I have tried for over 2 hours trying to figure this out, not 100% sure but i think it has to do with the fail in the sapi5.py module because i dont have the following voices installed:

MSSAM = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\\MSSam'
MSMARY = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\\MSMary'
MSMIKE = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\\MSMike'

I have tried adding to the above list, changed the first entry to MSGeorge, tried downgrading to python 3.6 and 3.7, tried using pyttsx3 2.71,

also tried changing the registry to add in MSGeorge like what is called out in this issue "https://stackoverflow.com/questions/62756194/pyttsx3-module-is-not-showing-all-installed-voices"

I dont suppose anyone has seen this before, given that i searched the internet and youtube i couldnt find anything so im thinking its something simple,

Im running a windows 10 PC with python 3.8.6 on pycharm,

Code:

import pyttsx3
engine = pyttsx3.init() # object creation
voices = engine.getProperty('voices')
print(voices)

Error:

Traceback (most recent call last):
  File "C:\Users\user\PycharmProjects\venv\lib\site-packages\pyttsx3\__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\weakref.py", line 131, 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/user/PycharmProjects/pythonProject/Jarvis/Jarvis.py", line 2, in <module>
    engine = pyttsx3.init() # object creation
  File "C:\Users\user\PycharmProjects\venv\lib\site-packages\pyttsx3\__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "C:\Users\user\PycharmProjects\venv\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\user\PycharmProjects\venv\lib\site-packages\pyttsx3\driver.py", line 52, in __init__
    self._driver = self._module.buildDriver(weakref.proxy(self))
  File "C:\Users\user\PycharmProjects\venv\lib\site-packages\pyttsx3\drivers\sapi5.py", line 32, in buildDriver
    return SAPI5Driver(proxy)
  File "C:\Users\user\PycharmProjects\venv\lib\site-packages\pyttsx3\drivers\sapi5.py", line 49, in __init__
    self.setProperty('voice', self.getProperty('voice'))
  File "C:\Users\user\PycharmProjects\venv\lib\site-packages\pyttsx3\drivers\sapi5.py", line 102, in setProperty
    token = self._tokenFromId(value)
  File "C:\Users\user\PycharmProjects\venv\lib\site-packages\pyttsx3\drivers\sapi5.py", line 86, 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_enGB_GeorgeM')

2 Answers2

0

Had this same problem, after playing around with the code,

def _tokenFromId(self, id_):
    tokens = self._tts.GetVoices()
    id_ = id_.replace("Speech_OneCore", "Speech") #<----
    for token in tokens:
        if token.Id == id_:
            return token
    raise ValueError('unknown voice id %s', id_)

Added id_ = id_.replace("Speech_OneCore", "Speech"), which solved the problem.

For me, the problem was that id_ was HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\ and the the token were in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\.

-1

Ok I think i finally fixed it, turns out that the raise value error located in the function below appears to be at fault:

def _tokenFromId(self, id_):
    tokens = self._tts.GetVoices()
    for token in tokens:
        if token.Id == id_:
            return token
#    raise ValueError('unknown voice id %s', id_)

To fix the error i commented out the raise ValueError Line and code works, while i was debugging though pycharm i could see that the voice id was getting passed into the function but for some reason the if statement returns a false.

Anyway seems to be working now,

Location of the file is Drive Letter e.g F:...\Lib\site-packages\pyttsx3\drivers scroll down until you find the function above and just comment out the raise piece of code,

  • The exception is only raise if the ```return token``` is not reached. Meaning your ```id``` is not part of ```tokens```. This will only return ```None``` and seems very bad as it would probably fails somewhere else. I don't know the code, but I would wonder why the id is missing from ```tokens``` – Nic Laforge Jan 17 '21 at 00:10
  • @NicLaforge thought as much, but what I can't figure out is that I tried this on another PC and it worked fine i'm at a loss really, any ideas what I could do in order to debug it further? granted you haven't seen the code before, but have you ever seen a similar issue like this? – Silent_storm Jan 17 '21 at 01:01
  • If the keys are missing in the registry, I would assume that there is more missing. Have you try to install the Speech Platform: https://www.microsoft.com/en-us/download/details.aspx?id=27225. – Nic Laforge Jan 17 '21 at 01:30
  • @NicLaforge Gave that a go there, no change. I will dig a little deeper into this and see whats going on, thanks for your help, I might compare my other PC to see if something obvious jumps out at me. – Silent_storm Jan 17 '21 at 02:40