2

I downloaded pyttsx, and it seems to work fine except that the list of voices only has one voice (Microsoft Anna). I'd like to be able to change it to a male voice, but nothing I tried or research worked! Here's my current test code:

import pyttsx
engine = pyttsx.init()
engine.setProperty('rate', 100)

voices = engine.getProperty('voices')
for voice in voices:
    print "Using voice:", repr(voice.name)
    engine.setProperty('voice', voice.id)
    engine.setProperty('gender', 'male') #this doesn't raise an error, but also won't do anything
    engine.say("Hi there, how's you ?")
    engine.say("A B C D E F G H I J K L M")
    engine.say("N O P Q R S T U V W X Y Z")
    engine.say("0 1 2 3 4 5 6 7 8 9")
    engine.say("Sunday Monday Tuesday Wednesday Thursday Friday Saturday")
    engine.say("Violet Indigo Blue Green Yellow Orange Red")
    engine.say("Apple Banana Cherry Date Guava")
engine.runAndWait()

and this only runs for one loop. If I say print(voices), it prints a list with only one item in it. Any suggestions?

Davis Diercks
  • 629
  • 1
  • 10
  • 11

3 Answers3

0

Since you said you're using MS Anna, I'm assuming you're on windows 7. MS Speech Platform is the only one I'm aware of that you can provide you with extra "voices".

There are many commercial ones out there but, of course, most you'll have to pay for, and some come with a free trial.

PYTTSX does not come with extra voices it only provides you the tools to access what you have.

Leb
  • 15,483
  • 10
  • 56
  • 75
  • But that's exactly what I did except different text, no rate initialization, and no print(voice.name). I tried it and it does the exact same thing. What I meant is that there seems to be no more than one item that can be called from the list of voices; the list is only one item long. How do I get more voices? – Davis Diercks Jul 12 '15 at 00:01
  • Ahhh ok, gotcha. I'll look into MS Speech Platform. Thanks! – Davis Diercks Jul 12 '15 at 19:29
0

voices are stored in a list that you can print. print voices to get all the voices that are on your system.

engine = pyttsx3.init()

voices = engine.getProperty("voices")

engine.setProperty("voice", voices[1].id)
vekerdyb
  • 1,213
  • 12
  • 26
0

Try this

import pyttsx
engine = pyttsx.init()
engine.setProperty('rate', 100)

voices = engine.getProperty('voices')
for voice in range(len(voices)):
    engine.setProperty('voice', voices[voices].id)

# engine.setProperty('gender', 'male') This function won't work if you don't have any female voices in your system