diff --git a/texttospeech/README.md b/texttospeech/README.md
index e864ff59f5..382b0dd940 100644
--- a/texttospeech/README.md
+++ b/texttospeech/README.md
@@ -41,8 +41,10 @@ Usage:
Examples:
php texttospeech.php synthesize-text -h
php texttospeech.php synthesize-ssml -h
+ php texttospeech.php synthesize-text-audio-profile -h
php texttospeech.php synthesize-text "Hello there."
php texttospeech.php synthesize-ssml "Hello there."
+ php texttospeech.php synthesize-text-effects-profile "Hello there." "handset-class-device"
```
### Synthesize file
@@ -50,12 +52,15 @@ Examples:
Usage:
php texttospeech.php synthesize-text-file
php texttospeech.php synthesize-ssml-file
-
+ php texttospeech.php synthesize-text-effects-profile-file
+
Examples:
php texttospeech.php synthesize-text-file -h
php texttospeech.php synthesize-ssml-file -h
+ php texttospeech.php synthesize-text-audio-profile-file -h
php texttospeech.php synthesize-text-file resources/hello.txt
php texttospeech.php synthesize-ssml-file resources/hello.ssml
+ php texttospeech.php synthesize-text-effects-profile-file resources/hello.txt "handset-class-device"
```
## The client library
diff --git a/texttospeech/composer.json b/texttospeech/composer.json
index 70dd8bfd66..08b6514a47 100644
--- a/texttospeech/composer.json
+++ b/texttospeech/composer.json
@@ -1,6 +1,6 @@
{
"require": {
- "google/cloud-text-to-speech": "^0.1",
+ "google/cloud-text-to-speech": "^0.2.1",
"symfony/console": "^3.0"
},
"require-dev": {
@@ -12,7 +12,9 @@
"src/synthesize_ssml.php",
"src/synthesize_ssml_file.php",
"src/synthesize_text.php",
- "src/synthesize_text_file.php"
+ "src/synthesize_text_file.php",
+ "src/synthesize_text_effects_profile.php",
+ "src/synthesize_text_effects_profile_file.php"
]
}
}
diff --git a/texttospeech/quickstart.php b/texttospeech/quickstart.php
index 3f3fc8f83b..dfbae379ee 100644
--- a/texttospeech/quickstart.php
+++ b/texttospeech/quickstart.php
@@ -31,7 +31,7 @@
$client = new TextToSpeechClient();
// sets text to be synthesised
-$synthesis_input = (new SynthesisInput())
+$synthesisInputText = (new SynthesisInput())
->setText('Hello, world!');
// build the voice request, select the language code ("en-US") and the ssml
@@ -40,13 +40,17 @@
->setLanguageCode('en-US')
->setSsmlGender(SsmlVoiceGender::FEMALE);
+// Effects profile
+$effectsProfileId = "telephony-class-application";
+
// select the type of audio file you want returned
$audioConfig = (new AudioConfig())
- ->setAudioEncoding(AudioEncoding::MP3);
+ ->setAudioEncoding(AudioEncoding::MP3)
+ ->setEffectsProfileId(array($effectsProfileId));
// perform text-to-speech request on the text input with selected voice
// parameters and audio file type
-$response = $client->synthesizeSpeech($synthesis_input, $voice, $audioConfig);
+$response = $client->synthesizeSpeech($synthesisInputText, $voice, $audioConfig);
$audioContent = $response->getAudioContent();
// the response's audioContent is binary
diff --git a/texttospeech/src/synthesize_text_effects_profile.php b/texttospeech/src/synthesize_text_effects_profile.php
new file mode 100644
index 0000000000..b732aab92e
--- /dev/null
+++ b/texttospeech/src/synthesize_text_effects_profile.php
@@ -0,0 +1,55 @@
+setText($text);
+
+ // note: the voice can also be specified by name
+ // names of voices can be retrieved with $client->listVoices()
+ $voice = (new VoiceSelectionParams())
+ ->setLanguageCode('en-US')
+ ->setSsmlGender(SsmlVoiceGender::FEMALE);
+
+ // define effects profile id.
+ $audioConfig = (new AudioConfig())
+ ->setAudioEncoding(AudioEncoding::MP3)
+ ->setEffectsProfileId(array($effectsProfileId));
+
+ $response = $client->synthesizeSpeech($inputText, $voice, $audioConfig);
+ $audioContent = $response->getAudioContent();
+
+ file_put_contents('output.mp3', $audioContent);
+ print('Audio content written to "output.mp3"' . PHP_EOL);
+
+ $client->close();
+}
+// [END tts_synthesize_text_audio_profile]
diff --git a/texttospeech/src/synthesize_text_effects_profile_file.php b/texttospeech/src/synthesize_text_effects_profile_file.php
new file mode 100644
index 0000000000..12359ef01c
--- /dev/null
+++ b/texttospeech/src/synthesize_text_effects_profile_file.php
@@ -0,0 +1,56 @@
+setText($text);
+
+ // note: the voice can also be specified by name
+ // names of voices can be retrieved with $client->listVoices()
+ $voice = (new VoiceSelectionParams())
+ ->setLanguageCode('en-US')
+ ->setSsmlGender(SsmlVoiceGender::FEMALE);
+
+ $audioConfig = (new AudioConfig())
+ ->setAudioEncoding(AudioEncoding::MP3)
+ ->setEffectsProfileId(array($effectsProfileId));
+
+ $response = $client->synthesizeSpeech($inputText, $voice, $audioConfig);
+ $audioContent = $response->getAudioContent();
+
+ file_put_contents('output.mp3', $audioContent);
+ print('Audio content written to "output.mp3"' . PHP_EOL);
+
+ $client->close();
+}
+// [END tts_synthesize_text_audio_profile_file]
diff --git a/texttospeech/test/textToSpeechTest.php b/texttospeech/test/textToSpeechTest.php
index 0ceb58953c..cc94e180aa 100644
--- a/texttospeech/test/textToSpeechTest.php
+++ b/texttospeech/test/textToSpeechTest.php
@@ -54,6 +54,16 @@ public function testSynthesizeText()
$this->assertGreaterThan(0,filesize('output.mp3'));
unlink('output.mp3');
}
+ public function testSynthesizeTextEffectsProfile()
+ {
+ $output = $this->runCommand('synthesize-text-effects-profile', [
+ 'text' => 'hello there',
+ 'effects_profile_id' => 'telephony-class-application'
+ ]);
+ $this->assertContains('Audio content written to', $output);
+ $this->assertGreaterThan(0,filesize('output.mp3'));
+ unlink('output.mp3');
+ }
public function testSynthesizeSsmlFile()
{
$path = __DIR__ . '/../resources/hello.ssml';
@@ -74,6 +84,17 @@ public function testSynthesizeTextFile()
$this->assertGreaterThan(0,filesize('output.mp3'));
unlink('output.mp3');
}
+ public function testSynthesizeTextEffectsProfileFile()
+ {
+ $path = __DIR__ . '/../resources/hello.txt';
+ $output = $this->runCommand('synthesize-text-effects-profile-file', [
+ 'path' => $path,
+ 'effects_profile_id' => 'telephony-class-application'
+ ]);
+ $this->assertContains('Audio content written to', $output);
+ $this->assertGreaterThan(0,filesize('output.mp3'));
+ unlink('output.mp3');
+ }
private function runCommand($commandName, array $args = [])
{
$application = require __DIR__ . '/../texttospeech.php';
diff --git a/texttospeech/texttospeech.php b/texttospeech/texttospeech.php
index 3689c05d6b..2a66fa8d10 100644
--- a/texttospeech/texttospeech.php
+++ b/texttospeech/texttospeech.php
@@ -28,12 +28,26 @@
$inputDefinition = new InputDefinition([
new InputArgument('text', InputArgument::REQUIRED,
'Text/SSML to synthesize.')
+
+]);
+
+$inputDefinitionEffectsProfile = new InputDefinition([
+ new InputArgument('text', InputArgument::REQUIRED,
+ 'Text/SSML to synthesize.'),
+ new InputArgument('effects_profile_id', InputArgument::REQUIRED,
+ 'Audio Profile.')
]);
$inputDefinitionFile = new InputDefinition([
new InputArgument('path', InputArgument::REQUIRED, 'File to synthesize.')
]);
+$inputDefinitionEffectsProfileFile = new InputDefinition([
+ new InputArgument('path', InputArgument::REQUIRED, 'File to synthesize.'),
+ new InputArgument('effects_profile_id', InputArgument::REQUIRED,
+ 'Audio Profile.')
+]);
+
$application->add(new Command('list-voices'))
->setDescription('List the available voices')
@@ -78,6 +92,22 @@
})
);
+$application->add((new Command('synthesize-text-effects-profile'))
+ ->setDefinition($inputDefinitionEffectsProfile)
+ ->setDescription('Synthesizes speech from the input string of text using Audio Profiles')
+ ->setHelp(<<%command.name% command synthesizes speech from the input string
+of text using Google Cloud Text-to-Speech API using Audio Profiles.
+ php %command.full_name% "hello there" "wearable-class-device"
+EOF
+ )
+ ->setCode(function ($input) {
+ $text = $input->getArgument('text');
+ $effectsProfileId = $input->getArgument('effects_profile_id');
+ synthesize_text_effects_profile($text, $effectsProfileId);
+ })
+);
+
$application->add((new Command('synthesize-ssml-file'))
->setDefinition($inputDefinitionFile)
->setDescription('Synthesizes speech from the input file of ssml')
@@ -108,6 +138,22 @@
})
);
+$application->add((new Command('synthesize-text-effects-profile-file'))
+ ->setDefinition($inputDefinitionEffectsProfileFile)
+ ->setDescription('Synthesizes speech from the input file of text using Audio Profiles')
+ ->setHelp(<<%command.name% command synthesizes speech from the input file
+of text using Google Cloud Text-to-Speech API using Audio Profiles.
+ php %command.full_name% path/to/file.txt "wearable-class-device"
+EOF
+ )
+ ->setCode(function ($input) {
+ $path = $input->getArgument('path');
+ $effectsProfileId = $input->getArgument('effects_profile_id');
+ synthesize_text_effects_profile_file($path, $effectsProfileId);
+ })
+);
+
// for testing
if (getenv('PHPUNIT_TESTS') === '1') {
return $application;