nateshmbhat / pyttsx3

Offline Text To Speech synthesis for python
Mozilla Public License 2.0
2.15k stars 336 forks source link

modified registry / invalid voices causes crash #315

Open lindawilliam6 opened 5 months ago

lindawilliam6 commented 5 months ago

this is the program which i tried import pyttsx3

engine = pyttsx3.init('sapi5') engine.setProperty('volume', 1.0)

voices = engine.getProperty('voices')

print(voices[0].id) engine.setProperty('voices',voices[0].id)

pyttsx3.speak("hello world")

getting an error in getproperty line as File "C:\Users\Nivetha Linda\PycharmProjects\testproject\demo.py", line 8, in voices = engine.getProperty('voices') File "C:\Users\Nivetha Linda\AppData\Local\Programs\Python\Python310\lib\site-packages\pyttsx3\engine.py", line 146, in getProperty return self.proxy.getProperty(name) File "C:\Users\Nivetha Linda\AppData\Local\Programs\Python\Python310\lib\site-packages\pyttsx3\driver.py", line 173, in getProperty return self._driver.getProperty(name) File "C:\Users\Nivetha Linda\AppData\Local\Programs\Python\Python310\lib\site-packages\pyttsx3\drivers\sapi5.py", line 88, in getProperty return [self._toVoice(attr) for attr in self._tts.GetVoices()] File "C:\Users\Nivetha Linda\AppData\Local\Programs\Python\Python310\lib\site-packages\pyttsx3\drivers\sapi5.py", line 88, in return [self._toVoice(attr) for attr in self._tts.GetVoices()] File "C:\Users\Nivetha Linda\AppData\Local\Programs\Python\Python310\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))

could some one help!! initially i changed the voice registry according to this website https://www.ghacks.net/2018/08/11/unlock-all-windows-10-tts-voices-system-wide-to-get-more-of-them/ but it dint work!! then tried to uninstall and reinstall pyttsx3 then tried to system restore too! nothing worked and im desperate!!!

Siddharth-Latthe-07 commented 4 months ago

Possible solutions:-

  1. Verify the Voices Ensure that the voices are correctly installed and accessible by SAPI5. You can do this by running the following code to list all available voices:
    
    import pyttsx3

engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices')

for voice in voices: print(f"Voice: {voice.name}") print(f" - ID: {voice.id}") print(f" - Languages: {voice.languages}") print(f" - Gender: {voice.gender}") print(f" - Age: {voice.age}\n")

2. Check Registry Changes
If you made registry changes to unlock more voices, ensure that these changes are correct. Undo any changes if possible to revert to the original state. Here is a summary of what the registry changes might look like:

Open regedit.
Navigate to `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SPEECH_OneCore\Voices\Tokens`.
Ensure that the subkeys under Tokens correspond to actual voice files on your system.
3. Reinstall SAPI5 Voices and libraries
Reinstall or repair the SAPI5 voices. 
4. Modify Your Code
There might be an issue with how the voices property is being set. Instead of `engine.setProperty('voices', voices[0].id)`, it should be `engine.setProperty('voice', voices[0].id)`.

import pyttsx3

Initialize the TTS engine

engine = pyttsx3.init('sapi5')

Set volume level

engine.setProperty('volume', 1.0)

Get available voices

voices = engine.getProperty('voices')

Print the first voice ID

print(voices[0].id)

Set the voice to the first available voice

engine.setProperty('voice', voices[0].id)

Speak the text

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


Hope this helps
Thanks 
willwade commented 2 months ago

Yep. I've seen something similar here when you mess around with voices in the registry. Its really easily done (I was thinking of doing better exception handling here but its tricky). The key giveaway is this _ctypes.COMError: (-2147200966, None, (None, None, None, 0, None))

As well as editing HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SPEECH_OneCore\Voices\Tokens - also check HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH_OneCore\Voices\Tokens

also HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SPEECH\Voices\Tokens HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens

MoltenEQ commented 1 week ago

Hello, I've encountered a similar issue. engine.runAndWait() was constantly getting stuck. Nothing would be said, or of I tried to save to a file it would be just empty. After enabling debug I got the same _ctypes.COMError error as mentioned previously. I decided to check the voices with the method provided by @Siddharth-Latthe-07 and it's wierd:

Voice: Microsoft Zira Desktop - English (United States)
 - ID: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0
 - Languages: []
 - Gender: None
 - Age: None

I don't know if the registry is broken on my machine or I have to install SAPI5 separately.

willwade commented 1 week ago

Nope. A fix is coming...infact I've merged the pr for this today. Try using this repo instead of a fixed release number to see if it's fixed. Once a few things settle I think we will push a new release.

pip install git+https://github.com/nateshmbhat/pyttsx3.git

At least I hope it is! Let me know.

Nb. If you come across and are using espeak. That's coming too https://github.com/nateshmbhat/pyttsx3/pull/363