如果你有已完成的錄音,或要處理範圍明確的音訊請求,請使用檔案轉錄。上傳音訊後,你可以接收最終轉錄文字,或在模型處理檔案時以串流方式接收文字。
建議先使用 gpt-transcribe 。若要以錄音的原始語言轉錄語音,這是建議使用的模型。只有在需要說話者標籤、逐字時間戳記、字幕格式或翻譯成英文時,才使用專用模型。
檔案大小上限為 25 MB。支援的輸入格式包括 mp3、mp4、mpeg、mpga、m4a、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 require "openai"
require "pathname"
client = OpenAI::Client.new
audio = Pathname("audio.wav")
transcript = client.audio.transcriptions.create(
file: audio,
model: "gpt-transcribe"
)
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 參考文件 。
新增轉錄上下文
使用 gpt-transcribe 時,搭配 prompt、keywords 和 languages,可改善專業術語和多語音訊的轉錄效果:
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 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"]
)
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 欄位。請勿同時傳送這兩個欄位。每個關鍵字都必須維持在同一行,且不得包含 <、>、歸位字元或換行字元。當 API 遇到其中任一字元,或 prompt 超過模型的長度限制時,會拒絕整個請求。
只有在需要辨識錄音各個部分由誰發言時,才使用 gpt-4o-transcribe-diarize。這個模型專門用於標記說話者,不是一般檔案轉錄的建議模型。
要求使用 diarized_json 回應格式,即可取得含有 speaker、start 和 end 中繼資料的片段。音訊長度若超過 30 秒,請將 chunking_strategy 設為 "auto" 或語音活動偵測組態。
你也可以選擇透過 known_speaker_names[] 和 known_speaker_references[] 提供最多四段簡短的參考音訊,將片段對應到已知的說話者。參考片段的長度須為 2–10 秒,可採用主要音訊上傳所支援的任何輸入格式;使用多部分表單資料時,請將參考片段編碼為 data 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],
});
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。轉錄會保留錄音的原始語言,而此端點會傳回英文文字。
1
2
3
4
5
6
7
8
9
10
11 import fs from "fs";
import OpenAI from "openai";
const openai = new OpenAI();
const translation = await openai.audio.translations.create({
file: fs.createReadStream("fixtures/german.wav"),
model: "whisper-1",
});
console.log(translation.text); 1
2
3
4
5
6
7
8
9
10
11 from openai import OpenAI
client = OpenAI()
audio_file = open ( "german.wav" , "rb" )
translation = client.audio.translations.create(
model = "whisper-1" ,
file = audio_file,
)
print (translation.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/german.wav")
if err != nil {
panic(err)
}
defer file.Close()
client := openai.NewClient()
translation, err := client.Audio.Translations.New(context.Background(), openai.AudioTranslationNewParams{
File: file,
Model: openai.AudioModelWhisper1,
})
if err != nil {
panic(err)
}
fmt.Println(translation.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.translations.TranslationCreateParams;
import java.nio.file.Path;
var result =
client
.audio()
.translations()
.create(
TranslationCreateParams.builder()
.file(Path.of(System.getenv("OPENAI_EXAMPLE_AUDIO_PATH")))
.model("whisper-1")
.build());
System.out.println(result.asTranslation().text()); 1
2
3
4
5
6
7
8
9
10
11
12 using OpenAI.Audio;
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
AudioClient client = new("whisper-1", key);
await using FileStream audio = File.OpenRead("german.wav");
AudioTranslation translation = await client.TranslateAudioAsync(
audio,
"german.wav"
);
Console.WriteLine(translation.Text); 1
2
3
4
5
6
7 require "openai"
require "pathname"
client = OpenAI::Client.new
audio = Pathname("german.wav")
translation = client.audio.translations.create(file: audio, model: "whisper-1")
puts(translation.text) 1
2
3
4
5
6 curl --request POST \
--url https://api.openai.com/v1/audio/translations \
--header "Authorization: Bearer $OPENAI_API_KEY" \
--header 'Content-Type: multipart/form-data' \
--form file=@/path/to/file/german.mp3 \
--form model=whisper-1 \
如果錄音使用的是其他語言,回應會包含英文翻譯:
Hello, my name is Wolfgang and I come from Germany. Where are you heading today?
此端點僅支援翻譯成英文。
若已知預期的輸入語言,請在使用 gpt-transcribe 時搭配 languages。支援的語言代碼格式包括:
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。
需要逐字或片段時間戳記時,請使用 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 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]
)
pp(transcript[: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"
只有 whisper-1 支援 timestamp_granularities[] 參數。
Transcriptions 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,請參閱提高可靠性 。
檔案轉錄可在模型處理已完成的錄音時,以串流方式傳回部分文字。這不需要建立 Realtime 工作階段。
使用 gpt-transcribe 時,設定 stream=true。模型轉錄錄音的各個部分時,Transcriptions 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 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 並提供轉錄上下文 。
使用 prompt 參數 第一種方法是使用選用的 prompt 參數,傳入包含正確拼字的詞彙表。
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.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 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 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"
)
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 require "openai"
require "pathname"
client = OpenAI::Client.new
audio = Pathname("speech.wav")
transcript = client.audio.transcriptions.create(
file: audio,
model: "gpt-4o-mini-transcribe"
)
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 限制的較長術語清單。請對照原始音訊檢查修正結果,以免改變說話者的原話。