> ## 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()` 等合成執行方法所傳回的回應物件。Client 模式與 Native 模式使用相同的 `VoicevoxResponse`。

內部保存 WAV 格式的 binary 資料,並提供儲存、轉換、字串化的 utility。

## `content()`

`content()` 回傳原始 WAV binary。可用於直接作為 HTTP response 回傳。

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

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

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

## `storeAs()`

`storeAs()` 將 WAV 儲存至 Laravel 的 `Storage`。參數與 `Storage::put()` 的概念相同。

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

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

// 僅指定檔名
$path = $response->storeAs('output.wav');

// 分別指定路徑與檔名
$path = $response->storeAs('audio', 'output.wav');

// 指定 disk
$path = $response->storeAs('audio', 'output.wav', 's3');
```

回傳值為已儲存的路徑(`string`)。儲存失敗時回傳 `false`。

## `toBase64()`

`toBase64()` 將 WAV binary 轉為 Base64 字串。可用於 JSON response 或嵌入 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 binary。

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


## Related topics

- [VOICEVOX for Laravel](/zh-TW/packages/laravel-voicevox/index.md)
- [入門 - VOICEVOX for Laravel](/zh-TW/packages/laravel-voicevox/getting-started.md)
- [Engine API 模式:Talk(文字語音合成)- VOICEVOX for Laravel](/zh-TW/packages/laravel-voicevox/engine-talk.md)
- [設定參考 - VOICEVOX for Laravel](/zh-TW/packages/laravel-voicevox/configuration.md)
- [Laravel AI SDK 整合 - VOICEVOX for Laravel](/zh-TW/packages/laravel-voicevox/ai-sdk.md)
