0

How do i change the accent in pyttsx3?

I've successfuly tried to change the voice and the rate at which it delivers the speech.

import pyttsx3
engine=pyttsx3.init()
voice=engine.getProperty('voices')[0]
engine.setProperty('voice',voice.id)
engine.setProperty('rate',100)
engine.say("Hello there!")
engine.runAndWait()  

Change in the accent.

2 Answers2

2

To change the accent of the voice, you can use the pyttsx3.setProperty('voice', 'en-us') code.

It does not do much ...

But here is the complete code anyway

import pyttsx3

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


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

engine.say("Hello World!")
engine.runAndWait()
engine.stop()

or

as mentioned in the other answer you can use a for loop to loop through all the different accents ...

As shown in the code below

import pyttsx3

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

for voice in voices:
    print(voice, voice.id)
    engine.setProperty('voice', voice.id)
    engine.say("Hello World!")
    engine.runAndWait()
starball
  • 20,030
  • 7
  • 43
  • 238
0

You can try this code:

import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
print(voice, voice.id)
engine.setProperty('voice', voice.id)
engine.say("Hello World!")
engine.runAndWait()
engine.stop()
bugfreerammohan
  • 1,471
  • 1
  • 7
  • 22