I want the Microsoft David Voice for my pyttsx3 module. I wrote the following code. With voices[0].id
it is giving Zira (Female voice) and when I use voices[1].id
it shows error list is out of index
. Please help. How do I get David Voice?
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id) #changing index changes voices but ony 0 and 1 are working here
engine.say('Hello World')
engine.runAndWait()
Traceback (most recent call last):
File "C:/Users/admin/Desktop/delet.py", line 4, in <module>
engine.setProperty('voice', voices[1].id) #changing index changes voices but ony 0 and 1 are working here
IndexError: list index out of range
I also had the same problem. It arises when our windows doesn't have voice. you can check by searching speech setting from windows icon(Windows 10)
In choose a voice you will find yourself with only 1 voice but when get down you will be able to add voice. there you have to add english(us) or any other as per your requirement.
when the voice is downloaded the settings tab will automatically close and after few moments you will have 2 voice in you Python IDLE.
You can check it by:
before the output was 1 voice but now I am getting 2 voices i.e. Zira and David.
ensure that you use 'sapi5' when initialising pyttsx3.