> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ai-stats.phaseo.app/llms.txt
> Use this file to discover all available pages before exploring further.

# TTS / STT (AI SDK)

> Speech-to-text (STT) and text-to-speech (TTS) with AI Stats provider models.

Use `experimental_transcribe` with `transcriptionModel`, and `experimental_generateSpeech` with `speechModel`.

```ts theme={null}
import { readFileSync, writeFileSync } from "node:fs";
import { aiStats } from "@ai-stats/ai-sdk-provider";
import { experimental_generateSpeech, experimental_transcribe } from "ai";

const audioInput = readFileSync("./audio.mp3");

const transcription = await experimental_transcribe({
  model: aiStats.transcriptionModel("openai/whisper-1"),
  audioData: new Blob([audioInput], { type: "audio/mpeg" }),
});

console.log(transcription.text);
console.log(transcription.providerMetadata);

const speech = await experimental_generateSpeech({
  model: aiStats.speechModel("openai/tts-1"),
  text: "Hello from AI Stats audio.",
  voice: "alloy",
  outputFormat: "mp3",
});

writeFileSync("./speech.mp3", Buffer.from(speech.audio.uint8Array));
console.log(speech.providerMetadata);
```

## Notes

* The current AI SDK audio helpers are still experimental, so expect naming changes when the upstream stable APIs land.
* Audio input/output formats are model-specific.
* Keep payload sizes and timeout settings appropriate for long files.
* Run retry logic for transient 429/5xx responses.
