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

# VoicevoxResponse - VOICEVOX for Laravel

> VOICEVOX for Laravel の音声合成結果を表す VoicevoxResponse クラスのメソッド解説。

## 概要

`VoicevoxResponse` は、`talk()->generate()` や `song()->generate()` など、合成実行メソッドが返すレスポンスオブジェクトです。クライアントモードでもネイティブモードでも同じ`VoicevoxResponse`が使われます。

内部では WAV 形式のバイナリデータを保持し、保存・変換・文字列化のユーティリティを提供します。

## `content()`

`content()` は生の WAV バイナリを返します。HTTP レスポンスとしてそのまま返したいときに使います。

```php theme={null}
use Revolution\Voicevox\Voicevox;

$response = Voicevox::talk('ずんだもんなのだ')->generate();
$wav = $response->content(); // WAVバイナリ

return response($wav)->header('Content-Type', 'audio/wav');
```

## `storeAs()`

`storeAs()` は Laravel の `Storage` に WAV を保存します。引数は `Storage::put()` と同じ考え方で扱えます。

```php theme={null}
use Revolution\Voicevox\Voicevox;

$response = Voicevox::talk('ずんだもんなのだ')->generate();

// ファイル名のみ指定
$path = $response->storeAs('output.wav');

// パスとファイル名を分けて指定
$path = $response->storeAs('audio', 'output.wav');

// ディスクを指定
$path = $response->storeAs('audio', 'output.wav', 's3');
```

戻り値は保存したパス（`string`）です。保存に失敗すると `false` を返します。

## `toBase64()`

`toBase64()` は WAV バイナリを Base64 文字列へ変換します。JSON レスポンスや HTML 埋め込みに使えます。

```php theme={null}
$base64 = $response->toBase64();

return response()->json([
    'audio' => $base64,
]);
```

```blade theme={null}
<audio controls src="data:audio/wav;base64,{{ $base64 }}"></audio>
```

## `__toString()`

`VoicevoxResponse` を文字列としてキャストすると `content()` と同じ WAV バイナリが返ります。

```php theme={null}
$wav = (string) $response;
```
