Skip to content

Commit 5994da5

Browse files
fix(client): correct types for transcriptions / translations (#1105)
1 parent b50d0cb commit 5994da5

File tree

6 files changed

+179
-7
lines changed

6 files changed

+179
-7
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 68
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-17ddd746c775ca4d4fbe64e5621ac30756ef09c061ff6313190b6ec162222d4c.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-71e58a77027c67e003fdd1b1ac8ac11557d8bfabc7666d1a827c6b1ca8ab98b5.yml

api.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,26 @@ Types:
114114
Types:
115115

116116
- <code><a href="./src/resources/audio/transcriptions.ts">Transcription</a></code>
117+
- <code><a href="./src/resources/audio/transcriptions.ts">TranscriptionSegment</a></code>
118+
- <code><a href="./src/resources/audio/transcriptions.ts">TranscriptionVerbose</a></code>
119+
- <code><a href="./src/resources/audio/transcriptions.ts">TranscriptionWord</a></code>
120+
- <code><a href="./src/resources/audio/transcriptions.ts">TranscriptionCreateResponse</a></code>
117121

118122
Methods:
119123

120-
- <code title="post /audio/transcriptions">client.audio.transcriptions.<a href="./src/resources/audio/transcriptions.ts">create</a>({ ...params }) -> Transcription</code>
124+
- <code title="post /audio/transcriptions">client.audio.transcriptions.<a href="./src/resources/audio/transcriptions.ts">create</a>({ ...params }) -> TranscriptionCreateResponse</code>
121125

122126
## Translations
123127

124128
Types:
125129

126130
- <code><a href="./src/resources/audio/translations.ts">Translation</a></code>
131+
- <code><a href="./src/resources/audio/translations.ts">TranslationVerbose</a></code>
132+
- <code><a href="./src/resources/audio/translations.ts">TranslationCreateResponse</a></code>
127133

128134
Methods:
129135

130-
- <code title="post /audio/translations">client.audio.translations.<a href="./src/resources/audio/translations.ts">create</a>({ ...params }) -> Translation</code>
136+
- <code title="post /audio/translations">client.audio.translations.<a href="./src/resources/audio/translations.ts">create</a>({ ...params }) -> TranslationCreateResponse</code>
131137

132138
## Speech
133139

src/resources/audio/audio.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ export namespace Audio {
2525
export import AudioResponseFormat = AudioAPI.AudioResponseFormat;
2626
export import Transcriptions = TranscriptionsAPI.Transcriptions;
2727
export import Transcription = TranscriptionsAPI.Transcription;
28+
export import TranscriptionSegment = TranscriptionsAPI.TranscriptionSegment;
29+
export import TranscriptionVerbose = TranscriptionsAPI.TranscriptionVerbose;
30+
export import TranscriptionWord = TranscriptionsAPI.TranscriptionWord;
31+
export import TranscriptionCreateResponse = TranscriptionsAPI.TranscriptionCreateResponse;
2832
export import TranscriptionCreateParams = TranscriptionsAPI.TranscriptionCreateParams;
2933
export import Translations = TranslationsAPI.Translations;
3034
export import Translation = TranslationsAPI.Translation;
35+
export import TranslationVerbose = TranslationsAPI.TranslationVerbose;
36+
export import TranslationCreateResponse = TranslationsAPI.TranslationCreateResponse;
3137
export import TranslationCreateParams = TranslationsAPI.TranslationCreateParams;
3238
export import Speech = SpeechAPI.Speech;
3339
export import SpeechModel = SpeechAPI.SpeechModel;

src/resources/audio/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,19 @@
22

33
export { AudioModel, AudioResponseFormat, Audio } from './audio';
44
export { SpeechModel, SpeechCreateParams, Speech } from './speech';
5-
export { Transcription, TranscriptionCreateParams, Transcriptions } from './transcriptions';
6-
export { Translation, TranslationCreateParams, Translations } from './translations';
5+
export {
6+
Transcription,
7+
TranscriptionSegment,
8+
TranscriptionVerbose,
9+
TranscriptionWord,
10+
TranscriptionCreateResponse,
11+
TranscriptionCreateParams,
12+
Transcriptions,
13+
} from './transcriptions';
14+
export {
15+
Translation,
16+
TranslationVerbose,
17+
TranslationCreateResponse,
18+
TranslationCreateParams,
19+
Translations,
20+
} from './translations';

src/resources/audio/transcriptions.ts

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export class Transcriptions extends APIResource {
99
/**
1010
* Transcribes audio into the input language.
1111
*/
12-
create(body: TranscriptionCreateParams, options?: Core.RequestOptions): Core.APIPromise<Transcription> {
12+
create(
13+
body: TranscriptionCreateParams,
14+
options?: Core.RequestOptions,
15+
): Core.APIPromise<TranscriptionCreateResponse> {
1316
return this._client.post('/audio/transcriptions', Core.multipartFormRequestOptions({ body, ...options }));
1417
}
1518
}
@@ -25,6 +28,115 @@ export interface Transcription {
2528
text: string;
2629
}
2730

31+
export interface TranscriptionSegment {
32+
/**
33+
* Unique identifier of the segment.
34+
*/
35+
id: number;
36+
37+
/**
38+
* Average logprob of the segment. If the value is lower than -1, consider the
39+
* logprobs failed.
40+
*/
41+
avg_logprob: number;
42+
43+
/**
44+
* Compression ratio of the segment. If the value is greater than 2.4, consider the
45+
* compression failed.
46+
*/
47+
compression_ratio: number;
48+
49+
/**
50+
* End time of the segment in seconds.
51+
*/
52+
end: number;
53+
54+
/**
55+
* Probability of no speech in the segment. If the value is higher than 1.0 and the
56+
* `avg_logprob` is below -1, consider this segment silent.
57+
*/
58+
no_speech_prob: number;
59+
60+
/**
61+
* Seek offset of the segment.
62+
*/
63+
seek: number;
64+
65+
/**
66+
* Start time of the segment in seconds.
67+
*/
68+
start: number;
69+
70+
/**
71+
* Temperature parameter used for generating the segment.
72+
*/
73+
temperature: number;
74+
75+
/**
76+
* Text content of the segment.
77+
*/
78+
text: string;
79+
80+
/**
81+
* Array of token IDs for the text content.
82+
*/
83+
tokens: Array<number>;
84+
}
85+
86+
/**
87+
* Represents a verbose json transcription response returned by model, based on the
88+
* provided input.
89+
*/
90+
export interface TranscriptionVerbose {
91+
/**
92+
* The duration of the input audio.
93+
*/
94+
duration: string;
95+
96+
/**
97+
* The language of the input audio.
98+
*/
99+
language: string;
100+
101+
/**
102+
* The transcribed text.
103+
*/
104+
text: string;
105+
106+
/**
107+
* Segments of the transcribed text and their corresponding details.
108+
*/
109+
segments?: Array<TranscriptionSegment>;
110+
111+
/**
112+
* Extracted words and their corresponding timestamps.
113+
*/
114+
words?: Array<TranscriptionWord>;
115+
}
116+
117+
export interface TranscriptionWord {
118+
/**
119+
* End time of the word in seconds.
120+
*/
121+
end: number;
122+
123+
/**
124+
* Start time of the word in seconds.
125+
*/
126+
start: number;
127+
128+
/**
129+
* The text content of the word.
130+
*/
131+
word: string;
132+
}
133+
134+
/**
135+
* Represents a transcription response returned by model, based on the provided
136+
* input.
137+
*/
138+
export type TranscriptionCreateResponse = Transcription | TranscriptionVerbose;
139+
28140
export interface TranscriptionCreateParams {
29141
/**
30142
* The audio file object (not file name) to transcribe, in one of these formats:
@@ -80,5 +192,9 @@ export interface TranscriptionCreateParams {
80192

81193
export namespace Transcriptions {
82194
export import Transcription = TranscriptionsAPI.Transcription;
195+
export import TranscriptionSegment = TranscriptionsAPI.TranscriptionSegment;
196+
export import TranscriptionVerbose = TranscriptionsAPI.TranscriptionVerbose;
197+
export import TranscriptionWord = TranscriptionsAPI.TranscriptionWord;
198+
export import TranscriptionCreateResponse = TranscriptionsAPI.TranscriptionCreateResponse;
83199
export import TranscriptionCreateParams = TranscriptionsAPI.TranscriptionCreateParams;
84200
}

src/resources/audio/translations.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import { APIResource } from '../../resource';
44
import * as Core from '../../core';
55
import * as TranslationsAPI from './translations';
66
import * as AudioAPI from './audio';
7+
import * as TranscriptionsAPI from './transcriptions';
78

89
export class Translations extends APIResource {
910
/**
1011
* Translates audio into English.
1112
*/
12-
create(body: TranslationCreateParams, options?: Core.RequestOptions): Core.APIPromise<Translation> {
13+
create(
14+
body: TranslationCreateParams,
15+
options?: Core.RequestOptions,
16+
): Core.APIPromise<TranslationCreateResponse> {
1317
return this._client.post('/audio/translations', Core.multipartFormRequestOptions({ body, ...options }));
1418
}
1519
}
@@ -18,6 +22,30 @@ export interface Translation {
1822
text: string;
1923
}
2024

25+
export interface TranslationVerbose {
26+
/**
27+
* The duration of the input audio.
28+
*/
29+
duration: string;
30+
31+
/**
32+
* The language of the output translation (always `english`).
33+
*/
34+
language: string;
35+
36+
/**
37+
* The translated text.
38+
*/
39+
text: string;
40+
41+
/**
42+
* Segments of the translated text and their corresponding details.
43+
*/
44+
segments?: Array<TranscriptionsAPI.TranscriptionSegment>;
45+
}
46+
47+
export type TranslationCreateResponse = Translation | TranslationVerbose;
48+
2149
export interface TranslationCreateParams {
2250
/**
2351
* The audio file object (not file name) translate, in one of these formats: flac,
@@ -57,5 +85,7 @@ export interface TranslationCreateParams {
5785

5886
export namespace Translations {
5987
export import Translation = TranslationsAPI.Translation;
88+
export import TranslationVerbose = TranslationsAPI.TranslationVerbose;
89+
export import TranslationCreateResponse = TranslationsAPI.TranslationCreateResponse;
6090
export import TranslationCreateParams = TranslationsAPI.TranslationCreateParams;
6191
}

0 commit comments

Comments
 (0)