|
| 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 | +} |
0 commit comments