Skip to content

Use the OpenAI TTS (text-to-speech) model to read any selected text on your Mac with a keyboard shortcut. Bring your own OpenAI API key.

Notifications You must be signed in to change notification settings

ryan-d-gordon/mac-openai-text-to-speech

Repository files navigation

OpenAI Text-to-Speech for macOS

A fun project that uses the OpenAI TTS (text-to-speech) model to read selected text on your Mac with a keyboard shortcut. This is instead of using the default macOS accessibility text reader, since OpenAI's text-to-speech sounds much better.

As of June 2024, the OpenAI TTS model is priced at $15 per 1 million characters processed.

How It Works

Select some text on a webpage or in the Apple Notes app, for example, and press the keyboard shortcut you defined. A window will appear letting you know how much the request will cost. (You can easily disable this feature if you want.)

cost

If you press continue, after a few seconds, the OpenAI-generated audio will start playing out of your system's default audio output and reading your text aloud.

Behind the Curtain

I'm using a combination of Python and Apple Scripts, plus an Automator Workflow to tie it all together and turn it into a macOS "Quick Action". Here's the Automator Workflow:

automator

Setup and Install

  1. If you don't already have one, sign up for an OpenAI account and generate an API key. See their quickstart guide for more info.

  2. Install the OpenAI Python library pip install openai

  3. Download both Python scripts openai-text-to-speech.py and openai-tts-cost-estimator.py and the OpenAI Text to Speech.zip file containing the Automator Workflow from this repo.

  4. Open openai-text-to-speech.py and replace YOUR_OPENAI_API_KEY_GOES_HERE with your OpenAI API key.

  5. Place both Python scripts in /usr/local/bin.

  6. Unzip the OpenAI Text to Speech.zip file and double click the OpenAI Text to Speech.workflow file to install it as a System Quick Action, or right click and open it with Automator to modify it to your liking first.

    install-service
  7. Finally, set up a keyboard shortcut on your Mac by visiting System Settings > Keyboard > Keyboard Shortcuts... > Services. Expand the Text list and find the OpenAI Text to Speech we just installed. Define your desired shortcut.


You can also run the Quick Action/Service by right clicking on any selected text, and selecting the action from the Services menu option:

Screenshot 2024-06-10 at 1 02 47 AM

About

Use the OpenAI TTS (text-to-speech) model to read any selected text on your Mac with a keyboard shortcut. Bring your own OpenAI API key.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages