@@ -47,27 +47,7 @@ type RealtimeEvent = {
|
47 | 47 | error?: unknown; |
48 | 48 | }; |
49 | 49 | |
50 | | -type OpenAIRealtimeTranscriptionSessionCreate = { |
51 | | -type: "transcription"; |
52 | | -audio: { |
53 | | -input: { |
54 | | -format: { type: "audio/pcmu" }; |
55 | | -transcription: { |
56 | | -model: string; |
57 | | -language?: string; |
58 | | -prompt?: string; |
59 | | -}; |
60 | | -turn_detection: { |
61 | | -type: "server_vad"; |
62 | | -threshold: number; |
63 | | -prefix_padding_ms: number; |
64 | | -silence_duration_ms: number; |
65 | | -}; |
66 | | -}; |
67 | | -}; |
68 | | -}; |
69 | | - |
70 | | -type OpenAIRealtimeTranscriptionSessionUpdate = { |
| 50 | +type OpenAIRealtimeTranscriptionSessionPayload = { |
71 | 51 | type: "transcription"; |
72 | 52 | audio: { |
73 | 53 | input: { |
@@ -131,33 +111,9 @@ function normalizeVadThreshold(value: unknown): number | undefined {
|
131 | 111 | return number; |
132 | 112 | } |
133 | 113 | |
134 | | -function buildOpenAIRealtimeTranscriptionSessionCreateConfig( |
135 | | -config: OpenAIRealtimeTranscriptionSessionConfig, |
136 | | -): OpenAIRealtimeTranscriptionSessionCreate { |
137 | | -return { |
138 | | -type: "transcription", |
139 | | -audio: { |
140 | | -input: { |
141 | | -format: { type: "audio/pcmu" }, |
142 | | -transcription: { |
143 | | -model: config.model, |
144 | | - ...(config.language ? { language: config.language } : {}), |
145 | | - ...(config.prompt ? { prompt: config.prompt } : {}), |
146 | | -}, |
147 | | -turn_detection: { |
148 | | -type: "server_vad", |
149 | | -threshold: config.vadThreshold, |
150 | | -prefix_padding_ms: 300, |
151 | | -silence_duration_ms: config.silenceDurationMs, |
152 | | -}, |
153 | | -}, |
154 | | -}, |
155 | | -}; |
156 | | -} |
157 | | - |
158 | | -function buildOpenAIRealtimeTranscriptionSessionUpdateConfig( |
| 114 | +function buildOpenAIRealtimeTranscriptionSessionPayload( |
159 | 115 | config: OpenAIRealtimeTranscriptionSessionConfig, |
160 | | -): OpenAIRealtimeTranscriptionSessionUpdate { |
| 116 | +): OpenAIRealtimeTranscriptionSessionPayload { |
161 | 117 | return { |
162 | 118 | type: "transcription", |
163 | 119 | audio: { |
@@ -196,7 +152,7 @@ async function resolveOpenAIRealtimeTranscriptionAuthorization(
|
196 | 152 | const clientSecret = await createOpenAIRealtimeTranscriptionClientSecret({ |
197 | 153 | authToken, |
198 | 154 | auditContext: "openai-realtime-transcription-session", |
199 | | -session: buildOpenAIRealtimeTranscriptionSessionCreateConfig(config), |
| 155 | +session: buildOpenAIRealtimeTranscriptionSessionPayload(config), |
200 | 156 | }); |
201 | 157 | return clientSecret.value; |
202 | 158 | } |
@@ -286,7 +242,7 @@ function createOpenAIRealtimeTranscriptionSession(
|
286 | 242 | onOpen: (transport: RealtimeTranscriptionWebSocketTransport) => { |
287 | 243 | transport.sendJson({ |
288 | 244 | type: "session.update", |
289 | | -session: buildOpenAIRealtimeTranscriptionSessionUpdateConfig(config), |
| 245 | +session: buildOpenAIRealtimeTranscriptionSessionPayload(config), |
290 | 246 | }); |
291 | 247 | }, |
292 | 248 | onMessage: handleEvent, |
|