Say Command: Text to Speech
Convert Text to Speech with the Say Command
The say command is a powerful utility for converting
text into spoken audio. It's an invaluable tool for developers and
users who need to generate speech from text, whether for
accessibility, scripting, or creating audio content. This guide
provides a comprehensive overview of its functionalities and usage.
Core Functionality: Basic Text-to-Speech
At its simplest, the say command can read any given
phrase aloud. This is useful for quick audio feedback or testing.
# Say a phrase aloud.
say "I like to ride my bike."
Reading from Files and Customizing Voices
Beyond simple phrases, say can read the content of
entire files. Furthermore, you can customize the speech output by
selecting different voices and adjusting the speaking rate.
# Read a file aloud.
say -f filename.txt
# Say a phrase with a custom voice and speech rate.
say -v voice -r words_per_minute "I'm sorry Dave, I can't let you do that."
Exploring Available Voices
To discover the range of voices available on your system, you can use a special flag. This allows you to preview different vocal styles for your text-to-speech output.
# List the available voices.
say -v '?'
# Hear the available voices.
say -v \? | awk '{ print $1 }' | while read v; do echo "$v is speaking..."; say -v $v "Hi, my name is $v"; done
Creating Audio Files
The say command also allows you to save the spoken text
directly to an audio file, such as an AIFF file. This is perfect for
generating audio assets for projects or sharing spoken content.
# Create an audio file of the spoken text.
say -o filename.aiff "Here's to the Crazy Ones."