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.
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().
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.
$base64 = $response->toBase64();
return response()->json([
'audio' => $base64,
]);
<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().
$wav = (string) $response;
Last modified on May 23, 2026