> ## 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

> Method guide for the VoicevoxResponse class that represents synthesized audio output in VOICEVOX for Laravel.

## Overview

`VoicevoxResponse` is the response object returned by synthesis execution methods such as `talk()->generate()` and `song()->generate()`.

It wraps WAV binary data and provides helper methods for saving, converting, and casting.

## `content()`

`content()` returns the raw WAV binary. Use it when you want to return audio directly in an 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()` saves the WAV data through Laravel `Storage`. Its arguments follow the same idea as `Storage::put()`.

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

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

// File name only
$path = $response->storeAs('output.wav');

// Path and file name separately
$path = $response->storeAs('audio', 'output.wav');

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

The return value is the stored path (`string`), or `false` if saving fails.

## `toBase64()`

`toBase64()` returns the WAV data as a Base64 string. This is useful for JSON responses and inline HTML audio playback.

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

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

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

## `__toString()`

When you cast `VoicevoxResponse` to a string, it returns the same WAV binary as `content()`.

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