Skip to content

Commit 03e88ed

Browse files
feat(api): add audio create method (#127)
1 parent 1d0fc52 commit 03e88ed

File tree

7 files changed

+151
-2
lines changed

7 files changed

+151
-2
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 16
1+
configured_endpoints: 17
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/togetherai%2FTogetherAI-87bcc1e47f49a52fc31601e87d387cf7ef17f50fba0a06aa105a7fcc65644de4.yml

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
This library provides convenient access to the Together REST API from server-side TypeScript or JavaScript.
66

7-
The REST API documentation can be found on [docs.together.ai](https://docs.together.ai). The full API of this library can be found in [api.md](api.md).
7+
The REST API documentation can be found on [docs.together.ai](https://docs.together.ai/). The full API of this library can be found in [api.md](api.md).
88

99
It is generated with [Stainless](https://www.stainlessapi.com/).
1010

api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ Methods:
9999

100100
- <code title="post /images/generations">client.images.<a href="./src/resources/images.ts">create</a>({ ...params }) -> ImageFile</code>
101101

102+
# Audio
103+
104+
Types:
105+
106+
- <code><a href="./src/resources/audio.ts">AudioFile</a></code>
107+
108+
Methods:
109+
110+
- <code title="post /audio/speech">client.audio.<a href="./src/resources/audio.ts">create</a>({ ...params }) -> Response</code>
111+
102112
# Models
103113

104114
Types:

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as Uploads from './uploads';
77
import * as API from './resources/index';
88
import * as TopLevelAPI from './resources/top-level';
99
import { RerankParams, RerankResponse } from './resources/top-level';
10+
import { Audio, AudioCreateParams, AudioFile } from './resources/audio';
1011
import {
1112
Completion,
1213
CompletionCreateParams,
@@ -157,6 +158,7 @@ export class Together extends Core.APIClient {
157158
files: API.Files = new API.Files(this);
158159
fineTune: API.FineTuneResource = new API.FineTuneResource(this);
159160
images: API.Images = new API.Images(this);
161+
audio: API.Audio = new API.Audio(this);
160162
models: API.Models = new API.Models(this);
161163

162164
/**
@@ -211,6 +213,7 @@ Together.Embeddings = Embeddings;
211213
Together.Files = Files;
212214
Together.FineTuneResource = FineTuneResource;
213215
Together.Images = Images;
216+
Together.Audio = Audio;
214217
Together.Models = Models;
215218
export declare namespace Together {
216219
export type RequestOptions = Core.RequestOptions;
@@ -256,6 +259,8 @@ export declare namespace Together {
256259

257260
export { Images as Images, type ImageFile as ImageFile, type ImageCreateParams as ImageCreateParams };
258261

262+
export { Audio as Audio, type AudioFile as AudioFile, type AudioCreateParams as AudioCreateParams };
263+
259264
export { Models as Models, type ModelListResponse as ModelListResponse };
260265
}
261266

src/resources/audio.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../resource';
4+
import * as Core from '../core';
5+
import { type Response } from '../_shims/index';
6+
7+
export class Audio extends APIResource {
8+
/**
9+
* Generate audio from input text
10+
*/
11+
create(body: AudioCreateParams, options?: Core.RequestOptions): Core.APIPromise<Response> {
12+
return this._client.post('/audio/speech', {
13+
body,
14+
...options,
15+
headers: { Accept: 'application/octet-stream', ...options?.headers },
16+
__binaryResponse: true,
17+
});
18+
}
19+
}
20+
21+
export type AudioFile = AudioFile.AudioSpeechStreamEvent | AudioFile.StreamSentinel;
22+
23+
export namespace AudioFile {
24+
export interface AudioSpeechStreamEvent {
25+
data: AudioSpeechStreamEvent.Data;
26+
}
27+
28+
export namespace AudioSpeechStreamEvent {
29+
export interface Data {
30+
/**
31+
* base64 encoded audio stream
32+
*/
33+
b64: string;
34+
35+
model: string;
36+
37+
object: 'audio.tts.chunk';
38+
}
39+
}
40+
41+
export interface StreamSentinel {
42+
data: '[DONE]';
43+
}
44+
}
45+
46+
export interface AudioCreateParams {
47+
/**
48+
* Input text to generate the audio for
49+
*/
50+
input: string;
51+
52+
/**
53+
* The name of the model to query.
54+
*
55+
* [See all of Together AI's chat models](https://docs.together.ai/docs/serverless-models#audio-models)
56+
*/
57+
model: 'cartesia/sonic' | (string & {});
58+
59+
/**
60+
* The voice to use for generating the audio.
61+
* [View all supported voices here](https://docs.together.ai/docs/text-to-speech#voices-available).
62+
*/
63+
voice: 'laidback woman' | 'polite man' | 'storyteller lady' | 'friendly sidekick' | (string & {});
64+
65+
/**
66+
* Language of input text
67+
*/
68+
language?:
69+
| 'en'
70+
| 'de'
71+
| 'fr'
72+
| 'es'
73+
| 'hi'
74+
| 'it'
75+
| 'ja'
76+
| 'ko'
77+
| 'nl'
78+
| 'pl'
79+
| 'pt'
80+
| 'ru'
81+
| 'sv'
82+
| 'tr'
83+
| 'zh';
84+
85+
/**
86+
* Audio encoding of response
87+
*/
88+
response_encoding?: 'pcm_f32le' | 'pcm_s16le' | 'pcm_mulaw' | 'pcm_alaw';
89+
90+
/**
91+
* The format of audio output
92+
*/
93+
response_format?: 'mp3' | 'wav' | 'raw';
94+
95+
/**
96+
* Sampling rate to use for the output audio
97+
*/
98+
sample_rate?: number;
99+
100+
/**
101+
* If true, output is streamed for several characters at a time instead of waiting
102+
* for the full response. The stream terminates with `data: [DONE]`. If false,
103+
* return the encoded audio as octet stream
104+
*/
105+
stream?: boolean;
106+
}
107+
108+
export declare namespace Audio {
109+
export { type AudioFile as AudioFile, type AudioCreateParams as AudioCreateParams };
110+
}

src/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3+
export { Audio, type AudioFile, type AudioCreateParams } from './audio';
34
export { Chat } from './chat/chat';
45
export {
56
Completions,

tests/api-resources/audio.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import Together from 'together-ai';
4+
5+
const client = new Together({
6+
apiKey: 'My API Key',
7+
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
8+
});
9+
10+
describe('resource audio', () => {
11+
test('create: required and optional params', async () => {
12+
const response = await client.audio.create({
13+
input: 'input',
14+
model: 'cartesia/sonic',
15+
voice: 'laidback woman',
16+
language: 'en',
17+
response_encoding: 'pcm_f32le',
18+
response_format: 'mp3',
19+
sample_rate: 0,
20+
stream: true,
21+
});
22+
});
23+
});

0 commit comments

Comments
 (0)