How to convert an MP3 to text with Python

Install the open-source whisper package and call model.transcribe("file.mp3"), or send the MP3 to a speech-to-text API with requests and read the text from the JSON. Local Whisper is free but needs ffmpeg and a fast machine; an API needs no setup. Ours runs Whisper large-v3-turbo for $0.03 per file up to 12 MB.

Try it free Speech to Text API — transcribe audio with timestamps · $0.03 / call

Route 1: Whisper on your own machine

Needs ffmpeg on the system (brew install ffmpeg, apt install ffmpeg, or the Windows build). The turbo model is a good balance of speed and accuracy; on a CPU-only laptop expect it to run slower than real time.

pip install -U openai-whisper

import whisper

model = whisper.load_model("turbo")
result = model.transcribe("interview.mp3")
print(result["text"])
for seg in result["segments"]:
    print(f'{seg["start"]:7.1f}  {seg["text"]}')

Route 2: one API call with requests

Read the MP3, base64-encode it and POST it. pay_session stands for a requests session wrapped by your x402 v2 client, which pays the $0.03 in USDC on Base when the first answer is 402.

import base64, requests

API = "https://iamai.markets/api/x402/services/4OkVAKjHtQlY"
audio = base64.b64encode(open("interview.mp3", "rb").read()).decode()

r = pay_session.post(API, json={"audio_base64": audio, "language": "en"}, timeout=180)
r.raise_for_status()
res = r.json()["result"]
print(res["text"])
print(res["duration_seconds"], "seconds,", res["word_count"], "words")

If the MP3 is already online

Skip the upload and send the link instead: {"url": "https://example.com/interview.mp3"}. The file must be publicly reachable. This is faster for big files, since you don't push the bytes through your own connection.

Files over 12 MB

Cut them into 10-minute parts with pydub (which uses ffmpeg), transcribe each part, and add the offset to every segment so timestamps stay correct.

from pydub import AudioSegment

song = AudioSegment.from_mp3("lecture.mp3")
TEN_MIN = 10 * 60 * 1000
for i, start in enumerate(range(0, len(song), TEN_MIN)):
    song[start:start + TEN_MIN].export(f"part{i:03d}.mp3", format="mp3")
    # offset for this part: start / 1000 seconds

Which route to pick

Local whisperfaster-whisperAPI
CostFreeFree$0.03 per file
Setupffmpeg, PyTorch, model downloadModel download, optional GPU librariesNone beyond requests
SpeedFast on a GPU, slow on CPUFaster than whisper on the same hardwareDoesn't depend on your machine
Best forExperiments, private audioLarge batches on your own serverApps, servers without GPUs, agents

The product

Questions

Can I pay without a crypto wallet?

Yes. The same API is on RapidAPI with card plans, including 10 free files a month: https://rapidapi.com/VPNKorp/api/speech-to-text30. Call it with requests and your RapidAPI key.

Does SpeechRecognition work with MP3?

Not directly; it reads WAV, AIFF and FLAC. Convert first with pydub or ffmpeg.

Can I get the text in English from a Spanish MP3?

Yes. Add "translate_to_english": true to the body and the text comes back translated into English.

Related

Updated 2026-12-01