A simple Python script that converts text to speech using the Siri voices available on macOS. This tool is designed to easily generate spoken messages for use in the Home Assistant app on your phone.
This script allows you to convert any text to speech using macOS’s built-in Siri voices. You can save the spoken message as a WAV file, which can then be used in applications like Home Assistant for notifications or alerts.
The script works in two modes:
- Voice Selection Mode: Allows you to choose a voice from the available Siri voices, and save that choice into a configuration file for future use.
- Text to Speech Mode: Reads the voice from the config file and converts any entered text into speech. If no voice is selected, it will ask you to select one first.
- Uses macOS's
say
command for generating speech - Converts AIFF files to WAV for cross-compatibility
- Automatically creates the output folder if it doesn't exist
- Plays the resulting audio file for quick feedback
- macOS (this script utilizes the
say
command, available on macOS) - Python 3.x
- Pixi for environment management
To run this script, you need to have pixi
set up. Follow these steps:
-
Install
pixi
by following their installation guide. -
Once
pixi
is installed, navigate to the project folder and initialize the environment:pixi run speak
-
pixi
will automatically install the necessary dependencies, likepydub
, using the providedpixi.toml
file.
-
Choosing a Voice First, you need to choose a Siri voice that the script will use. To do this, run the script and select from the available voices:
pixi run speak
The script will display a list of available voices on your system. Choose one, and it will be saved for future use in a configuration file.
-
Converting Text to Speech Once you have a voice configured, you can enter the text you want spoken. The script will use the preselected voice and create a WAV file of the spoken message. This file will be saved in the
audio-files
folder.If the folder does not exist, it will be created automatically.
-
Playing the Audio After generating the WAV file, the script will automatically play the audio so you can verify that everything works as expected.
Pixi is a minimal environment manager, similar to Conda, that ensures your project dependencies and environment are consistent across platforms.
In this project, the pixi.toml
file is used to define the project setup, including:
- The project name, version, and description.
- Dependencies (e.g.,
pydub
) that the script requires. - Task definitions, such as
speak
, which is the command that runs the Python script.
To get started with pixi
, make sure you have it installed. Then, simply use the pixi run
command to execute tasks:
pixi run speak
This command will install dependencies if necessary and run the speak.py
script.
Theo van der Sluijs Email: theo@vandersluijs.nl Resume: theovandersluijs.nl Website: itheo.tech Hire me for your next gig!
This project is licensed under the MIT License. See the LICENSE file for details.