Best for · AI tools
Python speech to text (and text to speech): what to install
- Last checked
- 8 sources, linked below
- By the vectaai team
We read every plan page. Paid links are labelled. Money never changes a ranking. How we pick.
Verdict Our pick
The bar guide has a call.

- the SpeechRecognition package if you want one wrapper over many engines plus microphone input.
- Use the OpenAI Transcription API (gpt-transcribe, files up to 25 MB) when you would rather pay per minute than run a model.
Compared here
- 01SpeechRecognition
- 02OpenAI Whisper
- 03faster-whisper
- 04OpenAI Transcription API
- 05pyttsx3
- 06gTTS
- 07ElevenLabs Python SDK
Short answer
For speech to text in Python, start with faster-whisper if you want free, offline, accurate transcription of files: pip install faster-whisper, no separate ffmpeg needed, MIT licence, and its README says up to 4x faster than OpenAI's original Whisper at the same accuracy. Use the SpeechRecognition package if you want one wrapper over many engines plus microphone input. Use the OpenAI Transcription API (gpt-transcribe, files up to 25 MB) when you would rather pay per minute than run a model.
For text to speech in Python, pyttsx3 speaks fully offline using your operating system's voices, gTTS makes MP3s through Google Translate's voice (online, unofficial), and the ElevenLabs SDK gives the most natural voices for a fee. Below: a pick table, working snippets from each project's own docs, the gotchas (PyAudio, ffmpeg, GPU memory) and which to choose for which job.
Sponsored links. We may earn a commission; it never changes the pick.
At a glance
| Library | Direction | Runs offline? | Cost | Install | Best for |
|---|---|---|---|---|---|
| faster-whisper | Speech to text | Yes | Free, MIT | pip install faster-whisper | Accurate file transcription on your own machine |
| openai-whisper | Speech to text | Yes | Free, MIT | pip install -U openai-whisper (plus ffmpeg) | The reference Whisper, simplest code |
| SpeechRecognition 3.18.0 | Speech to text | Some engines (Sphinx, Vosk, Whisper, NeMo) | Free, BSD-3; online engines may charge | pip install SpeechRecognition | Microphone input, swapping engines |
| OpenAI Transcription API | Speech to text | No | Paid per use | pip install openai | No GPU, fast setup, 25 MB per file |
| pyttsx3 | Text to speech | Yes | Free, MPL-2.0 | pip install pyttsx3 | Offline voice using OS voices |
| gTTS 2.5.4 | Text to speech | No | Free, MIT; unofficial | pip install gTTS | Quick MP3 files |
| ElevenLabs SDK | Text to speech (and more) | No | Paid plans, free tier | pip install elevenlabs | Natural voices for apps and video |
Money first. ElevenLabs pays affiliates, and our /go/ link to it may earn us a cut. Everything else on this page is free open source software, which earns us exactly nothing, and most readers should start there. The FTC's disclosure guide is why we say so.
How we wrote it: every install command, snippet, licence and limit below comes from each project's own PyPI or GitHub page, OpenAI's speech to text guide and ElevenLabs' quickstart, read on 4 December 2026. We did not benchmark accuracy or speed ourselves; where a speed claim appears, it is the project's own. Library versions move fast, so check the page before you pin a version in production.
Pick by job
| You want to... | Use | Why |
|---|---|---|
| Transcribe audio files, free, offline | faster-whisper | Whisper accuracy, lighter and faster per its README |
| Learn, or need the simplest Whisper code | openai-whisper | Reference implementation, three lines of code |
| Listen to a microphone and react | SpeechRecognition | Built-in Microphone class, many engines |
| Transcribe with no GPU and no setup | OpenAI Transcription API | Upload file, get text |
| Make your script talk, offline | pyttsx3 | Uses Windows, macOS or Linux voices |
| Save an MP3 of some text, quickly | gTTS | Two lines, needs internet |
| Natural voices for an app or video | ElevenLabs SDK | Paid, human-sounding voices |
Notice the split. The members of this search mix up "python speech to text" and "python text to speech". They are opposite jobs. Speech to text listens and writes. Text to speech reads aloud. Different libraries, so pick from the right half of the table.
Speech to text in Python
faster-whisper: the default pick for files
faster-whisper is a reimplementation of OpenAI's Whisper on CTranslate2, a fast inference engine. Its README says it is "up to 4 times faster than openai/whisper for the same accuracy while using less memory." In the README's own large-v2 GPU benchmark, faster-whisper at int8 used 2,926 MB of video memory versus 4,708 MB for the original at fp16.
The quality-of-life win: no separate ffmpeg install. It decodes audio with PyAV, which bundles the ffmpeg libraries. Python 3.9 or newer, MIT licence.
# pip install faster-whisper
from faster_whisper import WhisperModel
model = WhisperModel("large-v3", device="cpu", compute_type="int8")
segments, info = model.transcribe("audio.mp3", beam_size=5)
for segment in segments:
print(f"[{segment.start:.2f}s -> {segment.end:.2f}s] {segment.text}")
Gotcha: transcription is lazy. Nothing runs until you loop over segments. If your script "finishes instantly" and prints nothing, that is why.
On a laptop without a GPU, start with a small model ("small" or "base") and move up only if accuracy is not good enough.
openai-whisper: the reference
OpenAI's Whisper repo is where it all started. Code and model weights are under the MIT License. It handles multilingual recognition, translation into English and language identification.
# pip install -U openai-whisper (and install ffmpeg on your system)
import whisper
model = whisper.load_model("turbo")
result = model.transcribe("audio.mp3")
print(result["text"])
Two gotchas: it needs the ffmpeg command-line tool installed separately, and the README says the code was tested on Python 3.9.9 and is expected to work on 3.8 to 3.11. Newer Python may work; it is not what the README promises.
Model sizes from the README, with speed relative to large:
| Model | Parameters | Video memory | Relative speed |
|---|---|---|---|
| tiny | 39M | about 1 GB | about 10x |
| base | 74M | about 1 GB | about 7x |
| small | 244M | about 2 GB | about 4x |
| medium | 769M | about 5 GB | about 2x |
| large | 1,550M | about 10 GB | 1x |
| turbo | 809M | about 6 GB | about 8x |
turbo is an optimised large-v3: much faster, small accuracy loss. One catch from the README: turbo is not trained for translation. If you want Spanish audio turned into English text, use medium or large.
SpeechRecognition: one wrapper, many engines, and the microphone
SpeechRecognition (version 3.18.0 on PyPI, released 29 November 2026, Python 3.10+, BSD-3 licence) is not a model. It is a wrapper that talks to many engines with one API:
- Offline: CMU Sphinx, Snowboy, Vosk, OpenAI Whisper, NVIDIA NeMo.
- Online: Google Speech Recognition, Google Cloud Speech, Wit.ai, Microsoft Azure Speech, Houndify, IBM, the OpenAI transcription API (including OpenAI-compatible self-hosted endpoints), Groq's Whisper API and Cohere Transcribe.
Its big advantage is the Microphone class. If your project listens to a person talking, this is the easiest start.
# pip install SpeechRecognition (Windows: pip install SpeechRecognition[audio])
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something")
audio = r.listen(source)
print(r.recognize_google(audio))
That uses the free Google web recogniser, which needs internet. Swap recognize_google for one of the offline engines if you need it to work on a plane.
The number one error: microphone input needs PyAudio 0.2.11 or newer. Without it, creating a Microphone raises an AttributeError. On Windows, the [audio] extra installs it. On macOS and Linux, install PortAudio with your package manager first, then PyAudio.
OpenAI Transcription API: pay instead of run
If you do not want models on your machine, OpenAI's speech to text guide recommends a model called gpt-transcribe. The guide says whisper-1, gpt-4o-transcribe and gpt-4o-mini-transcribe are deprecated and scheduled to shut down on 26 February 2027. If you have old code calling whisper-1, put that date in your calendar.
Limits from the guide: files up to 25 MB, in flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav or webm. Longer recordings need splitting. Setting stream=true returns transcript events as it works through a finished file; for live microphone or call audio, the guide points you to its Realtime transcription instead.
# pip install openai (set OPENAI_API_KEY)
from openai import OpenAI
client = OpenAI()
with open("audio.mp3", "rb") as f:
transcription = client.audio.transcriptions.create(model="gpt-transcribe", file=f)
print(transcription.text)
It costs money per use; check OpenAI's pricing page, we do not quote it here. Our Claude API vs subscription page explains how per-use API billing compares with flat plans in general.
Text to speech in Python
pyttsx3: offline, free, robotic-ish
pyttsx3 is fully offline. It drives the voices already on your system: SAPI5 or eSpeak on Windows, eSpeak, NSSpeechSynthesizer (deprecated by Apple) or AVSpeech (experimental) on macOS, eSpeak on Linux. MPL-2.0 licence.
# pip install pyttsx3
import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()
If Linux stays silent, the README says to install espeak-ng and libespeak1. If macOS throws a pyobjc error, install pyobjc 9.0.1 or newer. Quality is as good as your operating system's voices, which on Windows and macOS is decent and on bare Linux eSpeak is... characterful.
gTTS: an MP3 in two lines
gTTS (2.5.4, MIT licence, Python 3.7+) talks to Google Translate's text to speech, not Google Cloud. It is unofficial: the page says it is "not affiliated with Google or Google Cloud" and that "breaking upstream changes can occur without notice." It needs internet, since the voice comes from Google's servers.
# pip install gTTS
from gtts import gTTS
gTTS("hello").save("hello.mp3")
Fine for scripts and hobby projects. For anything customers rely on, an unofficial API that can break without notice is a bad foundation.
ElevenLabs SDK: natural voices, paid
For voices that sound like people, ElevenLabs' quickstart uses its Python SDK. Install with pip install elevenlabs, store your key as ELEVENLABS_API_KEY, and call text_to_speech.convert; the example uses the model eleven_v4.
# pip install elevenlabs (set ELEVENLABS_API_KEY)
import os
from elevenlabs.client import ElevenLabs
from elevenlabs import play
elevenlabs = ElevenLabs(api_key=os.getenv("ELEVENLABS_API_KEY"))
audio = elevenlabs.text_to_speech.convert(
text="The first move is what sets everything in motion.",
voice_id="YOUR_VOICE_ID",
model_id="eleven_v4",
output_format="mp3_44100_128",
)
play(audio)
Replace YOUR_VOICE_ID with a voice from your ElevenLabs account. Usage is billed in credits; our ElevenLabs credits page works out the price per credit, and ElevenLabs alternatives covers the competition.
Which one should you pick?
- A student project or a script for yourself: faster-whisper for listening, pyttsx3 for talking. Both free, both offline.
- A voice assistant that reacts to speech: SpeechRecognition with an offline engine for the microphone loop, pyttsx3 or ElevenLabs to answer.
- Batch transcription of hundreds of files: faster-whisper on a GPU if you have one; the OpenAI API if you do not and the budget is fine.
- A product with customers: a paid API for both directions, because support, uptime and a contract matter more than saving a few dollars. Avoid gTTS there.
- No coding at all: you are on the wrong page. Our best speech to text apps and best free text to speech guides cover apps you just open and use.
Common errors, fixed
AttributeErroron Microphone: PyAudio missing. See above.FileNotFoundErrorwith openai-whisper: ffmpeg is not installed or not on your PATH. Install it, or switch to faster-whisper, which bundles what it needs.- CUDA out of memory: pick a smaller model, or use
compute_type="int8"with faster-whisper. - Script ends with no output in faster-whisper: you never looped over
segments. - gTTS suddenly fails: Google changed something upstream. The project warns this can happen.
- API file too large: OpenAI caps files at 25 MB. Split the audio or compress it.
More in the AI tools category.
Questions people ask
What is the best Python library for speech to text?
For files on your own machine, faster-whisper: free, offline, MIT licensed, and its README claims up to 4x the speed of OpenAI's Whisper at the same accuracy with less memory. For live microphone input with a simple API, SpeechRecognition. For no setup at all, the OpenAI Transcription API, paid per use.
How do I convert speech to text in Python offline?
Install faster-whisper or openai-whisper and run a model locally. Neither needs internet after the model downloads. SpeechRecognition also lists offline engines: CMU Sphinx, Vosk, Whisper and NVIDIA NeMo. Smaller Whisper models like tiny and base need about 1 GB of video memory per the Whisper README, and run on CPU, just slower.
How do I do text to speech in Python?
The shortest offline route is pyttsx3: import it, call init(), then say() and runAndWait(). It uses your system's voices, so quality depends on your OS. For an MP3 file, gTTS saves one in two lines but needs internet. For natural, human-sounding voices, the ElevenLabs SDK, which needs an API key.
Why does SpeechRecognition fail on the microphone?
Microphone input needs PyAudio 0.2.11 or newer. Without it, creating a Microphone object raises an AttributeError, per the package page. On Windows, pip install SpeechRecognition[audio] pulls it in. On macOS and Linux, install PortAudio first with your package manager, then PyAudio.
Is Whisper free to use in Python?
Yes. OpenAI says Whisper's code and model weights are under the MIT License, so running it locally costs you nothing but hardware and electricity. OpenAI's hosted transcription API is a different thing and is paid; its guide now recommends a model called gpt-transcribe, and says whisper-1 is deprecated.
Can Python transcribe audio in real time?
Yes, but pick the right tool. OpenAI's guide points live microphone or call audio to its Realtime transcription, not the file endpoint. Locally, you can feed short microphone chunks from SpeechRecognition to a Whisper engine. Expect a delay of a second or more on a laptop CPU with larger models.
Sources
Every fact above comes from these pages. Prices change, so each one carries the date we read it.
- PyPI: SpeechRecognition, checked 4 Dec 2026
- GitHub: openai/whisper, checked 4 Dec 2026
- GitHub: SYSTRAN/faster-whisper, checked 4 Dec 2026
- OpenAI API docs: Speech to text, checked 4 Dec 2026
- GitHub: nateshmbhat/pyttsx3, checked 4 Dec 2026
- PyPI: gTTS, checked 4 Dec 2026
- ElevenLabs docs: Quickstart, checked 4 Dec 2026
- FTC: Disclosures 101 for social media influencers, checked 4 Dec 2026