transcriptions.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. import { APIResource } from "../../resource.js";
  2. import * as Core from "../../core.js";
  3. import * as TranscriptionsAPI from "./transcriptions.js";
  4. import * as AudioAPI from "./audio.js";
  5. import { Stream } from "../../streaming.js";
  6. export declare class Transcriptions extends APIResource {
  7. /**
  8. * Transcribes audio into the input language.
  9. *
  10. * @example
  11. * ```ts
  12. * const transcription =
  13. * await client.audio.transcriptions.create({
  14. * file: fs.createReadStream('speech.mp3'),
  15. * model: 'gpt-4o-transcribe',
  16. * });
  17. * ```
  18. */
  19. create(body: TranscriptionCreateParamsNonStreaming<'json' | undefined>, options?: Core.RequestOptions): Core.APIPromise<Transcription>;
  20. create(body: TranscriptionCreateParamsNonStreaming<'verbose_json'>, options?: Core.RequestOptions): Core.APIPromise<TranscriptionVerbose>;
  21. create(body: TranscriptionCreateParamsNonStreaming<'srt' | 'vtt' | 'text'>, options?: Core.RequestOptions): Core.APIPromise<string>;
  22. create(body: TranscriptionCreateParamsNonStreaming, options?: Core.RequestOptions): Core.APIPromise<Transcription>;
  23. create(body: TranscriptionCreateParamsStreaming, options?: Core.RequestOptions): Core.APIPromise<Stream<TranscriptionStreamEvent>>;
  24. create(body: TranscriptionCreateParamsStreaming, options?: Core.RequestOptions): Core.APIPromise<TranscriptionCreateResponse | string | Stream<TranscriptionStreamEvent>>;
  25. }
  26. /**
  27. * Represents a transcription response returned by model, based on the provided
  28. * input.
  29. */
  30. export interface Transcription {
  31. /**
  32. * The transcribed text.
  33. */
  34. text: string;
  35. /**
  36. * The log probabilities of the tokens in the transcription. Only returned with the
  37. * models `gpt-4o-transcribe` and `gpt-4o-mini-transcribe` if `logprobs` is added
  38. * to the `include` array.
  39. */
  40. logprobs?: Array<Transcription.Logprob>;
  41. }
  42. export declare namespace Transcription {
  43. interface Logprob {
  44. /**
  45. * The token in the transcription.
  46. */
  47. token?: string;
  48. /**
  49. * The bytes of the token.
  50. */
  51. bytes?: Array<number>;
  52. /**
  53. * The log probability of the token.
  54. */
  55. logprob?: number;
  56. }
  57. }
  58. export type TranscriptionInclude = 'logprobs';
  59. export interface TranscriptionSegment {
  60. /**
  61. * Unique identifier of the segment.
  62. */
  63. id: number;
  64. /**
  65. * Average logprob of the segment. If the value is lower than -1, consider the
  66. * logprobs failed.
  67. */
  68. avg_logprob: number;
  69. /**
  70. * Compression ratio of the segment. If the value is greater than 2.4, consider the
  71. * compression failed.
  72. */
  73. compression_ratio: number;
  74. /**
  75. * End time of the segment in seconds.
  76. */
  77. end: number;
  78. /**
  79. * Probability of no speech in the segment. If the value is higher than 1.0 and the
  80. * `avg_logprob` is below -1, consider this segment silent.
  81. */
  82. no_speech_prob: number;
  83. /**
  84. * Seek offset of the segment.
  85. */
  86. seek: number;
  87. /**
  88. * Start time of the segment in seconds.
  89. */
  90. start: number;
  91. /**
  92. * Temperature parameter used for generating the segment.
  93. */
  94. temperature: number;
  95. /**
  96. * Text content of the segment.
  97. */
  98. text: string;
  99. /**
  100. * Array of token IDs for the text content.
  101. */
  102. tokens: Array<number>;
  103. }
  104. /**
  105. * Emitted when there is an additional text delta. This is also the first event
  106. * emitted when the transcription starts. Only emitted when you
  107. * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)
  108. * with the `Stream` parameter set to `true`.
  109. */
  110. export type TranscriptionStreamEvent = TranscriptionTextDeltaEvent | TranscriptionTextDoneEvent;
  111. /**
  112. * Emitted when there is an additional text delta. This is also the first event
  113. * emitted when the transcription starts. Only emitted when you
  114. * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)
  115. * with the `Stream` parameter set to `true`.
  116. */
  117. export interface TranscriptionTextDeltaEvent {
  118. /**
  119. * The text delta that was additionally transcribed.
  120. */
  121. delta: string;
  122. /**
  123. * The type of the event. Always `transcript.text.delta`.
  124. */
  125. type: 'transcript.text.delta';
  126. /**
  127. * The log probabilities of the delta. Only included if you
  128. * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)
  129. * with the `include[]` parameter set to `logprobs`.
  130. */
  131. logprobs?: Array<TranscriptionTextDeltaEvent.Logprob>;
  132. }
  133. export declare namespace TranscriptionTextDeltaEvent {
  134. interface Logprob {
  135. /**
  136. * The token that was used to generate the log probability.
  137. */
  138. token?: string;
  139. /**
  140. * The bytes that were used to generate the log probability.
  141. */
  142. bytes?: Array<unknown>;
  143. /**
  144. * The log probability of the token.
  145. */
  146. logprob?: number;
  147. }
  148. }
  149. /**
  150. * Emitted when the transcription is complete. Contains the complete transcription
  151. * text. Only emitted when you
  152. * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)
  153. * with the `Stream` parameter set to `true`.
  154. */
  155. export interface TranscriptionTextDoneEvent {
  156. /**
  157. * The text that was transcribed.
  158. */
  159. text: string;
  160. /**
  161. * The type of the event. Always `transcript.text.done`.
  162. */
  163. type: 'transcript.text.done';
  164. /**
  165. * The log probabilities of the individual tokens in the transcription. Only
  166. * included if you
  167. * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)
  168. * with the `include[]` parameter set to `logprobs`.
  169. */
  170. logprobs?: Array<TranscriptionTextDoneEvent.Logprob>;
  171. }
  172. export declare namespace TranscriptionTextDoneEvent {
  173. interface Logprob {
  174. /**
  175. * The token that was used to generate the log probability.
  176. */
  177. token?: string;
  178. /**
  179. * The bytes that were used to generate the log probability.
  180. */
  181. bytes?: Array<unknown>;
  182. /**
  183. * The log probability of the token.
  184. */
  185. logprob?: number;
  186. }
  187. }
  188. /**
  189. * Represents a verbose json transcription response returned by model, based on the
  190. * provided input.
  191. */
  192. export interface TranscriptionVerbose {
  193. /**
  194. * The duration of the input audio.
  195. */
  196. duration: number;
  197. /**
  198. * The language of the input audio.
  199. */
  200. language: string;
  201. /**
  202. * The transcribed text.
  203. */
  204. text: string;
  205. /**
  206. * Segments of the transcribed text and their corresponding details.
  207. */
  208. segments?: Array<TranscriptionSegment>;
  209. /**
  210. * Extracted words and their corresponding timestamps.
  211. */
  212. words?: Array<TranscriptionWord>;
  213. }
  214. export interface TranscriptionWord {
  215. /**
  216. * End time of the word in seconds.
  217. */
  218. end: number;
  219. /**
  220. * Start time of the word in seconds.
  221. */
  222. start: number;
  223. /**
  224. * The text content of the word.
  225. */
  226. word: string;
  227. }
  228. /**
  229. * Represents a transcription response returned by model, based on the provided
  230. * input.
  231. */
  232. export type TranscriptionCreateResponse = Transcription | TranscriptionVerbose;
  233. export type TranscriptionCreateParams<ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined> = TranscriptionCreateParamsNonStreaming<ResponseFormat> | TranscriptionCreateParamsStreaming;
  234. export interface TranscriptionCreateParamsBase<ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined> {
  235. /**
  236. * The audio file object (not file name) to transcribe, in one of these formats:
  237. * flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
  238. */
  239. file: Core.Uploadable;
  240. /**
  241. * ID of the model to use. The options are `gpt-4o-transcribe`,
  242. * `gpt-4o-mini-transcribe`, and `whisper-1` (which is powered by our open source
  243. * Whisper V2 model).
  244. */
  245. model: (string & {}) | AudioAPI.AudioModel;
  246. /**
  247. * Controls how the audio is cut into chunks. When set to `"auto"`, the server
  248. * first normalizes loudness and then uses voice activity detection (VAD) to choose
  249. * boundaries. `server_vad` object can be provided to tweak VAD detection
  250. * parameters manually. If unset, the audio is transcribed as a single block.
  251. */
  252. chunking_strategy?: 'auto' | TranscriptionCreateParams.VadConfig | null;
  253. /**
  254. * Additional information to include in the transcription response. `logprobs` will
  255. * return the log probabilities of the tokens in the response to understand the
  256. * model's confidence in the transcription. `logprobs` only works with
  257. * response_format set to `json` and only with the models `gpt-4o-transcribe` and
  258. * `gpt-4o-mini-transcribe`.
  259. */
  260. include?: Array<TranscriptionInclude>;
  261. /**
  262. * The language of the input audio. Supplying the input language in
  263. * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)
  264. * format will improve accuracy and latency.
  265. */
  266. language?: string;
  267. /**
  268. * An optional text to guide the model's style or continue a previous audio
  269. * segment. The
  270. * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting)
  271. * should match the audio language.
  272. */
  273. prompt?: string;
  274. /**
  275. * The format of the output, in one of these options: `json`, `text`, `srt`,
  276. * `verbose_json`, or `vtt`. For `gpt-4o-transcribe` and `gpt-4o-mini-transcribe`,
  277. * the only supported format is `json`.
  278. */
  279. response_format?: ResponseFormat;
  280. /**
  281. * If set to true, the model response data will be streamed to the client as it is
  282. * generated using
  283. * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
  284. * See the
  285. * [Streaming section of the Speech-to-Text guide](https://platform.openai.com/docs/guides/speech-to-text?lang=curl#streaming-transcriptions)
  286. * for more information.
  287. *
  288. * Note: Streaming is not supported for the `whisper-1` model and will be ignored.
  289. */
  290. stream?: boolean | null;
  291. /**
  292. * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the
  293. * output more random, while lower values like 0.2 will make it more focused and
  294. * deterministic. If set to 0, the model will use
  295. * [log probability](https://en.wikipedia.org/wiki/Log_probability) to
  296. * automatically increase the temperature until certain thresholds are hit.
  297. */
  298. temperature?: number;
  299. /**
  300. * The timestamp granularities to populate for this transcription.
  301. * `response_format` must be set `verbose_json` to use timestamp granularities.
  302. * Either or both of these options are supported: `word`, or `segment`. Note: There
  303. * is no additional latency for segment timestamps, but generating word timestamps
  304. * incurs additional latency.
  305. */
  306. timestamp_granularities?: Array<'word' | 'segment'>;
  307. }
  308. export declare namespace TranscriptionCreateParams {
  309. interface VadConfig {
  310. /**
  311. * Must be set to `server_vad` to enable manual chunking using server side VAD.
  312. */
  313. type: 'server_vad';
  314. /**
  315. * Amount of audio to include before the VAD detected speech (in milliseconds).
  316. */
  317. prefix_padding_ms?: number;
  318. /**
  319. * Duration of silence to detect speech stop (in milliseconds). With shorter values
  320. * the model will respond more quickly, but may jump in on short pauses from the
  321. * user.
  322. */
  323. silence_duration_ms?: number;
  324. /**
  325. * Sensitivity threshold (0.0 to 1.0) for voice activity detection. A higher
  326. * threshold will require louder audio to activate the model, and thus might
  327. * perform better in noisy environments.
  328. */
  329. threshold?: number;
  330. }
  331. type TranscriptionCreateParamsNonStreaming = TranscriptionsAPI.TranscriptionCreateParamsNonStreaming;
  332. type TranscriptionCreateParamsStreaming = TranscriptionsAPI.TranscriptionCreateParamsStreaming;
  333. }
  334. export interface TranscriptionCreateParamsNonStreaming<ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined> extends TranscriptionCreateParamsBase<ResponseFormat> {
  335. /**
  336. * If set to true, the model response data will be streamed to the client as it is
  337. * generated using
  338. * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
  339. * See the
  340. * [Streaming section of the Speech-to-Text guide](https://platform.openai.com/docs/guides/speech-to-text?lang=curl#streaming-transcriptions)
  341. * for more information.
  342. *
  343. * Note: Streaming is not supported for the `whisper-1` model and will be ignored.
  344. */
  345. stream?: false | null;
  346. }
  347. export interface TranscriptionCreateParamsStreaming extends TranscriptionCreateParamsBase {
  348. /**
  349. * If set to true, the model response data will be streamed to the client as it is
  350. * generated using
  351. * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
  352. * See the
  353. * [Streaming section of the Speech-to-Text guide](https://platform.openai.com/docs/guides/speech-to-text?lang=curl#streaming-transcriptions)
  354. * for more information.
  355. *
  356. * Note: Streaming is not supported for the `whisper-1` model and will be ignored.
  357. */
  358. stream: true;
  359. }
  360. export declare namespace Transcriptions {
  361. export { type Transcription as Transcription, type TranscriptionInclude as TranscriptionInclude, type TranscriptionSegment as TranscriptionSegment, type TranscriptionStreamEvent as TranscriptionStreamEvent, type TranscriptionTextDeltaEvent as TranscriptionTextDeltaEvent, type TranscriptionTextDoneEvent as TranscriptionTextDoneEvent, type TranscriptionVerbose as TranscriptionVerbose, type TranscriptionWord as TranscriptionWord, type TranscriptionCreateResponse as TranscriptionCreateResponse, type TranscriptionCreateParams as TranscriptionCreateParams, type TranscriptionCreateParamsNonStreaming as TranscriptionCreateParamsNonStreaming, type TranscriptionCreateParamsStreaming as TranscriptionCreateParamsStreaming, };
  362. }
  363. //# sourceMappingURL=transcriptions.d.ts.map