Skip to main content

Create transcription

Transcribes audio into the input language.
from openai import OpenAI

client = OpenAI()

audio_file = open("speech.mp3", "rb")
transcription = client.audio.transcriptions.create(
    model="whisper-1",
    file=audio_file
)

print(transcription.text)

Parameters

file
file
required
The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
model
string
required
ID of the model to use. Available models:
  • whisper-1 - Powered by OpenAI’s open source Whisper V2 model
  • gpt-4o-transcribe - GPT-4 optimized transcription
  • gpt-4o-mini-transcribe - GPT-4 mini transcription
  • gpt-4o-mini-transcribe-2025-12-15 - Latest GPT-4 mini transcription
  • gpt-4o-transcribe-diarize - GPT-4 transcription with speaker diarization
language
string
The language of the input audio. Supplying the input language in ISO-639-1 format (e.g. en) will improve accuracy and latency.
prompt
string
An optional text to guide the model’s style or continue a previous audio segment. The prompt should match the audio language. Not supported when using gpt-4o-transcribe-diarize.
response_format
string
default:"json"
The format of the output. Options: json, text, srt, verbose_json, vtt, or diarized_json.
  • For gpt-4o-transcribe and gpt-4o-mini-transcribe, only json is supported
  • For gpt-4o-transcribe-diarize, supported formats are json, text, and diarized_json (required for speaker annotations)
temperature
float
default:"0"
The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.
timestamp_granularities
array
The timestamp granularities to populate for this transcription. response_format must be set to verbose_json to use timestamp granularities. Options: word or segment.Note: There is no additional latency for segment timestamps, but generating word timestamps incurs additional latency. Not available for gpt-4o-transcribe-diarize.
stream
boolean
default:"false"
If set to true, the model response data will be streamed to the client as it is generated using server-sent events. Not supported for the whisper-1 model.
chunking_strategy
object
Controls how the audio is cut into chunks. When set to "auto", the server first normalizes loudness and then uses voice activity detection (VAD) to choose boundaries. Required when using gpt-4o-transcribe-diarize for inputs longer than 30 seconds.
include
array
Additional information to include in the transcription response. logprobs will return the log probabilities of the tokens in the response. Only works with response_format set to json and only with the models gpt-4o-transcribe, gpt-4o-mini-transcribe, and gpt-4o-mini-transcribe-2025-12-15. Not supported when using gpt-4o-transcribe-diarize.
known_speaker_names
array
Optional list of speaker names that correspond to the audio samples provided in known_speaker_references[]. Each entry should be a short identifier (e.g. customer or agent). Up to 4 speakers are supported.
known_speaker_references
array
Optional list of audio samples (as data URLs) that contain known speaker references matching known_speaker_names[]. Each sample must be between 2 and 10 seconds, and can use any of the same input audio formats supported by file.

Response

text
string
The transcribed text.
logprobs
array
The log probabilities of the tokens in the transcription. Only returned with certain models when logprobs is added to the include array.
usage
object
Token usage statistics for the request.

Examples

Basic transcription

from openai import OpenAI

client = OpenAI()

audio_file = open("audio.mp3", "rb")
transcription = client.audio.transcriptions.create(
    model="whisper-1",
    file=audio_file
)

print(transcription.text)

Transcribe with language hint

from openai import OpenAI

client = OpenAI()

audio_file = open("french_audio.mp3", "rb")
transcription = client.audio.transcriptions.create(
    model="whisper-1",
    file=audio_file,
    language="fr"  # French audio
)

print(transcription.text)

Get SRT subtitles

from openai import OpenAI

client = OpenAI()

audio_file = open("video_audio.mp3", "rb")
transcription = client.audio.transcriptions.create(
    model="whisper-1",
    file=audio_file,
    response_format="srt"
)

# Save SRT file
with open("subtitles.srt", "w") as f:
    f.write(transcription)

Transcribe with timestamps

from openai import OpenAI

client = OpenAI()

audio_file = open("audio.mp3", "rb")
transcription = client.audio.transcriptions.create(
    model="whisper-1",
    file=audio_file,
    response_format="verbose_json",
    timestamp_granularities=["word", "segment"]
)

# Access segments with timestamps
for segment in transcription.segments:
    print(f"[{segment['start']:.2f}s - {segment['end']:.2f}s] {segment['text']}")

Speaker diarization

from openai import OpenAI

client = OpenAI()

audio_file = open("conversation.mp3", "rb")
transcription = client.audio.transcriptions.create(
    model="gpt-4o-transcribe-diarize",
    file=audio_file,
    response_format="diarized_json",
    chunking_strategy="auto"
)

# Access speaker-segmented transcription
for segment in transcription.segments:
    speaker = segment.get('speaker', 'Unknown')
    print(f"{speaker}: {segment['text']}")

Streaming transcription

from openai import OpenAI

client = OpenAI()

audio_file = open("audio.mp3", "rb")

# Stream transcription events
stream = client.audio.transcriptions.create(
    model="gpt-4o-mini-transcribe",
    file=audio_file,
    stream=True
)

for event in stream:
    if event.type == "transcription.text.delta":
        print(event.delta, end="", flush=True)

Transcribe with prompt for context

from openai import OpenAI

client = OpenAI()

audio_file = open("meeting.mp3", "rb")
transcription = client.audio.transcriptions.create(
    model="whisper-1",
    file=audio_file,
    prompt="This is a quarterly business review meeting discussing Q4 revenue targets."
)

print(transcription.text)

Get log probabilities

from openai import OpenAI

client = OpenAI()

audio_file = open("audio.mp3", "rb")
transcription = client.audio.transcriptions.create(
    model="gpt-4o-mini-transcribe",
    file=audio_file,
    response_format="json",
    include=["logprobs"]
)

print(f"Transcription: {transcription.text}")

# Check confidence scores
if transcription.logprobs:
    for logprob in transcription.logprobs:
        print(f"Token: {logprob.token}, Confidence: {logprob.logprob}")

Async usage

import asyncio
from openai import AsyncOpenAI

async def transcribe_audio():
    client = AsyncOpenAI()
    
    audio_file = open("audio.mp3", "rb")
    transcription = await client.audio.transcriptions.create(
        model="whisper-1",
        file=audio_file
    )
    
    print(transcription.text)

asyncio.run(transcribe_audio())

Supported audio formats

The transcription endpoint supports the following audio formats:
  • flac - Free Lossless Audio Codec
  • mp3 - MPEG audio format
  • mp4 - MPEG-4 Part 14
  • mpeg - MPEG audio
  • mpga - MPEG audio
  • m4a - MPEG-4 audio
  • ogg - Ogg Vorbis
  • wav - Waveform audio
  • webm - WebM audio

File uploads

Files are uploaded using multipart/form-data. The file object should be opened in binary mode:
# Correct way to open file
audio_file = open("path/to/file.mp3", "rb")

# Or using pathlib
from pathlib import Path
audio_file = Path("path/to/file.mp3").open("rb")
For more information on prompting and best practices, see the Speech to text guide.

Build docs developers (and LLMs) love