Use Mac OS to generate speech files from text

Here’s a free (if you’ve got access to a Mac), quick method for creating spoken experimental stimuli, which I’ve implemented in this project and now use regularly in my lab. Hat tip to Richard Morey for suggesting this and writing a few lines of code that saves many hours of tedious voice recording.

  1. Create a plain text file with the texts you want to create .wavs for entered on separate lines. Line break after each word or phrase that you want to generate a sound file for. Name your text file “words.txt”. It should look something like this one we recently used to generate audio files for a digit span task: 
  2. Open iTerm, and navigate to the folder where your “words.txt” file is located. Here’s a lesson on how to navigate via command line. TLDR: the “cd” (current directory) command is what you need. cd .. will move you to the directory one above where you are. The “ls” command lists the folders in the current directory.
  3. Type the following into iTerm:

In a few seconds, the directory containing “words.txt” will also include a .wav file for each entry from “words.txt”.

This code uses the MacOS voice “Kate” (a female voice with a British accent). You can replace “Kate” with any voice available on your system by removing “Kate” from the code and typing your preferred voice instead.

Text-to-speech isn’t  perfect. You want to check that your .wav files sound like the text you meant for them to sound like. Different voices sometimes pronounce the text in different ways, so one solution to weird-sounding speech is to try another voice. You can also try alternative spellings to get the right pronunciation.

Share this post:
— May 4, 2017

One thought on “Use Mac OS to generate speech files from text

  1. Thanks Candice. This is wonderful once you get it working.
    I struggled a bit at first.
    I think the default voice that comes with a Mac is Daniel. If you need to install Kate, you go to System Preferences|Accessibility|Speech and you can then inspect a range of voices to install.
    My main problem was that I could not get the program to recognise the words.txt file. I think there are issues if you create your text in Word – there seem to be hidden characters. Fortunately, Richard Morey kindly sent me a working version that I could adapt, but even then, I found that if I just pasted words from a Word list into words.txt, the program would do odd things, like run them all together. Eventually I found that the answer was to use something like Notepad to create the list, and then be careful to paste and match format. Then, magically, it all worked brilliantly.

What Do You Think?