Audio
Two endpoints in OpenAI’s audio format: one reads text aloud, the other writes down what was said.
Text to speech
Section titled “Text to speech”POST https://api.exoticrouter.com/v1/audio/speech
curl https://api.exoticrouter.com/v1/audio/speech \ -H "Authorization: Bearer $EXOTIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-4o-mini-tts", "voice": "alloy", "input": "The sky is blue because air scatters blue light the most." }' \ -o speech.mp3with client.audio.speech.with_streaming_response.create( model="openai/gpt-4o-mini-tts", voice="alloy", input="The sky is blue because air scatters blue light the most.",) as response: response.stream_to_file("speech.mp3")import fs from "node:fs";
const speech = await client.audio.speech.create({ model: "openai/gpt-4o-mini-tts", voice: "alloy", input: "The sky is blue because air scatters blue light the most.",});fs.writeFileSync("speech.mp3", Buffer.from(await speech.arrayBuffer()));modelhas to be a speech model: one whoseformatsin the list of models hasspeech.- The answer is the audio itself, sent as it is made, with its own content type (
audio/mpegfor MP3). The rest of the body,voiceand the output format for instance, goes to the model.
Speech to text
Section titled “Speech to text”POST https://api.exoticrouter.com/v1/audio/transcriptions
Send the recording as a form, with the model beside it.
curl https://api.exoticrouter.com/v1/audio/transcriptions \ -H "Authorization: Bearer $EXOTIC_API_KEY" \ -F model="openai/gpt-4o-mini-transcribe" \ -F file="@meeting.mp3"transcript = client.audio.transcriptions.create( model="openai/gpt-4o-mini-transcribe", file=open("meeting.mp3", "rb"),)print(transcript.text)import fs from "node:fs";
const transcript = await client.audio.transcriptions.create({ model: "openai/gpt-4o-mini-transcribe", file: fs.createReadStream("meeting.mp3"),});console.log(transcript.text);{ "text": "Right, shall we start? First on the list is the launch date." }modelhas to be a transcription model: one whoseformatshastranscriptions.- The file and every other part of the form reach the model unchanged. Ask for another
response_format, plain text or subtitles, and the answer comes in it. - The whole request, recording included, may be up to 32 MiB.
What it costs
Section titled “What it costs”- Speech is priced on the characters of
input: for a speech model,input_per_mtokis USD per million characters. - Transcription is priced on the tokens the model reports where it reports them, and otherwise on the length of the recording, by the second.
- A model’s
per_request, if it has one, is added once to each request.
Billing has the whole of it.
Where next
Section titled “Where next”- Embeddings: Text to vectors.
- OpenAI SDK: The client these samples use.