-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathspeech.ts
More file actions
115 lines (103 loc) · 3.14 KB
/
Copy pathspeech.ts
File metadata and controls
115 lines (103 loc) · 3.14 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../core/resource';
import { APIPromise } from '../../core/api-promise';
import { buildHeaders } from '../../internal/headers';
import { RequestOptions } from '../../internal/request-options';
/**
* Turn audio into text or text into audio.
*/
export class Speech extends APIResource {
/**
* Generates audio from the input text.
*
* Returns the audio file content, or a stream of audio events.
*
* @example
* ```ts
* const speech = await client.audio.speech.create({
* input: 'input',
* model: 'tts-1',
* voice: 'alloy',
* });
*
* const content = await speech.blob();
* console.log(content);
* ```
*/
create(body: SpeechCreateParams, options?: RequestOptions): APIPromise<Response> {
return this._client.post('/audio/speech', {
body,
...options,
headers: buildHeaders([{ Accept: 'application/octet-stream' }, options?.headers]),
__security: { bearerAuth: true },
__binaryResponse: true,
});
}
}
export type SpeechModel = 'tts-1' | 'tts-1-hd' | 'gpt-4o-mini-tts' | 'gpt-4o-mini-tts-2025-12-15';
export interface SpeechCreateParams {
/**
* The text to generate audio for. The maximum length is 4096 characters.
*/
input: string;
/**
* One of the available [TTS models](https://platform.openai.com/docs/models#tts):
* `tts-1`, `tts-1-hd`, `gpt-4o-mini-tts`, or `gpt-4o-mini-tts-2025-12-15`.
*/
model: (string & {}) | SpeechModel;
/**
* The voice to use when generating the audio. Supported built-in voices are
* `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`,
* `shimmer`, `verse`, `marin`, and `cedar`. You may also provide a custom voice
* object with an `id`, for example `{ "id": "voice_1234" }`. Previews of the
* voices are available in the
* [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
*/
voice:
| string
| 'alloy'
| 'ash'
| 'ballad'
| 'coral'
| 'echo'
| 'sage'
| 'shimmer'
| 'verse'
| 'marin'
| 'cedar'
| SpeechCreateParams.ID;
/**
* Control the voice of your generated audio with additional instructions. Does not
* work with `tts-1` or `tts-1-hd`.
*/
instructions?: string;
/**
* The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`,
* `wav`, and `pcm`.
*/
response_format?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm';
/**
* The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is
* the default.
*/
speed?: number;
/**
* The format to stream the audio in. Supported formats are `sse` and `audio`.
* `sse` is not supported for `tts-1` or `tts-1-hd`.
*/
stream_format?: 'sse' | 'audio';
}
export namespace SpeechCreateParams {
/**
* Custom voice reference.
*/
export interface ID {
/**
* The custom voice ID, e.g. `voice_1234`.
*/
id: string;
}
}
export declare namespace Speech {
export { type SpeechModel as SpeechModel, type SpeechCreateParams as SpeechCreateParams };
}