How to use the command 'say' (with examples)
- Osx
- December 25, 2023
The ‘say’ command is a powerful text-to-speech tool in macOS that allows users to convert text into spoken words. This command is particularly useful for individuals with visual impairments, as it can read out text from various sources, including phrases, files, and even multiple languages. It also provides additional features like customizing the voice and speech rate. This article will explore different use cases of the ‘say’ command with examples.
Use case 1: Say a phrase aloud
Code:
say "I like to ride my bike."
Motivation:
This use case is handy when you want to hear a specific phrase out loud. For example, if you are writing a document or an email, you can use the ‘say’ command to listen to your text, which can help catch any errors or improve the overall flow of the content.
Explanation:
say
: The command itself, followed by the phrase enclosed in quotation marks."I like to ride my bike."
: The text to be converted into speech, enclosed in quotation marks.
Example output:
The system will speak aloud the phrase “I like to ride my bike.”
Use case 2: Read a file aloud
Code:
say --input-file=filename.txt
Motivation:
When you have a lengthy document or a text file that you want to listen to rather than read visually, you can use this use case of the ‘say’ command. It is particularly useful for people who prefer listening to content or have difficulty reading large amounts of text.
Explanation:
say
: The command itself.--input-file=filename.txt
: Specifies the input file to be read aloud. Replace “filename.txt” with the actual file name or path.
Example output:
The system will read aloud the content of the specified file, line by line.
Use case 3: Say a phrase with a custom voice and speech rate
Code:
say --voice=voice --rate=words_per_minute "I'm sorry Dave, I can't let you do that."
Motivation:
Sometimes, you may want to customize the voice and speech rate to match a particular character or make the speech more engaging. This use case allows you to specify the voice and adjust the speech rate according to your preference.
Explanation:
say
: The command itself.--voice=voice
: Specifies the voice to be used. Replace “voice” with the desired voice name (e.g., “Alex”).--rate=words_per_minute
: Specifies the speech rate in words per minute. Replace “words_per_minute” with the desired rate.
Example output:
The system will say the phrase “I’m sorry Dave, I can’t let you do that.” using the specified voice and speech rate.
Use case 4: List the available voices
Code:
say --voice="?"
Motivation:
To know the available voices on your macOS system, this use case allows you to retrieve a list of all the available voices that can be used with the ‘say’ command.
Explanation:
say
: The command itself.--voice="?""
: This argument with a question mark ("?") retrieves a list of available voices.
Example output:
The system will display a list of available voices in the terminal window.
Use case 5: Say something in Polish
Code:
say --voice=Zosia "Litwo, ojczyzno moja!"
Motivation:
The ‘say’ command supports multiple languages, and this use case demonstrates how to make it speak in Polish. It can be useful for language learners, individuals communicating with Polish-speaking people, or anyone who simply wants to hear the pronunciation of Polish phrases.
Explanation:
say
: The command itself.--voice=Zosia
: Specifies the particular Polish voice to be used. Replace “Zosia” with the desired Polish voice name."Litwo, ojczyzno moja!"
: The Polish text to be spoken, enclosed in quotation marks.
Example output:
The system will speak the Polish phrase “Litwo, ojczyzno moja!” using the specific Polish voice.
Use case 6: Create an audio file of the spoken text
Code:
say --output-file=filename.aiff "Here's to the Crazy Ones."
Motivation:
In situations where you want to save the spoken text for later use or include it in multimedia projects, this ‘say’ command use case allows you to create an audio file in AIFF format. The generated audio file can be easily played or shared with others.
Explanation:
say
: The command itself.--output-file=filename.aiff
: Specifies the output file name and format. Replace “filename.aiff” with the desired file name and format.
Example output:
The ‘say’ command will create an audio file named “filename.aiff” containing the spoken text “Here’s to the Crazy Ones.”
Conclusion
The ‘say’ command in macOS offers a range of functionalities to convert text into speech. From simply speaking a phrase aloud to customizing voices and speech rates, it provides a flexible and accessible way to interact with text content. Whether it’s proofreading, listening to documents, language learning, or multimedia projects, the ‘say’ command can be a valuable tool for users to enhance their productivity and accessibility.