Advertisement
  1. Computer Skills
  2. OS X
Computers

Give Your Mac a Voice with Text-to-Speech

by
Difficulty:IntermediateLength:MediumLanguages:

Mountain Lion introduced us to Dictation, a Siri-like speech-to-text service for your Mac. But what if you want your Mac to talk to you? OS X has had some of the best Text-to-Speech functionality in the industry for a long time. Let's take advantage of it and give your Mac (and even your iPhone) a voice!

What is Text-to-Speech?

Text-to-Speech is one of the core accessibility features of OS X that was designed for those with visual impairments. It's been around since the early days of OS X and adopts a synthesized voice to provide an audio interface to on-screen dialog boxes, as well as a way to read out passages of text

Text-to-Speech is one of the core accessibility features of OS X

When in use, you can have your Mac alert you with a voice for things like an application bouncing in the dock or reading out an alert when an error occurs.

The Speech Preference Pane

In System Preferences, you can access your Mac's Text-to-Speech settings under the Speech preference pane (or Dictation and Speech for Mountain Lion).

System Preferences
System Preferences

In the preference pane we have these two sections: Speech Recognition (or Dictation for Mountain Lion users) and Text to Speech.

Text-to-Speech Preferences
Text-to-Speech Preferences

For the purposes of this tutorial, we're only interested in the Text to Speech section. So, what have we got here? Let's work from top to bottom:

System Voice and Speaking Rate

This option lets you set the voice and speech rate of your Mac, as well as preview your changes. By default, your Mac uses a voice called Alex.

It might only look like there's a handful of voices available, but if you click Customize, you can select to download additional voice packs for a wide variety of different languages.

Voices
Voices

Each voice pack is roughly 300–500Mb each so it may take a little time depending on your internet connection speed.

Tip: Want your Mac to sound like Siri? If you're in the US, it's Samantha. For UK residents, Siri's name is Daniel.

Announcements

When you've picked the perfect voice, you can have your Mac announce if there's an alert box and optionally read it out. Once enabled, you can customize the settings further.

Alert Options
Alert Options
  • Voice: You can customize the voice if you'd prefer a specific (and unique) voice to read out alerts.
  • Phrase: Choose from a list of phrases that the Mac will say when an alert is displayed, or better yet, create your own!
  • Delay: Setting a delay means you can dismiss an alert before the Mac begins to read it out. This is useful if you're wanting to use a spoken alert for those times when you may miss it.

Your Mac can also announce when an application requires your attention. This is the audio equivalent of an application bouncing in the Dock.

If you'd like to be able to have a keyboard shortcut to speak any selected text in most applications, you can enable this option and specify what shortcut you'd like. The default is Alt-Esc. Alternatively, right-click text in most applications will bring up a Speech menu you can use to start speaking text.

If you're a fan of a talking clock you can also have the clock announce the time.

Delving Deeper: The 'say' Command

We've explored the standard settings of OS X's Text-to-Speech functionality. Now it's time to take things one step further with some Terminal commands. In the following section, we're not only going to have the Mac say anything we want, we're going to use it to make some customized ringtones for our iPhone's contacts!

Tip: We're going to be delving into the Terminal here. Please continue if you're comfortable using the command line.

Step 1: Introduction to "say"

Open Terminal, located in Applications > Utilities, and type the following command:

Hello World
Hello World

Press enter and your Mac should now have said "Hello World" in the default voice you set in the Speech System Preference. Neat!

Step 2: Different Voices

What if we want to use a different voice? We could go back to Speech in System Preferences and change the default voice, but that means changing our existing settings. Instead, we use an optional parameter commonly known as a flag. The best way to explain it is to type the following command:

Your Mac would've now said "Hello World" with Alex's voice. Try this command:

Hello World 2
Hello World 2

And now the same again, but in Vicki's voice. Using the -v flag followed by a voice name tells the command that we want to use a specific voice.

Using just one command in Terminal, we can tell our Mac exactly what to say!

Step 3: Output to a File

Now we have a general idea of how to have our Mac say what we want, instead of speaking through the speakers, we're going to save it to a file instead. Before we begin, let's make sure you're in your home folder.
In your open Terminal window, type "cd" and press enter. If you aren't aware of this, typing this command on its own takes you to your home folder.

Before, we used the -v flag. Now, we're going to use the -o flag. This lets us tell the command to output the audio to a file instead of playing it through the speakers. Putting this into action, enter the following command and press enter:

Outputting to a file
Outputting to a file

Nothing happened, right? Because we've told the command to save it to a file, it won't play anything. Instead, use the Finder to go to your home folder and you should see a file there called helloworld.aiff.

The file in our home folder
The file in our home folder

Open the file in QuickTime and you'll now have an audio file with your Mac's voice saying Hello World.

Tip: You can use multiple flags so you can customise the voice and output to a file if you wish.

Step 4: Punctuation

OS X's Text-to-Speech creates inflections when used with correct punctuation. For example, enter the following command and press enter:

Hello World?
Hello World?

Now your Mac sounds confused! Let's try an exclamation mark:

Uh-oh!
Uh-oh!

Wait, what happened? Well, an exclamation mark is a special character and used on it's own, it is interpreted as something else. To let Terminal know we want to use the exclamation mark as part of our text, we escape it by adding a backslash just before it. This tells Terminal "Hey, the character right after this backslash is to just be a normal character, nothing special".

That's better
That's better

Creating a Customized Ringtone

For the next section, I'm going to use a great app for ringtones called Ringer ($3.99 on the Mac App Store). This will let us easily create a ringtone from a file that we will create.

Step 1: Choose a Contact

Have a look at your contacts list and pick a contact that you'd like to give a personalized greeting. I'm going to use the name Tim (feel free to substitute your own contact name). Now, let's jump back in to Terminal and create our new ringtone.

Step 2: Use Terminal to Generate a Suitable Ringtone

In Terminal, use the following Command and press enter:

There's the command
There's the command

Now, head back to your home folder in the Finder and you should see a file called Tim.aiff.

The file in our home folder
The file in our home folder

Step 3: Drag the File to Ringer

Open up Ringer, drag the file to the app and you should then have the ringtone available to create.

Ringer
Ringer

Before we create our ringtone, make sure the Gap is set to at least 3 seconds. If it's left to anything less, you'll just get the ringtone repeating too quickly which will make your iPhone sound very impatient! After you've set the gap, hit Create.

You'll now see the ringtone in iTunes (called Tim). Now that we've got a customized ringtone in iTunes, it's time to sync your iPhone. Once you've synced it, open Contacts on your iPhone and select the desired contact. Tap edit and from here, assign your custom ringtone.

Edit your desired contact
Edit your desired contact

And that's it! Your iPhone now has a customized ringtone for that certain contact to distinguish them so you don't even need to look at your iPhone to know who's calling. Using the above information, why not try and create ringtones for other contacts or alert tones for emails and text messages?

Wrapping Up

Although serving a very specific need, OS X's Text-to-Speech capabilities have a wide range of uses for many different users. After completing the above tutorial, you'll be able to make use of this often-overlooked feature a whole lot more.

Ringtones are just one novel way of using Text-to-Speech. Because it's available via Terminal, advanced users can integrate it into Automator, AppleScript and even shell scripts. Imagine being able to be told when you've received a new email and for your Mac to tell you who it's from? It's perfectly doable and I'd love to hear from anyone who uses Text-to-Speech in unique and interesting ways!

Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.