> ## 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()` 会将 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');

// 指定磁盘
$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;
```


## Related topics

- [VOICEVOX for Laravel](/zh/packages/laravel-voicevox/index.md)
- [引擎 API 模式：Talk（文本语音合成） - VOICEVOX for Laravel](/zh/packages/laravel-voicevox/engine-talk.md)
- [开始使用 - VOICEVOX for Laravel](/zh/packages/laravel-voicevox/getting-started.md)
- [配置参考 - VOICEVOX for Laravel](/zh/packages/laravel-voicevox/configuration.md)
- [Laravel AI SDK 集成 - VOICEVOX for Laravel](/zh/packages/laravel-voicevox/ai-sdk.md)
