Skip to content

Audio generation models ​

Audio generation models turn text into audio bytes. Use them for narration, accessibility, voice responses, and media workflows.

Create an audio model ​

ts
import { TTS_1, OpenAIClient } from '@anvia/openai'

const openai = new OpenAIClient({
  apiKey: process.env.OPENAI_API_KEY,
})

export const audioModel = openai.audioGenerationModel(TTS_1)

OpenAI and Grok currently provide audio-generation adapters.

Generate audio ​

ts
import { writeFile } from 'node:fs/promises'
import { audioGenerationRequest } from '@anvia/core/audio-generation'

const response = await audioGenerationRequest(audioModel)
  .text('Your incident summary is ready.')
  .voice('alloy')
  .speed(1)
  .additionalParams({ response_format: 'mp3' })
  .send()

await writeFile('incident-summary.mp3', response.audio)

The response contains audio bytes, an optional media type, and the raw provider response.

Production boundary ​

Validate text length, voice, speed, and format before generation. Store generated bytes in media storage instead of agent memory or event logs, and use a queue for long scripts or bulk work.

Built for Anvia.