如果錄音已完成,或請求中的音訊有明確的起訖範圍,就可以使用檔案轉錄。上傳音訊後,你可以取得完整的轉錄文字,也可以在模型處理檔案時串流接收文字。
建議先使用 gpt-transcribe 。這是以錄音的原始語言轉錄語音時建議使用的模型。下方關於說話者標記、詞級時間戳記和字幕格式的專門範例使用的是已棄用的模型。
whisper-1、gpt-4o-transcribe、gpt-4o-mini-transcribe、gpt-4o-transcribe-diarize 和 /v1/audio/translations 均已棄用,將於 2027 年 2 月 26 日 停止服務。請參閱棄用公告 ,並選擇目前可用的轉錄流程 。下方的專門範例說明現有整合在服務停止前仍可使用哪些功能。
檔案大小上限為 25 MB。支援的輸入格式包括 flac、mp3、mp4、mpeg、mpga、m4a、ogg、wav 和 webm。
如果音訊仍持續從麥克風、通話或媒體串流傳入,請使用即時轉錄 。
將音訊檔案傳送至 /v1/audio/transcriptions,並指定 gpt-transcribe:
1
2
3
4
5
6
7
8
9
10
11 import fs from "fs";
import OpenAI from "openai";
const openai = new OpenAI();
const transcription = await openai.audio.transcriptions.create({
file: fs.createReadStream("fixtures/audio.wav"),
model: "gpt-transcribe",
});
console.log(transcription.text); 1
2
3
4
5
6
7
8
9
10 from openai import OpenAI
client = OpenAI()
audio_file = open ( "audio.wav" , "rb" )
transcription = client.audio.transcriptions.create(
model = "gpt-transcribe" , file = audio_file
)
print (transcription.text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package main
import (
"context"
"fmt"
"os"
"github.com/openai/openai-go/v3"
)
func main() {
file, err := os.Open("fixtures/audio.wav")
if err != nil {
panic(err)
}
defer file.Close()
client := openai.NewClient()
transcription, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{
File: file,
Model: "gpt-transcribe",
})
if err != nil {
panic(err)
}
fmt.Println(transcription.Text)
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.audio.transcriptions.TranscriptionCreateParams;
import java.nio.file.Path;
var result =
client
.audio()
.transcriptions()
.create(
TranscriptionCreateParams.builder()
.file(Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH")))
.model("gpt-transcribe")
.build());
System.out.println(result.asTranscription().text()); 1
2
3
4
5
6
7
8
9
10
11
12
13 using OpenAI.Audio;
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
string model = "gpt-transcribe";
AudioClient client = new(model, key);
await using FileStream audio = File.OpenRead("audio.wav");
AudioTranscription transcription = await client.TranscribeAudioAsync(
audio,
"audio.wav"
);
Console.WriteLine(transcription.Text); 1
2
3
4
5
6
7
8
9
10
11
12 require "openai"
require "pathname"
client = OpenAI::Client.new
audio = Pathname("audio.wav")
transcript = client.audio.transcriptions.create(
file: audio,
model: "gpt-transcribe"
)
raise "Expected a JSON transcript response" if transcript.is_a?(StringIO)
puts(transcript.text) 1
2
3
4
5 openai audio:transcriptions create \
--model gpt-transcribe \
--file /path/to/file/audio.mp3 \
--raw-output \
--transform text 1
2
3
4
5
6 curl --request POST \
--url https://api.openai.com/v1/audio/transcriptions \
--header "Authorization: Bearer $OPENAI_API_KEY" \
--header 'Content-Type: multipart/form-data' \
--form file=@/path/to/file/audio.mp3 \
--form model=gpt-transcribe
模型會以 JSON 格式傳回轉錄文字和偵測到的語言:
1 2 3 4 {
"text" : "Bonjour, pouvez-vous m'entendre ?" ,
"languages" : [{ "code" : "fr" }]
}
如果模型無法可靠地判斷語言,就會傳回 "languages": []。如需完整的請求和回應欄位說明,請參閱音訊 API 參考文件 。
使用 prompt、keywords 和 languages,可提升 gpt-transcribe 轉錄專業術語和多語音訊的準確度:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import fs from "fs";
import OpenAI from "openai";
const openai = new OpenAI();
const request = {
model: "gpt-transcribe",
file: fs.createReadStream("fixtures/audio.wav"),
prompt: "A customer support call about a premium plan and account AC-42.",
};
const transcription = await openai.audio.transcriptions.create(request, {
body: {
...request,
keywords: ["premium plan", "AC-42", "billing"],
languages: ["en", "fr"],
},
});
console.log(transcription.text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from openai import OpenAI
client = OpenAI()
with open ( "meeting.wav" , "rb" ) as audio_file:
transcription = client.audio.transcriptions.create(
model = "gpt-transcribe" ,
file = audio_file,
prompt = "A customer support call about a premium plan and account AC-42." ,
extra_body = {
"keywords" : [ "premium plan" , "AC-42" , "billing" ],
"languages" : [ "en" , "fr" ],
},
)
print (transcription.text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 package main
import (
"context"
"fmt"
"os"
"github.com/openai/openai-go/v3"
)
func main() {
file, err := os.Open("fixtures/audio.wav")
if err != nil {
panic(err)
}
defer file.Close()
parameters := openai.AudioTranscriptionNewParams{
File: file,
Model: "gpt-transcribe",
Prompt: openai.String("A customer support call about a premium plan and account AC-42."),
}
parameters.SetExtraFields(map[string]any{
"keywords": []string{"premium plan", "AC-42", "billing"},
"languages": []string{"en", "fr"},
})
client := openai.NewClient()
transcription, err := client.Audio.Transcriptions.New(context.Background(), parameters)
if err != nil {
panic(err)
}
fmt.Println(transcription.Text)
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.JsonValue;
import com.openai.models.audio.transcriptions.TranscriptionCreateParams;
import java.nio.file.Path;
import java.util.List;
var result =
client
.audio()
.transcriptions()
.create(
TranscriptionCreateParams.builder()
.file(Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH")))
.model("gpt-transcribe")
.prompt("A customer support call about a premium plan and account AC-42.")
.putAdditionalBodyProperty(
"keywords", JsonValue.from(List.of("premium plan", "AC-42", "billing")))
.putAdditionalBodyProperty("languages", JsonValue.from(List.of("en", "fr")))
.build());
System.out.println(result.asTranscription().text()); 1
2
3
4
5
6
7
8
9
10
11
12
13 require "openai"
require "pathname"
client = OpenAI::Client.new
audio = Pathname("audio.wav")
transcript = client.audio.transcriptions.create(
file: audio,
model: "gpt-transcribe",
keywords: ["OpenAI", "Responses API", "Codex"]
)
raise "Expected a JSON transcript response" if transcript.is_a?(StringIO)
puts(transcript.text) 1
2
3
4
5
6
7
8
9
10
11 curl https://api.openai.com/v1/audio/transcriptions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F model="gpt-transcribe" \
-F file="@/path/to/file/meeting.wav" \
-F 'prompt=A customer support call about a premium plan and account AC-42.' \
-F 'keywords[]=premium plan' \
-F 'keywords[]=AC-42' \
-F 'keywords[]=billing' \
-F 'languages[]=en' \
-F 'languages[]=fr'
使用 prompt 以自由文字提供錄音的背景資訊。
使用 keywords 列出預期會聽到的確切詞彙。
使用 languages 指定預期的輸入語言。
關鍵字只供模型參考,不一定會出現在輸出中。請只列出相關詞彙,並檢查這些關鍵字是否能提高準確度,以及是否導致轉錄文字出現錄音中未說過的詞彙。
在 gpt-transcribe 中,languages 取代了單數形式的 language 欄位。請勿同時傳送這兩個欄位。每個關鍵字都不得跨行,也不得包含 <、>、歸位字元或換行字元。如果關鍵字含有上述任一字元,或 prompt 超出模型的長度限制,API 會拒絕整個請求。
在 2027 年 2 月 26 日停止服務前,現有整合仍可使用已棄用的 gpt-4o-transcribe-diarize 模型,辨識錄音中各個片段的說話者。這個模型專門用於標記說話者,一般檔案轉錄不建議使用。
請指定 diarized_json 回應格式,以取得含有 speaker、start 和 end 中繼資料的片段。如果音訊超過 30 秒,請將 chunking_strategy 設為 "auto",或指定語音活動偵測設定。
你也可以透過 known_speaker_names[] 和 known_speaker_references[] 提供最多四段簡短的參考音訊,將各片段對應到已知的說話者。每段參考音訊的長度須為 2 至 10 秒,可使用上傳主要音訊時支援的任何輸入格式。如果使用多部分表單資料,請將參考音訊編碼為資料 URL 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import fs from "fs";
import OpenAI from "openai";
const openai = new OpenAI();
const agentRef = fs.readFileSync("fixtures/agent.wav").toString("base64");
const transcript = (await openai.audio.transcriptions.create({
file: fs.createReadStream("fixtures/meeting.wav"),
model: "gpt-4o-transcribe-diarize",
response_format: "diarized_json",
chunking_strategy: "auto",
known_speaker_names: ["agent"],
known_speaker_references: ["data:audio/wav;base64," + agentRef],
})) as OpenAI.Audio.TranscriptionDiarized;
for (const segment of transcript.segments) {
if (!("speaker" in segment)) continue;
console.log(
`${segment.speaker}: ${segment.text}`,
segment.start,
segment.end
);
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import base64
from openai import OpenAI
client = OpenAI()
def to_data_url (path: str ) -> str :
with open (path, "rb" ) as fh:
return "data:audio/wav;base64," + base64.b64encode(fh.read()).decode( "utf-8" )
with open ( "meeting.wav" , "rb" ) as audio_file:
transcript = client.audio.transcriptions.create(
model = "gpt-4o-transcribe-diarize" ,
file = audio_file,
response_format = "diarized_json" ,
chunking_strategy = "auto" ,
extra_body = {
"known_speaker_names" : [ "agent" ],
"known_speaker_references" : [to_data_url( "agent.wav" )],
},
)
for segment in transcript.segments:
print (segment.speaker, segment.text, segment.start, segment.end) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 package main
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"os"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/shared/constant"
)
type diarizedTranscript struct {
Segments []struct {
Speaker string `json:"speaker"`
Text string `json:"text"`
Start float64 `json:"start"`
End float64 `json:"end"`
} `json:"segments"`
}
func main() {
agentAudio, err := os.ReadFile("fixtures/agent.wav")
if err != nil {
panic(err)
}
meeting, err := os.Open("fixtures/meeting.wav")
if err != nil {
panic(err)
}
defer meeting.Close()
client := openai.NewClient()
transcription, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{
File: meeting,
Model: "gpt-4o-transcribe-diarize",
ResponseFormat: openai.AudioResponseFormatDiarizedJSON,
ChunkingStrategy: openai.AudioTranscriptionNewParamsChunkingStrategyUnion{
OfAuto: constant.ValueOf[constant.Auto](),
},
KnownSpeakerNames: []string{"agent"},
KnownSpeakerReferences: []string{"data:audio/wav;base64," + base64.StdEncoding.EncodeToString(agentAudio)},
})
if err != nil {
panic(err)
}
var result diarizedTranscript
if err := json.Unmarshal([]byte(transcription.RawJSON()), &result); err != nil {
panic(err)
}
for _, segment := range result.Segments {
fmt.Println(segment.Speaker+":", segment.Text, segment.Start, segment.End)
}
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 import com.fasterxml.jackson.databind.json.JsonMapper;
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.audio.AudioResponseFormat;
import com.openai.models.audio.transcriptions.TranscriptionCreateParams;
import com.openai.models.audio.transcriptions.TranscriptionDiarized;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
Path audio = Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH"));
Path speakerAudio = Path.of(System.getenv("OPENAI_EXAMPLE_SPEAKER_AUDIO_PATH"));
String speakerReference =
"data:audio/wav;base64,"
+ Base64.getEncoder().encodeToString(Files.readAllBytes(speakerAudio));
var result =
client
.audio()
.transcriptions()
.create(
TranscriptionCreateParams.builder()
.file(audio)
.model("gpt-4o-transcribe-diarize")
.responseFormat(AudioResponseFormat.DIARIZED_JSON)
.chunkingStrategyAuto()
.addKnownSpeakerName("agent")
.addKnownSpeakerReference(speakerReference)
.build());
TranscriptionDiarized diarized =
result.isDiarized()
? result.asDiarized()
: new JsonMapper()
.readValue(result.asTranscription().text(), TranscriptionDiarized.class);
for (var segment : diarized.segments()) {
System.out.println(
segment.speaker()
+ ": "
+ segment.text()
+ " ("
+ segment.start()
+ "-"
+ segment.end()
+ ")");
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 require "base64"
require "openai"
require "pathname"
client = OpenAI::Client.new
audio = Pathname("meeting.wav")
speaker_reference = Base64.strict_encode64(File.binread("agent.wav"))
transcript = client.audio.transcriptions.create(
file: audio,
model: "gpt-4o-transcribe-diarize",
response_format: :diarized_json,
chunking_strategy: :auto,
known_speaker_names: ["agent"],
known_speaker_references: ["data:audio/wav;base64,#{speaker_reference}"]
)
segments = Array(
transcript.to_h.fetch(:segments) do
raise "The transcription did not include speaker segments"
end
)
segments.each do |segment|
segment = Hash.try_convert(segment) or raise "Invalid speaker segment"
puts(
"#{segment.fetch(:speaker)}: #{segment.fetch(:text)} " \
"(#{segment.fetch(:start)}-#{segment.fetch(:end_)})"
)
end 1
2
3
4
5
6
7
8
9
10 curl --request POST \
--url https://api.openai.com/v1/audio/transcriptions \
--header "Authorization: Bearer $OPENAI_API_KEY" \
--header 'Content-Type: multipart/form-data' \
--form file=@/path/to/file/meeting.wav \
--form model=gpt-4o-transcribe-diarize \
--form response_format=diarized_json \
--form chunking_strategy=auto \
--form 'known_speaker_names[]=agent' \
--form 'known_speaker_references[]=data:audio/wav;base64,AAA...'
設定 stream=true 時,含說話者標記的回應會在每個片段完成時送出 transcript.text.segment 事件。transcript.text.delta 事件包含 segment_id 欄位,但這些增量更新不會標記尚未完成片段的說話者。模型只會在片段定稿時標記說話者。
說話者標記功能可透過 /v1/audio/transcriptions 使用。即時轉錄工作階段不支援這項功能。
已棄用的 /v1/audio/translations 端點使用 whisper-1 將已完成的錄音翻譯成英文。此端點在 2027 年 2 月 26 日停止服務前仍可使用。轉錄會保留錄音的原始語言,而此端點只會傳回英文文字。
請遷移至即時翻譯 ,使用 gpt-realtime-translate 模型呼叫 /v1/realtime/translations 端點。遷移時必須建立翻譯工作階段、以串流方式輸入音訊,並處理翻譯事件。只變更 /v1/audio/translations 請求中的模型 ID 無法完成遷移。
如果知道輸入音訊可能包含哪些語言,可以使用 languages 為 gpt-transcribe 指定這些語言。支援的語言代碼格式包括:
ISO 639-1 代碼,例如 en、es 和 fr。
部分 ISO 639-3 代碼,例如 eng、spa、yue 和 cmn。
含地區資訊的 zh 語言代碼,例如 zh-cn、zh-tw 和 zh-hk。
如果語言代碼不受支援或格式錯誤,API 會拒絕請求。回應也會列出模型能可靠偵測到的所有語言。
如需瞭解 whisper-1 支援哪些語言,請參閱 Whisper 語言清單 。Whisper 支援 98 種語言,但準確度因語言而異。只接受一種語言提示的現有模型使用 language 欄位,而非 languages。
在 2027 年 2 月 26 日停止服務前,現有整合仍可使用已棄用的 whisper-1 模型取得個別詞語或片段的時間戳記。timestamp_granularities[] 參數 可讓模型傳回結構化的時間戳記資料,供製作字幕和剪輯影片使用。
1
2
3
4
5
6
7
8
9
10
11
12
13 import fs from "fs";
import OpenAI from "openai";
const openai = new OpenAI();
const transcription = await openai.audio.transcriptions.create({
file: fs.createReadStream("fixtures/audio.wav"),
model: "whisper-1",
response_format: "verbose_json",
timestamp_granularities: ["word"],
});
console.log(transcription.words); 1
2
3
4
5
6
7
8
9
10
11
12
13 from openai import OpenAI
client = OpenAI()
audio_file = open ( "speech.wav" , "rb" )
transcription = client.audio.transcriptions.create(
file = audio_file,
model = "whisper-1" ,
response_format = "verbose_json" ,
timestamp_granularities = [ "word" ],
)
print (transcription.words) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package main
import (
"context"
"fmt"
"os"
"github.com/openai/openai-go/v3"
)
func main() {
file, err := os.Open("fixtures/audio.wav")
if err != nil {
panic(err)
}
defer file.Close()
client := openai.NewClient()
transcription, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{
File: file,
Model: openai.AudioModelWhisper1,
ResponseFormat: openai.AudioResponseFormatVerboseJSON,
TimestampGranularities: []string{"word"},
})
if err != nil {
panic(err)
}
fmt.Println(transcription.Words)
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.audio.AudioResponseFormat;
import com.openai.models.audio.transcriptions.TranscriptionCreateParams;
import java.nio.file.Path;
var result =
client
.audio()
.transcriptions()
.create(
TranscriptionCreateParams.builder()
.file(Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH")))
.model("whisper-1")
.responseFormat(AudioResponseFormat.VERBOSE_JSON)
.addTimestampGranularity(TranscriptionCreateParams.TimestampGranularity.WORD)
.build());
result
.asVerbose()
.words()
.orElseThrow()
.forEach(
word -> System.out.println(word.word() + ": " + word.start() + " - " + word.end())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 using OpenAI.Audio;
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
string model = "whisper-1";
AudioClient client = new(model, key);
await using FileStream audio = File.OpenRead("speech.wav");
AudioTranscriptionOptions options = new()
{
ResponseFormat = AudioTranscriptionFormat.Verbose,
TimestampGranularities = AudioTimestampGranularities.Word,
};
AudioTranscription transcription = await client.TranscribeAudioAsync(
audio,
"speech.wav",
options
);
foreach (TranscribedWord word in transcription.Words)
{
Console.WriteLine(
$"{word.Word}: {word.StartTime.TotalSeconds:0.00}s - {word.EndTime.TotalSeconds:0.00}s"
);
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 require "openai"
require "pathname"
require "pp"
client = OpenAI::Client.new
audio = Pathname("audio.wav")
transcript = client.audio.transcriptions.create(
file: audio,
model: "whisper-1",
response_format: :verbose_json,
timestamp_granularities: [:word]
)
raise "Expected a JSON transcript response" if transcript.is_a?(StringIO)
pp(transcript.deep_to_h.fetch(:words)) 1
2
3
4
5
6
7 curl https://api.openai.com/v1/audio/transcriptions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F file="@/path/to/file/audio.mp3" \
-F "timestamp_granularities[]=word" \
-F model="whisper-1" \
-F response_format="verbose_json"
timestamp_granularities[] 參數僅適用於 whisper-1。
轉錄 API 接受的檔案大小上限為 25 MB。若錄音檔案較大,請使用壓縮音訊格式,或將檔案分割為不超過 25 MB 的片段。請避免在句子中間分割,以免遺失上下文而降低準確度。
你可以使用 PyDub 開放原始碼 Python 套件 分割音訊:
1
2
3
4
5
6
7
8
9
10 from pydub import AudioSegment
song = AudioSegment.from_wav( "good_morning.wav" )
# PyDub handles time in milliseconds
ten_minutes = 10 * 60 * 1000
first_10_minutes = song[:ten_minutes]
first_10_minutes.export( "good_morning_10.wav" , format = "wav" )
OpenAI 不保證 PyDub 等第三方軟體的可用性或安全性。
使用提示詞 ,可協助模型辨識名稱、縮寫和錄音中的特定詞彙,並採用適當的格式。使用 gpt-transcribe 時,可以搭配提示詞使用 keywords 和 languages,詳見加入轉錄上下文 。
現有的 gpt-4o-transcribe 和 gpt-4o-mini-transcribe 整合也支援提示詞。gpt-4o-transcribe-diarize 不支援提示詞。
提示詞適用於下列情境:
正確轉錄產品名稱、技術術語和縮寫。
分段轉錄較長的錄音時,沿用上一段的上下文。
保留標點符號、字母大小寫和填充詞。
為特定語言指定偏好的書寫系統。
whisper-1 的提示詞上限為 224 個 Token,對轉錄結果的控制也比建議使用的轉錄模型有限。如果你的流程必須使用 Whisper,請參閱提高可靠性 。
使用檔案轉錄時,模型可以一邊處理已完成的錄音,一邊串流傳回已轉錄的文字。這不需要建立即時工作階段。
將 stream=true 與 gpt-transcribe 搭配使用。模型逐段轉錄錄音時,轉錄 API 會傳回轉錄事件 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14 import fs from "fs";
import OpenAI from "openai";
const openai = new OpenAI();
const stream = await openai.audio.transcriptions.create({
file: fs.createReadStream("fixtures/speech.wav"),
model: "gpt-transcribe",
stream: true,
});
for await (const event of stream) {
console.log(event);
} 1
2
3
4
5
6
7
8
9
10
11
12
13 from openai import OpenAI
client = OpenAI()
audio_file = open ( "speech.wav" , "rb" )
stream = client.audio.transcriptions.create(
model = "gpt-transcribe" ,
file = audio_file,
stream = True ,
)
for event in stream:
print (event) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package main
import (
"context"
"fmt"
"os"
"github.com/openai/openai-go/v3"
)
func main() {
file, err := os.Open("fixtures/speech.wav")
if err != nil {
panic(err)
}
defer file.Close()
client := openai.NewClient()
stream := client.Audio.Transcriptions.NewStreaming(context.Background(), openai.AudioTranscriptionNewParams{
File: file,
Model: "gpt-transcribe",
})
for stream.Next() {
fmt.Println(stream.Current().Type)
}
if err := stream.Err(); err != nil {
panic(err)
}
} 1
2
3
4
5
6
7
8
9
10
11
12 import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.audio.transcriptions.TranscriptionCreateParams;
import java.nio.file.Path;
var params =
TranscriptionCreateParams.builder()
.model("gpt-transcribe")
.file(Path.of("speech.wav"))
.build();
try (var stream = client.audio().transcriptions().createStreaming(params)) {
stream.stream().forEach(event -> System.out.println(event));
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 using OpenAI.Audio;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
string model = "gpt-transcribe";
AudioClient client = new(model, key);
await foreach (StreamingAudioTranscriptionUpdate update in client.TranscribeAudioStreamingAsync("speech.wav"))
{
if (update is StreamingAudioTranscriptionTextDeltaUpdate delta)
{
Console.Write(delta.Delta);
}
}
Console.WriteLine(); 1
2
3
4
5
6
7
8
9
10
11 require "openai"
require "pathname"
client = OpenAI::Client.new
audio = Pathname("speech.wav")
stream = client.audio.transcriptions.create_streaming(
file: audio,
model: "gpt-transcribe"
)
stream.each { |event| puts(event.type) } 1
2
3
4
5
6
7 curl --request POST \
--url https://api.openai.com/v1/audio/transcriptions \
--header "Authorization: Bearer $OPENAI_API_KEY" \
--header 'Content-Type: multipart/form-data' \
--form file=@example.wav \
--form model=gpt-transcribe \
--form stream=true
模型在轉錄音訊時會送出 transcript.text.delta 事件,最後透過 transcript.text.done 事件傳回完整的轉錄文字。如果使用 response_format="diarized_json" 取得含說話者標記的轉錄文字,區分說話者的模型也會在每個片段定稿時送出 transcript.text.segment 事件。
使用 gpt-transcribe 時,最後一個事件也會包含偵測到的語言:
1 2 3 4 5 {
"type" : "transcript.text.done" ,
"text" : "Bonjour, pouvez-vous m'entendre ?" ,
"languages" : [{ "code" : "fr" }]
}
現有的 gpt-4o-transcribe、gpt-4o-mini-transcribe 和 gpt-4o-transcribe-diarize 整合也支援串流接收檔案的轉錄文字。whisper-1 不支援這項功能。
如果音訊是從麥克風、通話或媒體串流即時傳入,請依照即時轉錄 指南操作,而非採用上述檔案串流流程。該指南說明目前的轉錄工作階段流程,以及如何使用建議的模型 gpt-live-transcribe 進行即時轉錄。
如果你使用 whisper-1 取得時間戳記、製作字幕或進行翻譯,下列方法可以提高模型辨識罕見詞彙和縮寫的準確度。對於新的通用轉錄應用,建議先使用 gpt-transcribe 並提供轉錄上下文 。
使用提示詞參數 第一種方法是透過選用的提示詞參數,提供一份列有正確拼法的詞彙表。
Whisper 無法像通用文字模型一樣遵循指示,且提示詞最多只能包含 224 個 Token。
1
2
3
4
5
6
7
8
9
10
11
12
13
14 import fs from "fs";
import OpenAI from "openai";
const openai = new OpenAI();
const transcription = await openai.audio.transcriptions.create({
file: fs.createReadStream("fixtures/speech.wav"),
model: "whisper-1",
response_format: "text",
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.",
});
console.log(transcription); 1
2
3
4
5
6
7
8
9
10
11
12
13 from openai import OpenAI
client = OpenAI()
audio_file = open ( "speech.wav" , "rb" )
transcription = client.audio.transcriptions.create(
model = "whisper-1" ,
file = audio_file,
response_format = "text" ,
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." ,
)
print (transcription) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package main
import (
"context"
"fmt"
"os"
"github.com/openai/openai-go/v3"
)
func main() {
file, err := os.Open("fixtures/speech.wav")
if err != nil {
panic(err)
}
defer file.Close()
client := openai.NewClient()
var transcription []byte
err = client.Post(context.Background(), "audio/transcriptions", openai.AudioTranscriptionNewParams{
File: file,
Model: openai.AudioModelWhisper1,
ResponseFormat: openai.AudioResponseFormatText,
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."),
}, &transcription)
if err != nil {
panic(err)
}
fmt.Println(string(transcription))
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.http.HttpResponse;
import com.openai.models.audio.AudioResponseFormat;
import com.openai.models.audio.transcriptions.TranscriptionCreateParams;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
try (HttpResponse result =
client
.audio()
.transcriptions()
.withRawResponse()
.create(
TranscriptionCreateParams.builder()
.file(Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH")))
.model("whisper-1")
.responseFormat(AudioResponseFormat.TEXT)
.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.")
.build())) {
System.out.println(new String(result.body().readAllBytes(), StandardCharsets.UTF_8));
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 using OpenAI.Audio;
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
string model = "whisper-1";
AudioClient client = new(model, key);
await using FileStream audio = File.OpenRead("speech.wav");
AudioTranscriptionOptions options = new()
{
ResponseFormat = AudioTranscriptionFormat.Text,
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.",
};
AudioTranscription transcription = await client.TranscribeAudioAsync(
audio,
"speech.wav",
options
);
Console.WriteLine(transcription.Text); 1
2
3
4
5
6
7
8
9
10
11
12
13 require "openai"
require "pathname"
client = OpenAI::Client.new
audio = Pathname("speech.wav")
transcript = client.audio.transcriptions.create(
file: audio,
model: "whisper-1",
prompt: "The speaker says OpenAI and Responses API"
)
raise "Expected a JSON transcript response" if transcript.is_a?(StringIO)
puts(transcript.text) 1
2
3
4
5
6
7 curl --request POST \
--url https://api.openai.com/v1/audio/transcriptions \
--header "Authorization: Bearer $OPENAI_API_KEY" \
--header 'Content-Type: multipart/form-data' \
--form file=@/path/to/file/speech.mp3 \
--form model=whisper-1 \
--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." 這種方法可以提高可靠性,但受限於 224 個 Token 的上限。若要大規模採用這種做法,SKU 清單就必須保持精簡。
使用文字模型進行後處理 第二種方法是使用文字模型對轉錄文字進行後處理。
透過 system_prompt 變數提供指示。和轉錄提示詞一樣,這些指示也可以包含公司和產品名稱。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 const systemPrompt = `
You are a helpful assistant for the company ZyntriQix. Your task is
to correct any spelling discrepancies in the transcribed text. Make
sure that the names of the following products are spelled correctly:
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. Only add necessary punctuation such as
periods, commas, and capitalization, and use only the context provided.
`;
const transcript = await transcribe(audioFile);
const completion = await openai.chat.completions.create({
model: "gpt-4.1",
temperature: temperature,
messages: [
{
role: "system",
content: systemPrompt,
},
{
role: "user",
content: transcript,
},
],
store: true,
});
console.log(completion.choices[0].message.content); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 system_prompt = """
You are a helpful assistant for the company ZyntriQix. Your task is to correct
any spelling discrepancies in the transcribed text. Make sure that the names of
the following products are spelled correctly: 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. Only add necessary
punctuation such as periods, commas, and capitalization, and use only the
context provided.
"""
def generate_corrected_transcript (temperature, system_prompt, audio_file):
response = client.chat.completions.create(
model = "gpt-4.1" ,
temperature = temperature,
messages = [
{ "role" : "system" , "content" : system_prompt},
{ "role" : "user" , "content" : transcribe(audio_file, "" )},
],
)
return response.choices[ 0 ].message.content
corrected_text = generate_corrected_transcript( 0 , system_prompt, fake_company_filepath) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 package main
import (
"context"
"fmt"
"os"
"github.com/openai/openai-go/v3"
)
const systemPrompt = `
You are a helpful assistant for the company ZyntriQix. Your task is
to correct any spelling discrepancies in the transcribed text. Make
sure that the names of the following products are spelled correctly:
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. Only add necessary punctuation such as
periods, commas, and capitalization, and use only the context provided.
`
func main() {
file, err := os.Open("fixtures/speech.wav")
if err != nil {
panic(err)
}
defer file.Close()
client := openai.NewClient()
transcription, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{
File: file,
Model: openai.AudioModelGPT4oTranscribe,
})
if err != nil {
panic(err)
}
completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
Model: "gpt-4.1",
Temperature: openai.Float(0),
Messages: []openai.ChatCompletionMessageParamUnion{
openai.SystemMessage(systemPrompt),
openai.UserMessage(transcription.Text),
},
Store: openai.Bool(true),
})
if err != nil {
panic(err)
}
fmt.Println(completion.Choices[0].Message.Content)
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.audio.transcriptions.TranscriptionCreateParams;
import com.openai.models.chat.completions.ChatCompletionCreateParams;
import java.nio.file.Path;
String systemPrompt =
"""
You are a helpful assistant for the company ZyntriQix. Your task is to
correct any spelling discrepancies in the transcribed text. Make sure that
the names of the following products are spelled correctly: 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.
Only add necessary punctuation such as periods, commas, and capitalization,
and use only the context provided.
""";
var result =
client
.audio()
.transcriptions()
.create(
TranscriptionCreateParams.builder()
.file(Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH")))
.model("gpt-4o-transcribe")
.build());
var completion =
client
.chat()
.completions()
.create(
ChatCompletionCreateParams.builder()
.model("gpt-4.1")
.temperature(0.0)
.store(true)
.addSystemMessage(systemPrompt)
.addUserMessage(result.asTranscription().text())
.build());
completion.choices().stream()
.flatMap(choice -> choice.message().content().stream())
.forEach(System.out::println); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 using OpenAI.Audio;
using OpenAI.Chat;
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
string model = "gpt-4.1";
ChatClient client = new(model, key);
string transcriptionModel = "gpt-4o-transcribe";
AudioClient audio = new(transcriptionModel, key);
await using FileStream source = File.OpenRead("speech.wav");
AudioTranscription transcription = await audio.TranscribeAudioAsync(source, "speech.wav");
string systemPrompt =
"""
You are a helpful assistant for the company ZyntriQix. Correct any
spelling discrepancies in the transcribed text. Make sure the names
of these products are spelled correctly: 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.
Only add necessary punctuation such as periods, commas, and
capitalization, and use only the context provided.
""";
ChatCompletionOptions correctionOptions = new() { Temperature = 0 };
ChatCompletion completion = await client.CompleteChatAsync(
[
new SystemChatMessage(systemPrompt),
new UserChatMessage(transcription.Text),
],
correctionOptions
);
Console.WriteLine(completion.Content[0].Text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 require "openai"
require "pathname"
client = OpenAI::Client.new
audio = Pathname("speech.wav")
transcript = client.audio.transcriptions.create(
file: audio,
model: "gpt-4o-mini-transcribe"
)
raise "Expected a JSON transcript response" if transcript.is_a?(StringIO)
response = client.responses.create(
model: "gpt-4.1",
input: "Add punctuation and paragraph breaks without changing the words:\n#{transcript.text}"
)
puts(response.output_text) 文字模型可以修正拼字錯誤,也能處理更長的術語清單,不受 Whisper 提示詞 224 個 Token 的限制。請對照原始音訊檢查修正結果,以免改變說話者的原話。