SPB Git

Repository Public

speech-to-text.md 38.6 KB 1,370 lines markdown

1# File transcription23> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.45Use file transcription when you have a completed recording or a bounded audio request. Upload the audio and receive a final transcript, or stream text while the model processes the file.67Start with [`gpt-transcribe`](https://developers.openai.com/api/docs/models/gpt-transcribe). This is the recommended model for transcribing recorded speech in its original language. Use a specialized model only if you need speaker labels, word timestamps, subtitle formats, or translation into English.89Files can be up to 25 MB. Supported input formats are `mp3`, `mp4`, `mpeg`, `mpga`, `m4a`, `wav`, and `webm`.1011For audio that is still arriving from a microphone, call, or media stream, use12  [Realtime transcription](https://developers.openai.com/api/docs/guides/realtime-transcription).1314## Quickstart1516### Transcriptions1718Send the audio file to `/v1/audio/transcriptions` with `gpt-transcribe`:1920Transcribe audio2122```javascript23import fs from "fs";24import OpenAI from "openai";2526const openai = new OpenAI();2728const transcription = await openai.audio.transcriptions.create({29  file: fs.createReadStream("fixtures/audio.wav"),30  model: "gpt-transcribe",31});3233console.log(transcription.text);34```3536```python37from openai import OpenAI3839client = OpenAI()40audio_file = open("audio.wav", "rb")4142transcription = client.audio.transcriptions.create(43    model="gpt-transcribe", file=audio_file44)4546print(transcription.text)47```4849```go50package main5152import (53	"context"54	"fmt"55	"os"5657	"github.com/openai/openai-go/v3"58)5960func main() {61	file, err := os.Open("fixtures/audio.wav")62	if err != nil {63		panic(err)64	}65	defer file.Close()6667	client := openai.NewClient()68	transcription, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{69		File:  file,70		Model: "gpt-transcribe",71	})72	if err != nil {73		panic(err)74	}75	fmt.Println(transcription.Text)76}77```7879```java80import com.openai.client.OpenAIClient;81import com.openai.client.okhttp.OpenAIOkHttpClient;82import com.openai.models.audio.transcriptions.TranscriptionCreateParams;83import java.nio.file.Path;8485var result =86    client87        .audio()88        .transcriptions()89        .create(90            TranscriptionCreateParams.builder()91                .file(Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH")))92                .model("gpt-transcribe")93                .build());9495System.out.println(result.asTranscription().text());96```9798```csharp99using OpenAI.Audio;100101string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;102string model = "gpt-transcribe";103AudioClient client = new(model, key);104105await using FileStream audio = File.OpenRead("audio.wav");106AudioTranscription transcription = await client.TranscribeAudioAsync(107    audio,108    "audio.wav"109);110111Console.WriteLine(transcription.Text);112```113114```ruby115require "openai"116require "pathname"117118client = OpenAI::Client.new119audio = Pathname("audio.wav")120transcript = client.audio.transcriptions.create(121  file: audio,122  model: "gpt-transcribe"123)124puts(transcript.text)125```126127```bash128openai audio:transcriptions create \129  --model gpt-transcribe \130  --file /path/to/file/audio.mp3 \131  --raw-output \132  --transform text133```134135```bash136curl --request POST \137  --url https://api.openai.com/v1/audio/transcriptions \138  --header "Authorization: Bearer $OPENAI_API_KEY" \139  --header 'Content-Type: multipart/form-data' \140  --form file=@/path/to/file/audio.mp3 \141  --form model=gpt-transcribe142```143144145The model returns the transcript and the detected languages as JSON:146147```json148{149  "text": "Bonjour, pouvez-vous m'entendre ?",150  "languages": [{ "code": "fr" }]151}152```153154When the model can't make a reliable language prediction, it returns `"languages": []`. See the [Audio API reference](https://developers.openai.com/api/reference/resources/audio) for the complete request and response fields.155156## Add transcription context157158Use `prompt`, `keywords`, and `languages` with `gpt-transcribe` to improve transcription of domain terms and multilingual audio:159160Add context and language hints161162```javascript163import fs from "fs";164import OpenAI from "openai";165166const openai = new OpenAI();167168const request = {169  model: "gpt-transcribe",170  file: fs.createReadStream("fixtures/audio.wav"),171  prompt: "A customer support call about a premium plan and account AC-42.",172};173174const transcription = await openai.audio.transcriptions.create(request, {175  body: {176    ...request,177    keywords: ["premium plan", "AC-42", "billing"],178    languages: ["en", "fr"],179  },180});181182console.log(transcription.text);183```184185```python186from openai import OpenAI187188client = OpenAI()189190with open("meeting.wav", "rb") as audio_file:191    transcription = client.audio.transcriptions.create(192        model="gpt-transcribe",193        file=audio_file,194        prompt="A customer support call about a premium plan and account AC-42.",195        extra_body={196            "keywords": ["premium plan", "AC-42", "billing"],197            "languages": ["en", "fr"],198        },199    )200201print(transcription.text)202```203204```go205package main206207import (208	"context"209	"fmt"210	"os"211212	"github.com/openai/openai-go/v3"213)214215func main() {216	file, err := os.Open("fixtures/audio.wav")217	if err != nil {218		panic(err)219	}220	defer file.Close()221222	parameters := openai.AudioTranscriptionNewParams{223		File:   file,224		Model:  "gpt-transcribe",225		Prompt: openai.String("A customer support call about a premium plan and account AC-42."),226	}227	parameters.SetExtraFields(map[string]any{228		"keywords":  []string{"premium plan", "AC-42", "billing"},229		"languages": []string{"en", "fr"},230	})231	client := openai.NewClient()232	transcription, err := client.Audio.Transcriptions.New(context.Background(), parameters)233	if err != nil {234		panic(err)235	}236	fmt.Println(transcription.Text)237}238```239240```java241import com.openai.client.OpenAIClient;242import com.openai.client.okhttp.OpenAIOkHttpClient;243import com.openai.core.JsonValue;244import com.openai.models.audio.transcriptions.TranscriptionCreateParams;245import java.nio.file.Path;246import java.util.List;247248var result =249    client250        .audio()251        .transcriptions()252        .create(253            TranscriptionCreateParams.builder()254                .file(Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH")))255                .model("gpt-transcribe")256                .prompt("A customer support call about a premium plan and account AC-42.")257                .putAdditionalBodyProperty(258                    "keywords", JsonValue.from(List.of("premium plan", "AC-42", "billing")))259                .putAdditionalBodyProperty("languages", JsonValue.from(List.of("en", "fr")))260                .build());261262System.out.println(result.asTranscription().text());263```264265```ruby266require "openai"267require "pathname"268269client = OpenAI::Client.new270audio = Pathname("audio.wav")271transcript = client.audio.transcriptions.create(272  file: audio,273  model: "gpt-transcribe",274  keywords: ["OpenAI", "Responses API", "Codex"]275)276puts(transcript.text)277```278279```bash280curl https://api.openai.com/v1/audio/transcriptions \281  -H "Authorization: Bearer $OPENAI_API_KEY" \282  -H "Content-Type: multipart/form-data" \283  -F model="gpt-transcribe" \284  -F file="@/path/to/file/meeting.wav" \285  -F 'prompt=A customer support call about a premium plan and account AC-42.' \286  -F 'keywords[]=premium plan' \287  -F 'keywords[]=AC-42' \288  -F 'keywords[]=billing' \289  -F 'languages[]=en' \290  -F 'languages[]=fr'291```292293294- Use `prompt` for unstructured context about the recording.295- Use `keywords` for literal terms you expect to hear.296- Use `languages` for the expected input languages.297298Keywords are hints, not required output. Include only relevant terms, and evaluate whether they improve accuracy without causing unspoken terms to appear.299300For `gpt-transcribe`, `languages` replaces the singular `language` field. Don't send both fields. Keep each keyword on one line and don't include `<`, `>`, a carriage return, or a line feed. The API rejects the entire request when it encounters one of these characters or when `prompt` exceeds the model's length limit.301302## Speaker diarization303304Use `gpt-4o-transcribe-diarize` only when you need to identify who speaks during different parts of a recording. This specialized speaker-labeling model isn't the recommended model for ordinary file transcription.305306Request the `diarized_json` response format to receive segments with `speaker`, `start`, and `end` metadata. For audio longer than 30 seconds, set `chunking_strategy` to `"auto"` or a voice activity detection configuration.307308You can optionally supply up to four short audio references with `known_speaker_names[]` and `known_speaker_references[]` to map segments onto known speakers. Provide reference clips between 2–10 seconds in any input format supported by the main audio upload; encode them as [data URLs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs) when using multipart form data.309310Diarize a meeting recording311312```javascript313import fs from "fs";314import OpenAI from "openai";315316const openai = new OpenAI();317318const agentRef = fs.readFileSync("fixtures/agent.wav").toString("base64");319320const transcript = await openai.audio.transcriptions.create({321  file: fs.createReadStream("fixtures/meeting.wav"),322  model: "gpt-4o-transcribe-diarize",323  response_format: "diarized_json",324  chunking_strategy: "auto",325  known_speaker_names: ["agent"],326  known_speaker_references: ["data:audio/wav;base64," + agentRef],327});328329for (const segment of transcript.segments) {330  if (!("speaker" in segment)) continue;331332  console.log(333    `${segment.speaker}: ${segment.text}`,334    segment.start,335    segment.end336  );337}338```339340```python341import base64342from openai import OpenAI343344client = OpenAI()345346347def to_data_url(path: str) -> str:348    with open(path, "rb") as fh:349        return "data:audio/wav;base64," + base64.b64encode(fh.read()).decode("utf-8")350351352with open("meeting.wav", "rb") as audio_file:353    transcript = client.audio.transcriptions.create(354        model="gpt-4o-transcribe-diarize",355        file=audio_file,356        response_format="diarized_json",357        chunking_strategy="auto",358        extra_body={359            "known_speaker_names": ["agent"],360            "known_speaker_references": [to_data_url("agent.wav")],361        },362    )363364for segment in transcript.segments:365    print(segment.speaker, segment.text, segment.start, segment.end)366```367368```go369package main370371import (372	"context"373	"encoding/base64"374	"encoding/json"375	"fmt"376	"os"377378	"github.com/openai/openai-go/v3"379	"github.com/openai/openai-go/v3/shared/constant"380)381382type diarizedTranscript struct {383	Segments []struct {384		Speaker string  `json:"speaker"`385		Text    string  `json:"text"`386		Start   float64 `json:"start"`387		End     float64 `json:"end"`388	} `json:"segments"`389}390391func main() {392	agentAudio, err := os.ReadFile("fixtures/agent.wav")393	if err != nil {394		panic(err)395	}396	meeting, err := os.Open("fixtures/meeting.wav")397	if err != nil {398		panic(err)399	}400	defer meeting.Close()401402	client := openai.NewClient()403	transcription, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{404		File:           meeting,405		Model:          "gpt-4o-transcribe-diarize",406		ResponseFormat: openai.AudioResponseFormatDiarizedJSON,407		ChunkingStrategy: openai.AudioTranscriptionNewParamsChunkingStrategyUnion{408			OfAuto: constant.ValueOf[constant.Auto](),409		},410		KnownSpeakerNames:      []string{"agent"},411		KnownSpeakerReferences: []string{"data:audio/wav;base64," + base64.StdEncoding.EncodeToString(agentAudio)},412	})413	if err != nil {414		panic(err)415	}416	var result diarizedTranscript417	if err := json.Unmarshal([]byte(transcription.RawJSON()), &result); err != nil {418		panic(err)419	}420	for _, segment := range result.Segments {421		fmt.Println(segment.Speaker+":", segment.Text, segment.Start, segment.End)422	}423}424```425426```java427import com.fasterxml.jackson.databind.json.JsonMapper;428import com.openai.client.OpenAIClient;429import com.openai.client.okhttp.OpenAIOkHttpClient;430import com.openai.models.audio.AudioResponseFormat;431import com.openai.models.audio.transcriptions.TranscriptionCreateParams;432import com.openai.models.audio.transcriptions.TranscriptionDiarized;433import java.nio.file.Files;434import java.nio.file.Path;435import java.util.Base64;436437Path audio = Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH"));438Path speakerAudio = Path.of(System.getenv("OPENAI_EXAMPLE_SPEAKER_AUDIO_PATH"));439String speakerReference =440    "data:audio/wav;base64,"441        + Base64.getEncoder().encodeToString(Files.readAllBytes(speakerAudio));442443var result =444    client445        .audio()446        .transcriptions()447        .create(448            TranscriptionCreateParams.builder()449                .file(audio)450                .model("gpt-4o-transcribe-diarize")451                .responseFormat(AudioResponseFormat.DIARIZED_JSON)452                .chunkingStrategyAuto()453                .addKnownSpeakerName("agent")454                .addKnownSpeakerReference(speakerReference)455                .build());456457TranscriptionDiarized diarized =458    result.isDiarized()459        ? result.asDiarized()460        : new JsonMapper()461            .readValue(result.asTranscription().text(), TranscriptionDiarized.class);462for (var segment : diarized.segments()) {463  System.out.println(464      segment.speaker()465          + ": "466          + segment.text()467          + " ("468          + segment.start()469          + "-"470          + segment.end()471          + ")");472}473```474475```ruby476require "base64"477require "openai"478require "pathname"479480client = OpenAI::Client.new481audio = Pathname("meeting.wav")482speaker_reference = Base64.strict_encode64(File.binread("agent.wav"))483transcript = client.audio.transcriptions.create(484  file: audio,485  model: "gpt-4o-transcribe-diarize",486  response_format: :diarized_json,487  chunking_strategy: :auto,488  known_speaker_names: ["agent"],489  known_speaker_references: ["data:audio/wav;base64,#{speaker_reference}"]490)491segments = Array(492  transcript.to_h.fetch(:segments) do493    raise "The transcription did not include speaker segments"494  end495)496segments.each do |segment|497  segment = Hash.try_convert(segment) or raise "Invalid speaker segment"498  puts(499    "#{segment.fetch(:speaker)}: #{segment.fetch(:text)} " \500      "(#{segment.fetch(:start)}-#{segment.fetch(:end_)})"501  )502end503```504505```bash506curl --request POST \507  --url https://api.openai.com/v1/audio/transcriptions \508  --header "Authorization: Bearer $OPENAI_API_KEY" \509  --header 'Content-Type: multipart/form-data' \510  --form file=@/path/to/file/meeting.wav \511  --form model=gpt-4o-transcribe-diarize \512  --form response_format=diarized_json \513  --form chunking_strategy=auto \514  --form 'known_speaker_names[]=agent' \515  --form 'known_speaker_references[]=data:audio/wav;base64,AAA...'516```517518519When `stream=true`, speaker-labeled responses emit `transcript.text.segment` events whenever a segment completes. `transcript.text.delta` events include a `segment_id` field, but deltas don't include partial speaker assignments. The model assigns a speaker only when it finalizes the segment.520521Speaker labeling is available through `/v1/audio/transcriptions`. It isn't522  supported in Realtime transcription sessions.523524## Translations525526To translate a completed audio recording into English, use `/v1/audio/translations` with `whisper-1`. Unlike transcription, which preserves the recording's original language, this endpoint returns English text.527528Translate audio529530```javascript531import fs from "fs";532import OpenAI from "openai";533534const openai = new OpenAI();535536const translation = await openai.audio.translations.create({537  file: fs.createReadStream("fixtures/german.wav"),538  model: "whisper-1",539});540541console.log(translation.text);542```543544```python545from openai import OpenAI546547client = OpenAI()548audio_file = open("german.wav", "rb")549550translation = client.audio.translations.create(551    model="whisper-1",552    file=audio_file,553)554555print(translation.text)556```557558```go559package main560561import (562	"context"563	"fmt"564	"os"565566	"github.com/openai/openai-go/v3"567)568569func main() {570	file, err := os.Open("fixtures/german.wav")571	if err != nil {572		panic(err)573	}574	defer file.Close()575576	client := openai.NewClient()577	translation, err := client.Audio.Translations.New(context.Background(), openai.AudioTranslationNewParams{578		File:  file,579		Model: openai.AudioModelWhisper1,580	})581	if err != nil {582		panic(err)583	}584	fmt.Println(translation.Text)585}586```587588```java589import com.openai.client.OpenAIClient;590import com.openai.client.okhttp.OpenAIOkHttpClient;591import com.openai.models.audio.translations.TranslationCreateParams;592import java.nio.file.Path;593594var result =595    client596        .audio()597        .translations()598        .create(599            TranslationCreateParams.builder()600                .file(Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH")))601                .model("whisper-1")602                .build());603604System.out.println(result.asTranslation().text());605```606607```csharp608using OpenAI.Audio;609610string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;611AudioClient client = new("whisper-1", key);612613await using FileStream audio = File.OpenRead("german.wav");614AudioTranslation translation = await client.TranslateAudioAsync(615    audio,616    "german.wav"617);618619Console.WriteLine(translation.Text);620```621622```ruby623require "openai"624require "pathname"625626client = OpenAI::Client.new627audio = Pathname("german.wav")628translation = client.audio.translations.create(file: audio, model: "whisper-1")629puts(translation.text)630```631632```bash633curl --request POST \634  --url https://api.openai.com/v1/audio/translations \635  --header "Authorization: Bearer $OPENAI_API_KEY" \636  --header 'Content-Type: multipart/form-data' \637  --form file=@/path/to/file/german.mp3 \638  --form model=whisper-1 \639```640641642For an audio recording in another language, the response contains the English translation:643644```example-content645Hello, my name is Wolfgang and I come from Germany. Where are you heading today?646```647648This endpoint supports translation into English only.649650## Supported languages651652Use `languages` with `gpt-transcribe` when you know which input languages to expect. Supported language-code formats include:653654- ISO 639-1 codes, such as `en`, `es`, and `fr`.655- Selected ISO 639-3 codes, such as `eng`, `spa`, `yue`, and `cmn`.656- Regional `zh` locale codes, such as `zh-cn`, `zh-tw`, and `zh-hk`.657658The API rejects unsupported or incorrectly formatted language codes. The response also identifies any languages that the model can reliably detect.659660For `whisper-1`, consult the [Whisper language list](https://github.com/openai/whisper#available-models-and-languages). Whisper supports 98 languages, but accuracy varies by language. Existing models that accept one language hint use `language` instead of `languages`.661662## Timestamps663664Use `whisper-1` when you need word or segment timestamps. The [`timestamp_granularities[]` parameter](/api/docs/api-reference/audio/createTranscription#audio-createtranscription-timestamp_granularities) returns structured timestamp data for captioning and video editing.665666Timestamp options667668```javascript669import fs from "fs";670import OpenAI from "openai";671672const openai = new OpenAI();673674const transcription = await openai.audio.transcriptions.create({675  file: fs.createReadStream("fixtures/audio.wav"),676  model: "whisper-1",677  response_format: "verbose_json",678  timestamp_granularities: ["word"],679});680681console.log(transcription.words);682```683684```python685from openai import OpenAI686687client = OpenAI()688audio_file = open("speech.wav", "rb")689690transcription = client.audio.transcriptions.create(691    file=audio_file,692    model="whisper-1",693    response_format="verbose_json",694    timestamp_granularities=["word"],695)696697print(transcription.words)698```699700```go701package main702703import (704	"context"705	"fmt"706	"os"707708	"github.com/openai/openai-go/v3"709)710711func main() {712	file, err := os.Open("fixtures/audio.wav")713	if err != nil {714		panic(err)715	}716	defer file.Close()717718	client := openai.NewClient()719	transcription, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{720		File:                   file,721		Model:                  openai.AudioModelWhisper1,722		ResponseFormat:         openai.AudioResponseFormatVerboseJSON,723		TimestampGranularities: []string{"word"},724	})725	if err != nil {726		panic(err)727	}728	fmt.Println(transcription.Words)729}730```731732```java733import com.openai.client.OpenAIClient;734import com.openai.client.okhttp.OpenAIOkHttpClient;735import com.openai.models.audio.AudioResponseFormat;736import com.openai.models.audio.transcriptions.TranscriptionCreateParams;737import java.nio.file.Path;738739var result =740    client741        .audio()742        .transcriptions()743        .create(744            TranscriptionCreateParams.builder()745                .file(Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH")))746                .model("whisper-1")747                .responseFormat(AudioResponseFormat.VERBOSE_JSON)748                .addTimestampGranularity(TranscriptionCreateParams.TimestampGranularity.WORD)749                .build());750751result752    .asVerbose()753    .words()754    .orElseThrow()755    .forEach(756        word -> System.out.println(word.word() + ": " + word.start() + " - " + word.end()));757```758759```csharp760using OpenAI.Audio;761762string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;763string model = "whisper-1";764AudioClient client = new(model, key);765766await using FileStream audio = File.OpenRead("speech.wav");767AudioTranscriptionOptions options = new()768{769    ResponseFormat = AudioTranscriptionFormat.Verbose,770    TimestampGranularities = AudioTimestampGranularities.Word,771};772AudioTranscription transcription = await client.TranscribeAudioAsync(773    audio,774    "speech.wav",775    options776);777778foreach (TranscribedWord word in transcription.Words)779{780    Console.WriteLine(781        $"{word.Word}: {word.StartTime.TotalSeconds:0.00}s - {word.EndTime.TotalSeconds:0.00}s"782    );783}784```785786```ruby787require "openai"788require "pathname"789require "pp"790791client = OpenAI::Client.new792audio = Pathname("audio.wav")793transcript = client.audio.transcriptions.create(794  file: audio,795  model: "whisper-1",796  response_format: :verbose_json,797  timestamp_granularities: [:word]798)799pp(transcript[:words])800```801802```bash803curl https://api.openai.com/v1/audio/transcriptions \804  -H "Authorization: Bearer $OPENAI_API_KEY" \805  -H "Content-Type: multipart/form-data" \806  -F file="@/path/to/file/audio.mp3" \807  -F "timestamp_granularities[]=word" \808  -F model="whisper-1" \809  -F response_format="verbose_json"810```811812813The `timestamp_granularities[]` parameter is only supported for `whisper-1`.814815## Longer inputs816817The Transcriptions API accepts files up to 25 MB. For larger recordings, use a compressed audio format or split the file into chunks of 25 MB or less. Avoid splitting in the middle of a sentence, which can remove context and reduce accuracy.818819One way to handle this is to use the [PyDub open source Python package](https://github.com/jiaaro/pydub) to split the audio:820821```python822from pydub import AudioSegment823824song = AudioSegment.from_wav("good_morning.wav")825826# PyDub handles time in milliseconds827ten_minutes = 10 * 60 * 1000828829first_10_minutes = song[:ten_minutes]830831first_10_minutes.export("good_morning_10.wav", format="wav")832```833834835_OpenAI makes no guarantees about the usability or security of third-party software like PyDub._836837## Prompting838839Use a [prompt](https://developers.openai.com/api/reference/resources/audio/subresources/transcriptions/methods/create#audio/createTranscription-prompt) to improve recognition of names, acronyms, formatting, or recording-specific vocabulary. With `gpt-transcribe`, combine the prompt with the `keywords` and `languages` shown in [Add transcription context](#add-transcription-context).840841Existing `gpt-4o-transcribe` and `gpt-4o-mini-transcribe` integrations also support prompting. `gpt-4o-transcribe-diarize` doesn't support prompts.842843Useful prompting scenarios include:844845- Correctly transcribing product names, technical terms, and acronyms.846- Carrying context from a previous chunk of a longer recording.847- Preserving punctuation, capitalization, and filler words.848- Selecting a preferred writing system for a language.849850For `whisper-1`, prompts have a 224-token limit and provide less control than the recommended transcription model. See [Improving reliability](#improving-reliability) if your workflow requires Whisper.851852853854Streaming transcriptions855856857858File transcription can stream partial text while the model processes a completed recording. This doesn't require a Realtime session.859860### Streaming the transcription of a completed audio recording861862Set `stream=true` with `gpt-transcribe`. The Transcriptions API returns [transcript events](https://developers.openai.com/api/reference/resources/audio) as the model transcribes each part of the recording.863864Stream transcriptions865866```javascript867import fs from "fs";868import OpenAI from "openai";869870const openai = new OpenAI();871872const stream = await openai.audio.transcriptions.create({873  file: fs.createReadStream("fixtures/speech.wav"),874  model: "gpt-transcribe",875  // highlight-start876  stream: true,877  // highlight-end878});879880// highlight-start881for await (const event of stream) {882  console.log(event);883}884// highlight-end885```886887```python888from openai import OpenAI889890client = OpenAI()891audio_file = open("speech.wav", "rb")892893stream = client.audio.transcriptions.create(894    model="gpt-transcribe",895    file=audio_file,896    # highlight-start897    stream=True,898    # highlight-end899)900901# highlight-start902for event in stream:903    print(event)904# highlight-end905```906907```go908package main909910import (911	"context"912	"fmt"913	"os"914915	"github.com/openai/openai-go/v3"916)917918func main() {919	file, err := os.Open("fixtures/speech.wav")920	if err != nil {921		panic(err)922	}923	defer file.Close()924925	client := openai.NewClient()926	stream := client.Audio.Transcriptions.NewStreaming(context.Background(), openai.AudioTranscriptionNewParams{927		File:  file,928		Model: "gpt-transcribe",929	})930	for stream.Next() {931		fmt.Println(stream.Current().Type)932	}933	if err := stream.Err(); err != nil {934		panic(err)935	}936}937```938939```ruby940require "openai"941require "pathname"942943client = OpenAI::Client.new944audio = Pathname("speech.wav")945stream = client.audio.transcriptions.create_streaming(946  file: audio,947  model: "gpt-transcribe"948)949950stream.each { |event| puts(event.type) }951```952953```bash954curl --request POST \955  --url https://api.openai.com/v1/audio/transcriptions \956  --header "Authorization: Bearer $OPENAI_API_KEY" \957  --header 'Content-Type: multipart/form-data' \958  --form file=@example.wav \959  --form model=gpt-transcribe \960  # highlight-start961  --form stream=true962```963964965The model emits `transcript.text.delta` events as it transcribes the audio, then returns the full transcript in a final `transcript.text.done` event. For speaker-labeled transcription with `response_format="diarized_json"`, the diarization model also emits a `transcript.text.segment` event whenever it finalizes a segment.966967For `gpt-transcribe`, the final event also includes detected languages:968969```json970{971  "type": "transcript.text.done",972  "text": "Bonjour, pouvez-vous m'entendre ?",973  "languages": [{ "code": "fr" }]974}975```976977Existing `gpt-4o-transcribe`, `gpt-4o-mini-transcribe`, and978  `gpt-4o-transcribe-diarize` integrations also support file streaming.979  `whisper-1` doesn't.980981### Streaming the transcription of an ongoing audio recording982983For live audio from a microphone, call, or media stream, use the [Realtime transcription](https://developers.openai.com/api/docs/guides/realtime-transcription) guide instead of the file-oriented streaming path above. It covers the current transcription-session flow and the recommended realtime path with [`gpt-live-transcribe`](https://developers.openai.com/api/docs/models/gpt-live-transcribe).984985## Improving reliability986987If you use `whisper-1` for timestamps, subtitles, or translation, these techniques can improve recognition of uncommon words and acronyms. For new general-purpose transcription, start with `gpt-transcribe` and use [transcription context](#add-transcription-context) instead.988989990991### Using the prompt parameter992993994995The first method involves using the optional prompt parameter to pass a dictionary of the correct spellings.996997Whisper doesn't follow instructions like a general-purpose text model and accepts prompts of up to 224 tokens.998999Prompt parameter10001001```javascript1002import fs from "fs";1003import OpenAI from "openai";10041005const openai = new OpenAI();10061007const transcription = await openai.audio.transcriptions.create({1008  file: fs.createReadStream("fixtures/speech.wav"),1009  model: "whisper-1",1010  response_format: "text",1011  prompt:1012    "ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T.",1013});10141015console.log(transcription);1016```10171018```python1019from openai import OpenAI10201021client = OpenAI()1022audio_file = open("speech.wav", "rb")10231024transcription = client.audio.transcriptions.create(1025    model="whisper-1",1026    file=audio_file,1027    response_format="text",1028    prompt="ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T.",1029)10301031print(transcription.text)1032```10331034```go1035package main10361037import (1038	"context"1039	"fmt"1040	"os"10411042	"github.com/openai/openai-go/v3"1043)10441045func main() {1046	file, err := os.Open("fixtures/speech.wav")1047	if err != nil {1048		panic(err)1049	}1050	defer file.Close()10511052	client := openai.NewClient()1053	var transcription []byte1054	err = client.Post(context.Background(), "audio/transcriptions", openai.AudioTranscriptionNewParams{1055		File:           file,1056		Model:          openai.AudioModelWhisper1,1057		ResponseFormat: openai.AudioResponseFormatText,1058		Prompt:         openai.String("ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T."),1059	}, &transcription)1060	if err != nil {1061		panic(err)1062	}1063	fmt.Println(string(transcription))1064}1065```10661067```java1068import com.openai.client.OpenAIClient;1069import com.openai.client.okhttp.OpenAIOkHttpClient;1070import com.openai.core.http.HttpResponse;1071import com.openai.models.audio.AudioResponseFormat;1072import com.openai.models.audio.transcriptions.TranscriptionCreateParams;1073import java.io.IOException;1074import java.nio.charset.StandardCharsets;1075import java.nio.file.Path;10761077try (HttpResponse result =1078    client1079        .audio()1080        .transcriptions()1081        .withRawResponse()1082        .create(1083            TranscriptionCreateParams.builder()1084                .file(Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH")))1085                .model("whisper-1")1086                .responseFormat(AudioResponseFormat.TEXT)1087                .prompt(1088                    "ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, "1089                        + "OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., "1090                        + "Q.U.A.R.T.Z., F.L.I.N.T.")1091                .build())) {1092  System.out.println(new String(result.body().readAllBytes(), StandardCharsets.UTF_8));1093}1094```10951096```csharp1097using OpenAI.Audio;10981099string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;1100string model = "whisper-1";1101AudioClient client = new(model, key);11021103await using FileStream audio = File.OpenRead("speech.wav");1104AudioTranscriptionOptions options = new()1105{1106    ResponseFormat = AudioTranscriptionFormat.Text,1107    Prompt = "ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T.",1108};1109AudioTranscription transcription = await client.TranscribeAudioAsync(1110    audio,1111    "speech.wav",1112    options1113);11141115Console.WriteLine(transcription.Text);1116```11171118```ruby1119require "openai"1120require "pathname"11211122client = OpenAI::Client.new1123audio = Pathname("speech.wav")1124transcript = client.audio.transcriptions.create(1125  file: audio,1126  model: "whisper-1",1127  prompt: "The speaker says OpenAI and Responses API"1128)1129puts(transcript.text)1130```11311132```bash1133curl --request POST \1134  --url https://api.openai.com/v1/audio/transcriptions \1135  --header "Authorization: Bearer $OPENAI_API_KEY" \1136  --header 'Content-Type: multipart/form-data' \1137  --form file=@/path/to/file/speech.mp3 \1138  --form model=whisper-1 \1139  --form prompt="ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T."1140```114111421143While it increases reliability, this technique is limited to 224 tokens, so your list of SKUs needs to be relatively small for this to be a scalable solution.11441145114611471148114911501151### Post-processing with a text model1152115311541155The second method uses a text model to post-process the transcript.11561157Provide instructions through the `system_prompt` variable. As with the transcription prompt, you can include company and product names.11581159Post-processing11601161```javascript1162const systemPrompt = `1163You are a helpful assistant for the company ZyntriQix. Your task is1164to correct any spelling discrepancies in the transcribed text. Make1165sure that the names of the following products are spelled correctly:1166ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array,1167OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K.,1168Q.U.A.R.T.Z., F.L.I.N.T. Only add necessary punctuation such as1169periods, commas, and capitalization, and use only the context provided.1170`;11711172const transcript = await transcribe(audioFile);1173const completion = await openai.chat.completions.create({1174  model: "gpt-4.1",1175  temperature: temperature,1176  messages: [1177    {1178      role: "system",1179      content: systemPrompt,1180    },1181    {1182      role: "user",1183      content: transcript,1184    },1185  ],1186  store: true,1187});11881189console.log(completion.choices[0].message.content);1190```11911192```python1193system_prompt = """1194You are a helpful assistant for the company ZyntriQix. Your task is to correct1195any spelling discrepancies in the transcribed text. Make sure that the names of1196the following products are spelled correctly: ZyntriQix, Digique Plus,1197CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal1198Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T. Only add necessary1199punctuation such as periods, commas, and capitalization, and use only the1200context provided.1201"""120212031204def generate_corrected_transcript(temperature, system_prompt, audio_file):1205    response = client.chat.completions.create(1206        model="gpt-4.1",1207        temperature=temperature,1208        messages=[1209            {"role": "system", "content": system_prompt},1210            {"role": "user", "content": transcribe(audio_file, "")},1211        ],1212    )1213    return response.choices[0].message.content121412151216corrected_text = generate_corrected_transcript(0, system_prompt, fake_company_filepath)1217```12181219```go1220package main12211222import (1223	"context"1224	"fmt"1225	"os"12261227	"github.com/openai/openai-go/v3"1228)12291230const systemPrompt = `1231You are a helpful assistant for the company ZyntriQix. Your task is1232to correct any spelling discrepancies in the transcribed text. Make1233sure that the names of the following products are spelled correctly:1234ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array,1235OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K.,1236Q.U.A.R.T.Z., F.L.I.N.T. Only add necessary punctuation such as1237periods, commas, and capitalization, and use only the context provided.1238`12391240func main() {1241	file, err := os.Open("fixtures/speech.wav")1242	if err != nil {1243		panic(err)1244	}1245	defer file.Close()12461247	client := openai.NewClient()1248	transcription, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{1249		File:  file,1250		Model: openai.AudioModelGPT4oTranscribe,1251	})1252	if err != nil {1253		panic(err)1254	}1255	completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{1256		Model:       "gpt-4.1",1257		Temperature: openai.Float(0),1258		Messages: []openai.ChatCompletionMessageParamUnion{1259			openai.SystemMessage(systemPrompt),1260			openai.UserMessage(transcription.Text),1261		},1262		Store: openai.Bool(true),1263	})1264	if err != nil {1265		panic(err)1266	}1267	fmt.Println(completion.Choices[0].Message.Content)1268}1269```12701271```java1272import com.openai.client.OpenAIClient;1273import com.openai.client.okhttp.OpenAIOkHttpClient;1274import com.openai.models.audio.transcriptions.TranscriptionCreateParams;1275import com.openai.models.chat.completions.ChatCompletionCreateParams;1276import java.nio.file.Path;12771278String systemPrompt =1279    """1280    You are a helpful assistant for the company ZyntriQix. Your task is to1281    correct any spelling discrepancies in the transcribed text. Make sure that1282    the names of the following products are spelled correctly: ZyntriQix,1283    Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven,1284    DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T.1285    Only add necessary punctuation such as periods, commas, and capitalization,1286    and use only the context provided.1287    """;12881289var result =1290    client1291        .audio()1292        .transcriptions()1293        .create(1294            TranscriptionCreateParams.builder()1295                .file(Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH")))1296                .model("gpt-4o-transcribe")1297                .build());12981299var completion =1300    client1301        .chat()1302        .completions()1303        .create(1304            ChatCompletionCreateParams.builder()1305                .model("gpt-4.1")1306                .temperature(0.0)1307                .store(true)1308                .addSystemMessage(systemPrompt)1309                .addUserMessage(result.asTranscription().text())1310                .build());1311completion.choices().stream()1312    .flatMap(choice -> choice.message().content().stream())1313    .forEach(System.out::println);1314```13151316```csharp1317using OpenAI.Audio;1318using OpenAI.Chat;13191320string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;1321string model = "gpt-4.1";1322ChatClient client = new(model, key);13231324string transcriptionModel = "gpt-4o-transcribe";1325AudioClient audio = new(transcriptionModel, key);13261327await using FileStream source = File.OpenRead("speech.wav");1328AudioTranscription transcription = await audio.TranscribeAudioAsync(source, "speech.wav");13291330string systemPrompt =1331    """1332    You are a helpful assistant for the company ZyntriQix. Correct any1333    spelling discrepancies in the transcribed text. Make sure the names1334    of these products are spelled correctly: ZyntriQix, Digique Plus,1335    CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven,1336    DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T.1337    Only add necessary punctuation such as periods, commas, and1338    capitalization, and use only the context provided.1339    """;1340ChatCompletionOptions correctionOptions = new() { Temperature = 0 };1341ChatCompletion completion = await client.CompleteChatAsync(1342    [1343        new SystemChatMessage(systemPrompt),1344        new UserChatMessage(transcription.Text),1345    ],1346    correctionOptions1347);1348Console.WriteLine(completion.Content[0].Text);1349```13501351```ruby1352require "openai"1353require "pathname"13541355client = OpenAI::Client.new1356audio = Pathname("speech.wav")1357transcript = client.audio.transcriptions.create(1358  file: audio,1359  model: "gpt-4o-mini-transcribe"1360)13611362response = client.responses.create(1363  model: "gpt-4.1",1364  input: "Add punctuation and paragraph breaks without changing the words:\n#{transcript.text}"1365)1366puts(response.output_text)1367```136813691370A text model can correct misspellings and handle longer terminology lists than Whisper's 224-token prompt window. Evaluate corrections against the original audio to avoid changing what the speaker said.
Files main
Menu

Theme