Skip to content

Commit 56bcaba

Browse files
authored
docs: Update speech synthesis sample code (#8230)
Update speech synthesis sample code
1 parent 17b5d48 commit 56bcaba

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

TextToSpeech/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ require __DIR__ . '/vendor/autoload.php';
3333
use Google\Cloud\TextToSpeech\V1\AudioConfig;
3434
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
3535
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
36-
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
36+
use Google\Cloud\TextToSpeech\V1\Client\TextToSpeechClient;
3737
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
38+
use Google\Cloud\TextToSpeech\V1\SynthesizeSpeechRequest;
3839

3940
$textToSpeechClient = new TextToSpeechClient();
4041

@@ -44,8 +45,12 @@ $voice = new VoiceSelectionParams();
4445
$voice->setLanguageCode('en-US');
4546
$audioConfig = new AudioConfig();
4647
$audioConfig->setAudioEncoding(AudioEncoding::MP3);
48+
$request = (new SynthesizeSpeechRequest())
49+
->setInput($input)
50+
->setVoice($voice)
51+
->setAudioConfig($audioConfig);
4752

48-
$resp = $textToSpeechClient->synthesizeSpeech($input, $voice, $audioConfig);
53+
$resp = $textToSpeechClient->synthesizeSpeech($request);
4954
file_put_contents('test.mp3', $resp->getAudioContent());
5055
```
5156

0 commit comments

Comments
 (0)