'Using Dispatch from win32com.client 'SAPI.Spvoice'
I'm trying to use Python code to change WIN10 text-to-speech voice from Windows Default to English.
There are mentions of using SetVoice commands with SAPI.Spvoice, but cannot find the expample
from win32com.client import Dispatch
Windows_Speak = Dispatch('SAPI.Spvoice')
Windows_Speak.Speak('Tomato')
The above code would use the Windows default language settings, but I need to be able to change languages using in-Python commands. Any ideas?
Solution 1:[1]
Try this:
from win32com.client import Dispatch
Windows_Speak = Dispatch('SAPI.Spvoice')
Windows_Speak.Voice = speak.GetVoices().Item(2)
Windows_Speak.Rate = 3
print(speak.GetVoices().Item(2).GetDescription()) #just to see what voice is used
Windows_Speak.Speak('Tomato')
Play around if the voice id
Solution 2:[2]
One alternative could be using 'pyttsx3. If you are trying to change voice from your Window's default one, then you can use try this:
engine = pyttsx3.init('sapi5')
#with given method you will get the list of voices available
voices = engine.getProperty('voices')
#in engine I am setting 0th indexed voice as my custom
engine.setProperty('voice', voices[0].id)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Darklighted |
| Solution 2 |
