Skip to content

Commit 34497ce

Browse files
bshafferpattishin
authored andcommitted
chore: upgrade texttospeech samples to new surface (#1880)
1 parent 508434d commit 34497ce

9 files changed

+54
-17
lines changed

texttospeech/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"google/cloud-text-to-speech": "^1.0.0"
3+
"google/cloud-text-to-speech": "^1.7"
44
}
55
}

texttospeech/quickstart.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
// Imports the Cloud Client Library
2323
use Google\Cloud\TextToSpeech\V1\AudioConfig;
2424
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
25+
use Google\Cloud\TextToSpeech\V1\Client\TextToSpeechClient;
2526
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
2627
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
27-
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
28+
use Google\Cloud\TextToSpeech\V1\SynthesizeSpeechRequest;
2829
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
2930

3031
// instantiates a client
@@ -50,7 +51,11 @@
5051

5152
// perform text-to-speech request on the text input with selected voice
5253
// parameters and audio file type
53-
$response = $client->synthesizeSpeech($synthesisInputText, $voice, $audioConfig);
54+
$request = (new SynthesizeSpeechRequest())
55+
->setInput($synthesisInputText)
56+
->setVoice($voice)
57+
->setAudioConfig($audioConfig);
58+
$response = $client->synthesizeSpeech($request);
5459
$audioContent = $response->getAudioContent();
5560

5661
// the response's audioContent is binary

texttospeech/src/list_voices.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@
2424
namespace Google\Cloud\Samples\TextToSpeech;
2525

2626
// [START tts_list_voices]
27-
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
27+
use Google\Cloud\TextToSpeech\V1\Client\TextToSpeechClient;
28+
use Google\Cloud\TextToSpeech\V1\ListVoicesRequest;
2829

2930
function list_voices(): void
3031
{
3132
// create client object
3233
$client = new TextToSpeechClient();
3334

3435
// perform list voices request
35-
$response = $client->listVoices();
36+
$request = (new ListVoicesRequest());
37+
$response = $client->listVoices($request);
3638
$voices = $response->getVoices();
3739

3840
foreach ($voices as $voice) {

texttospeech/src/synthesize_ssml.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
// [START tts_synthesize_ssml]
2727
use Google\Cloud\TextToSpeech\V1\AudioConfig;
2828
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
29+
use Google\Cloud\TextToSpeech\V1\Client\TextToSpeechClient;
2930
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
3031
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
31-
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
32+
use Google\Cloud\TextToSpeech\V1\SynthesizeSpeechRequest;
3233
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
3334

3435
/**
@@ -50,8 +51,12 @@ function synthesize_ssml(string $ssml): void
5051

5152
$audioConfig = (new AudioConfig())
5253
->setAudioEncoding(AudioEncoding::MP3);
54+
$request = (new SynthesizeSpeechRequest())
55+
->setInput($input_text)
56+
->setVoice($voice)
57+
->setAudioConfig($audioConfig);
5358

54-
$response = $client->synthesizeSpeech($input_text, $voice, $audioConfig);
59+
$response = $client->synthesizeSpeech($request);
5560
$audioContent = $response->getAudioContent();
5661

5762
file_put_contents('output.mp3', $audioContent);

texttospeech/src/synthesize_ssml_file.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
// [START tts_synthesize_ssml_file]
2727
use Google\Cloud\TextToSpeech\V1\AudioConfig;
2828
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
29+
use Google\Cloud\TextToSpeech\V1\Client\TextToSpeechClient;
2930
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
3031
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
31-
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
32+
use Google\Cloud\TextToSpeech\V1\SynthesizeSpeechRequest;
3233
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
3334

3435
/**
@@ -52,8 +53,12 @@ function synthesize_ssml_file(string $path): void
5253

5354
$audioConfig = (new AudioConfig())
5455
->setAudioEncoding(AudioEncoding::MP3);
56+
$request = (new SynthesizeSpeechRequest())
57+
->setInput($input_text)
58+
->setVoice($voice)
59+
->setAudioConfig($audioConfig);
5560

56-
$response = $client->synthesizeSpeech($input_text, $voice, $audioConfig);
61+
$response = $client->synthesizeSpeech($request);
5762
$audioContent = $response->getAudioContent();
5863

5964
file_put_contents('output.mp3', $audioContent);

texttospeech/src/synthesize_text.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
// [START tts_synthesize_text]
2727
use Google\Cloud\TextToSpeech\V1\AudioConfig;
2828
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
29+
use Google\Cloud\TextToSpeech\V1\Client\TextToSpeechClient;
2930
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
3031
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
31-
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
32+
use Google\Cloud\TextToSpeech\V1\SynthesizeSpeechRequest;
3233
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
3334

3435
/**
@@ -50,8 +51,12 @@ function synthesize_text(string $text): void
5051

5152
$audioConfig = (new AudioConfig())
5253
->setAudioEncoding(AudioEncoding::MP3);
54+
$request = (new SynthesizeSpeechRequest())
55+
->setInput($input_text)
56+
->setVoice($voice)
57+
->setAudioConfig($audioConfig);
5358

54-
$response = $client->synthesizeSpeech($input_text, $voice, $audioConfig);
59+
$response = $client->synthesizeSpeech($request);
5560
$audioContent = $response->getAudioContent();
5661

5762
file_put_contents('output.mp3', $audioContent);

texttospeech/src/synthesize_text_effects_profile.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
// [START tts_synthesize_text_audio_profile]
2727
use Google\Cloud\TextToSpeech\V1\AudioConfig;
2828
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
29+
use Google\Cloud\TextToSpeech\V1\Client\TextToSpeechClient;
2930
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
3031
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
31-
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
32+
use Google\Cloud\TextToSpeech\V1\SynthesizeSpeechRequest;
3233
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
3334

3435
/**
@@ -53,8 +54,12 @@ function synthesize_text_effects_profile(string $text, string $effectsProfileId)
5354
$audioConfig = (new AudioConfig())
5455
->setAudioEncoding(AudioEncoding::MP3)
5556
->setEffectsProfileId(array($effectsProfileId));
57+
$request = (new SynthesizeSpeechRequest())
58+
->setInput($inputText)
59+
->setVoice($voice)
60+
->setAudioConfig($audioConfig);
5661

57-
$response = $client->synthesizeSpeech($inputText, $voice, $audioConfig);
62+
$response = $client->synthesizeSpeech($request);
5863
$audioContent = $response->getAudioContent();
5964

6065
file_put_contents('output.mp3', $audioContent);

texttospeech/src/synthesize_text_effects_profile_file.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
// [START tts_synthesize_text_audio_profile_file]
2727
use Google\Cloud\TextToSpeech\V1\AudioConfig;
2828
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
29+
use Google\Cloud\TextToSpeech\V1\Client\TextToSpeechClient;
2930
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
3031
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
31-
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
32+
use Google\Cloud\TextToSpeech\V1\SynthesizeSpeechRequest;
3233
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
3334

3435
/**
@@ -54,8 +55,12 @@ function synthesize_text_effects_profile_file(string $path, string $effectsProfi
5455
$audioConfig = (new AudioConfig())
5556
->setAudioEncoding(AudioEncoding::MP3)
5657
->setEffectsProfileId(array($effectsProfileId));
58+
$request = (new SynthesizeSpeechRequest())
59+
->setInput($inputText)
60+
->setVoice($voice)
61+
->setAudioConfig($audioConfig);
5762

58-
$response = $client->synthesizeSpeech($inputText, $voice, $audioConfig);
63+
$response = $client->synthesizeSpeech($request);
5964
$audioContent = $response->getAudioContent();
6065

6166
file_put_contents('output.mp3', $audioContent);

texttospeech/src/synthesize_text_file.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
// [START tts_synthesize_text_file]
2727
use Google\Cloud\TextToSpeech\V1\AudioConfig;
2828
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
29+
use Google\Cloud\TextToSpeech\V1\Client\TextToSpeechClient;
2930
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
3031
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
31-
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
32+
use Google\Cloud\TextToSpeech\V1\SynthesizeSpeechRequest;
3233
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
3334

3435
/**
@@ -52,8 +53,12 @@ function synthesize_text_file(string $path): void
5253

5354
$audioConfig = (new AudioConfig())
5455
->setAudioEncoding(AudioEncoding::MP3);
56+
$request = (new SynthesizeSpeechRequest())
57+
->setInput($input_text)
58+
->setVoice($voice)
59+
->setAudioConfig($audioConfig);
5560

56-
$response = $client->synthesizeSpeech($input_text, $voice, $audioConfig);
61+
$response = $client->synthesizeSpeech($request);
5762
$audioContent = $response->getAudioContent();
5863

5964
file_put_contents('output.mp3', $audioContent);

0 commit comments

Comments
 (0)