Generating a Spelling Bee Practice Audio File with Python

This is a bit outside of the SQL Server realm, but might be of interest to some. I was asked to read 100 words recently, two sets of words, for use in a practice spelling test. The audio was supposed to be read with a 5 second pause between the word, with each word being repeated twice. I figured with the dawn of AI and other Text to Speech (TTS) tools, there might be a way to generate those lists without recording. Coming up with a way to do that would also mean we could generate future lists without a lot of trouble.

I will admit to asking for some ideas from Chat GPT. That got me started toward using Python to read my file, generate each spoken word as an individual MP3, then concatenate all of them together with appropriate spacing between each word. That let me preview the words for any “off” pronunciations without needing to play the entire final file.

For this to work, you’ll need to download and install FFMPEG. You’ll need to install python v3.x and then use PIP to install the “pydub” and “gtts” modules. That usually be done by opening a command prompt in the Python folder and running pip install pydub and pip install gtts.

I created my folder in the “C:\Temp” folder on my Windows machine to hold my code, the input word list, and the resulting audio folder. Here’s my basic Python file – Generate_Spelling_Audio.py. There are several “generate_silence” calls to insert the 5 seconds of silence between words. I haven’t tried to clean this up to use more global variables at this point as this was mostly an exercise for a short-term project. All of my files can be found at this gist. I’m listing the python code in-line below for easier viewing.

This generated my audio practice files quickly once I tuned some of the parameters and adjusted the silence between words, I was able to quickly generate several different practice spelling exams for students to use. The pronunciations aren’t 100% the way I’d say them, but sound natural enough to use for our purposes. I hope this will help someone else who might have students preparing for spelling tests.

Leave a Reply

Your email address will not be published. Required fields are marked *