• About the author
  • Colleagues
  • Contract work
  • Recordings

The Mnemonic Lode

Memory. Measurement. Life in Academia.

  • About the author
  • Colleagues
  • Contract work
  • Recordings

Use Mac OS to generate speech files from text

May 4, 2017 Measurement 3 Comments

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.

Who benefits from for-profit academic publishing?

ESCoP preliminary satellite event: The new Journal of Cognition

3 thoughts on “Use Mac OS to generate speech files from text”
  1. Dorothy Bishop
    May 13, 2017 at 13:19

    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.

    Reply
  2. Jan Philipp Röer
    May 26, 2017 at 15:00

    Thanks Candice.

    There might be even an easier way to create a sound file from text in Mac OS. If you highlight the text you want to record in a .txt or .pages document, and click on the right mouse button, you should be able to select “import as an audio file to iTunes” (or something similar, it is in German on my computer). Then you can select the voice and listen to what the recording will sound like. This recording is in .m4a format, so you might have to convert it to .wav or .aiff in Amadeus or whatever sound editing program you prefer.

    Best, Jan

    Reply
    • Candice Morey
      August 5, 2017 at 09:25

      Thanks, Jan, I didn’t know that! But it would still take quite a while to make a large batch of sound files using that method. If I need to create more than a few, struggling with scripting rapidly becomes worth the time.

      Reply
Leave a Reply to Candice Morey Cancel reply

Recent Posts
  • In memoriam, Bill
  • Wrangling messy data in R using the tidyverse
  • Alessandra Souza, the 2019 WomWoM Research Fairy
  • #WomWom: A wand award for the 2018 research-fairy
  • I’ve got a lab handbook now
Recent Comments
  • Alessandra on Alessandra Souza, the 2019 WomWoM Research Fairy
  • Alessandra Souza, the 2019 WomWoM Research Fairy – The Mnemonic Lode on #WomWom: A wand award for the 2018 research-fairy
  • Candice Morey on #WomWom: A wand award for the 2018 research-fairy
  • Candice Morey on Going for a Registered Report?
  • Alessandra Souza on Going for a Registered Report?
Archives
  • May 2020
  • November 2019
  • November 2018
  • August 2018
  • July 2018
  • May 2018
  • January 2018
  • August 2017
  • May 2017
  • April 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • June 2016
  • May 2016
  • March 2016
  • February 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
Categories
  • Academia
  • Measurement
  • Openness
  • Research
  • Uncategorized
  • WomWoM
Meta
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
About me
  • About the author
  • Colleagues
  • Contract work
  • Recordings
Proudly powered by WordPress | Theme: Doo by ThemeVS.