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

# 音声合成 / 音声認識（AI SDK）

> Phaseoプロバイダーモデルを使った音声認識（STT）と音声合成（TTS）。

`transcriptionModel`と`experimental_transcribe`、`speechModel`と`experimental_generateSpeech`を使います。

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

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

const transcription = await experimental_transcribe({
  model: phaseo.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: phaseo.speechModel("openai/tts-1"),
  text: "Hello from Phaseo audio.",
  voice: "alloy",
  outputFormat: "mp3",
});

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

## 注意事項

* 現在のAI SDK音声ヘルパーはまだ実験的なため、上流の安定版APIが公開された際に名前が変わる可能性があります。
* 音声の入力/出力形式はモデルによって異なります。
* 長いファイルに合わせてペイロードサイズとタイムアウトを設定します。
* 一時的な`429`や`5xx`レスポンスには再試行を行います。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.