Jessime / MazeDay2017

A game for Maze Day 2017 at UNC.
MIT License
1 stars 1 forks source link

Robotic voices in pygame #13

Open kwcurrin opened 7 years ago

kwcurrin commented 7 years ago

This is not an issue but a tip. (where should tips be added on github?)

This weekend I found a good way to add text-to-speech to pygame games. If you have a mac, use the "say" program. If you have windows, use the "espeak" program available for download here: http://espeak.sourceforge.net/

Both of these programs are available through the commandline. I've found that calling os.system('espeak "hello world"') works but causes delays in pygame. However, you can save text spoken by say or espeak to a wav file. These sounds can then be loaded like any other pygame sound for seemless game use. I have implemented this in my race game.

Note, printing text to the terminal in pygame most likely will be inaccessible to a screen reader.

Hope that is helpful!

Jessime commented 7 years ago

Right here is a perfect spot for tips. In a large project, you'd probably add a tag like "Suggestion" or something.

I've played around with "say", but haven't used "espeak". I've had a lot of success using the google text-to-speech API (https://github.com/pndurette/gTTS).

Pros: It works on every platform. I'm using linux, so it's nice to have something that works on all OS systems. Also, you don't have to ask the user to install any additional software.

Cons: You have to have an internet connection. But, that's pretty ubiquitous these days.

kwcurrin commented 7 years ago

The google api sounds cool; I'll check it out. How smooth is it to call the google api directly in the script?

Creating wav files with say or espeak is useful because it can be done outside of the game and then the sounds can be included with the game and the user doesn't have to install espeak or say. This works across platforms and gives smoother playback. However, it doesn't allow for text to be generated by the game as needed and results in a lot of extra sound files. I'll see how the google api does.