Python 3.4 - Text to Speech with SAPI

I tried to use this code to convert text to speech using Python 3.4, but since my computer's primary language is not English (I'm using Win7x64), the voice and accent are wrong (because I want it to “speak” English).

import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak("Hello, it works!")

      

So, is there a way to change the voice / language (programs, not system)? Also, do you think there is a better way to do this? Perhaps a module that can run on every system?

+2


source to share


1 answer


Chances are your OS only comes with one voice. There are several ways to output English audio using IPA (International Phonetic Language) and SVSFIsXML as a flag in your conversation ... but I assume you want something less complicated.

The first thing I would like to do is capture the English voice if you don't already have it. (First check by going to Control Panel -> Speech Recognition -> Text to Speech and look at the voice selection. If it says "Microsoft Anna - English (United States)" then you already have an English voice.)

If not, you'll have to grab another voice from Microsoft Speech Platform - Runtime Languages ​​(version 11) . I highly recommend Microsoft Speech Text to Speech Voice (en-US, ZiraPro) as an English voice. You will also want Microsoft Speech Platform - Software Development Kit (SDK) (version 11) .

To be honest, I'll just install them somehow, because I think it's cool.

Once you have everything installed, what I found to get the voices working is a neat registry hack I found in Voice Attack - freeing up alternative TTS voices that work with Win7 / 8 64-bit.

Basically, this is because you are doing some string substitution in your MS Speech Platform voices in your registry so that what you see in your

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Speech Server \ v11.0 \ Voices HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Microsoft \ Speech Server \ v11.0 \ Voices



registers will end:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Speech \ Voices HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Microsoft \ Speech \ Voices

Once that happens, head back to the dashboard and take a look at all the voices you've installed. You should be able to test them all, even in different languages. If the voices are not playing, then the voices you installed are not the correct bit (x86 vs 64).

Now in python you will need to make a call to SetVoice. I have never programmed in python in my life, but my guess is that the call you need will look something like speaker.SetVoice ("Microsoft Server Speech Text for Speech Voice (en-US, ZiraPro)"). Once you set the voice, that voice should be the one who speaks all the time you make the Speak call.

Now if you've gotten to this point and voices that were playing in the control panel but not in your code, it might happen that your program is 32bit / 64bit or whatever, and then you need to step back, reinstall 32bit / 64 bit voices, run your reg changes again and try running the app again.

A bit of work, but it will pay off. If you distribute your code, you will need to make sure your votes are part of the client's registry, and messing up can be a headache in itself.

+3


source







All Articles