pyttsx3
pyttsx3 copied to clipboard
pyttsx3 is not changing the voice?What to do now?
Hi sir ,i am also facing the same problem , here is the code that I ran in vscode
# This file contains program for speaking
import win32api
import pyttsx3
def speaking(text):
engine=pyttsx3.init()
engine.say(text)
engine.setProperty('rate',125)
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.setProperty('volume',1)
engine.runAndWait()
speaking('Hi sir , this code is not working')
And here is the error that I got
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\hp\Documents\GitHub\Tuition-Management-Software>"C:/Python 3.8 Files/py
thon.exe" c:/Users/hp/Documents/GitHub/Tuition-Management-Software/Tuition_Management_Software/Speaker.py
Traceback (most recent call last):
File "c:/Users/hp/Documents/GitHub/Tuition-Management-Software/Tuition_Management_Software/Speaker.py", line 16, in <module>
speaking('Hi sir , this code is not working')
File "c:/Users/hp/Documents/GitHub/Tuition-Management-Software/Tuition_Management_Software/Speaker.py", line 12, in speaking
engine.setProperty('voice', voices[1].id)
IndexError: list index out of range
C:\Users\hp\Documents\GitHub\Tuition-Management-Software>
I am using windows 7 version and programming in vscode Here is the screen shot also
And voices[0] which is to change voice to that of a male , is in return returning a female voice.
I spent a lot of time trying to figure out how to deal with it. First, I get code here to know what voices it has recognized, and compare it to the voice list in Windows Settings > Time & Language > Speech.
I notice that some voice I need is in path 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices\Tokens' while the pyttsx3 read path is 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\‘ in regedit , and then I try to specify the path directly to Speech_OneCore in voice property, but it's doesn't work.
So finally, I found a solution here, he's method is copy the registry entries which needed in to two other path.(‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\’ and HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\SPEECH\Voices\Tokens'').
An additional point to note is that some sounds use other files for their VoicePath, you may open 'C:\Windows\Speech_OneCore\Engines\TTS' to see the corresponding name, and edit VoicePath in regedit path where added.
eng = pyttsx3.init("sapi5") voices = eng.getProperty('voices') bot.setProperty('voices', voices[1].id) // used bot.setProperty('voices', voices[0].id) used this but voice keeps on male only not able to switch voice as per requirement