-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding TTS Beta samples : Audio profile (#1152)
* Adding TTS Beta samples : Audio profile * Updated based on comments : Adding TTS Beta samples - Audio profile * Updated based on comments : TTS Beta samples - Audio profile * Updated based on comments : TTS Beta samples - Audio profile * Updates after review * Updates after review * Updates after review : Please let this be the last one :) * Update to released client library * Update SynthesizeText.java Need to update the verification script to allow LLC. * Update SynthesizeText.java Need to update the verification script to allow LLC.
- Loading branch information
1 parent
cd9fe5b
commit 3f9af3c
Showing
13 changed files
with
1,064 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Google Cloud Text-To-Speech API Java examples | ||
|
||
The [Cloud Text To Speech API][texttospeech] enables you to generate and | ||
customize synthesized speech from text or SSML. | ||
|
||
These samples show how to list all supported voices, synthesize raw | ||
text, and synthesize a file. | ||
|
||
[texttospeech]: https://cloud.google.com/text-to-speech/ | ||
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java | ||
|
||
## Prerequisites | ||
|
||
### Download Maven | ||
|
||
To get started, [download][maven-download] and [install][maven-install] it. | ||
|
||
[maven]: https://maven.apache.org | ||
[maven-download]: https://maven.apache.org/download.cgi | ||
[maven-install]: https://maven.apache.org/install.html | ||
|
||
### Setup | ||
|
||
* Create a project with the [Google Cloud Console][cloud-console], and enable | ||
the [TextToSpeech API][text-to-speech-api]. | ||
* [Set up][auth] authentication. For | ||
example, from the Cloud Console, create a service account, | ||
download its json credentials file, then set the appropriate environment | ||
variable: | ||
|
||
```bash | ||
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json | ||
``` | ||
* Build the samples | ||
``` | ||
mvn clean package | ||
``` | ||
|
||
[cloud-console]: https://console.cloud.google.com | ||
[text-to-speech-api]: https://console.cloud.google.com/apis/api/texttospeech.googleapis.com/overview?project=_ | ||
[auth]: https://cloud.google.com/docs/authentication/getting-started | ||
|
||
## Quckstart | ||
Synthesize text to an output audio file. [Java Code](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/texttospeech/cloud-client/src/main/java/com/example/texttospeech/QuickstartSample.java) | ||
``` | ||
mvn exec:java -DQuickstart | ||
``` | ||
## List Voices | ||
This sample lists all the supported voices. [Java Code](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/texttospeech/cloud-client/src/main/java/com/example/texttospeech/ListAllSupportedVoices.java) | ||
``` | ||
mvn exec:java -DListVoices | ||
``` | ||
## Synthesize Text | ||
This sample synthesizes text to an output audio file. [Java Code](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/texttospeech/cloud-client/src/main/java/com/example/texttospeech/SynthesizeText.java) | ||
``` | ||
mvn exec:java -DSynthesizeText -Dexec.args='--text "hello"' | ||
``` | ||
This sample synthesizes text with an audio profile to an output audio file. [Java Code](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/texttospeech/cloud-client/src/main/java/com/example/texttospeech/SynthesizeText.java) | ||
``` | ||
mvn exec:java -DSynthesizeText -Dexec.args='--text "hello" "telephony-class-application"' | ||
``` | ||
This sample synthesizes ssml to an output audio file. [Java Code](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/texttospeech/cloud-client/src/main/java/com/example/texttospeech/SynthesizeText.java) | ||
``` | ||
mvn exec:java -DSynthesizeText -Dexec.args='--ssml "<speak>Hello there.</speak>"' | ||
``` | ||
## Synthesize File | ||
This sample synthesizes a text file to an output audio file. [Java Code](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/texttospeech/cloud-client/src/main/java/com/example/texttospeech/SynthesizeFile.java) | ||
``` | ||
mvn exec:java -DSynthesizeFile -Dexec.args='--text resources/hello.txt' | ||
``` | ||
This sample synthesizes a ssml file to an output audio file. [Java Code](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/texttospeech/cloud-client/src/main/java/com/example/texttospeech/SynthesizeFile.java) | ||
``` | ||
mvn exec:java -DSynthesizeFile -Dexec.args='--ssml resources/hello.ssml' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
<!-- | ||
Copyright 2018, Google LLC. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.example.texttospeech</groupId> | ||
<artifactId>tts-samples</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<!-- Parent defines config for testing & linting. --> | ||
<parent> | ||
<artifactId>doc-samples</artifactId> | ||
<groupId>com.google.cloud</groupId> | ||
<version>1.0.0</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
|
||
<properties> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- [START dependencies] --> | ||
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-texttospeech</artifactId> | ||
<version>0.55.0-beta</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.sourceforge.argparse4j</groupId> | ||
<artifactId>argparse4j</artifactId> | ||
<version>0.8.1</version> | ||
</dependency> | ||
<!-- [END dependencies] --> | ||
|
||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.truth</groupId> | ||
<artifactId>truth</artifactId> | ||
<version>0.41</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
<profiles> | ||
<!--Quickstart--> | ||
<profile> | ||
<id>Quickstart</id> | ||
<activation> | ||
<property> | ||
<name>Quickstart</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<mainClass>com.example.texttospeech.QuickstartSample</mainClass> | ||
<cleanupDaemonThreads>false</cleanupDaemonThreads> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
|
||
<!--ListVoices--> | ||
<profile> | ||
<id>ListVoices</id> | ||
<activation> | ||
<property> | ||
<name>ListVoices</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<mainClass>com.example.texttospeech.ListAllSupportedVoices</mainClass> | ||
<cleanupDaemonThreads>false</cleanupDaemonThreads> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
|
||
<!--SynthesizeFile--> | ||
<profile> | ||
<id>SynthesizeFile</id> | ||
<activation> | ||
<property> | ||
<name>SynthesizeFile</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<mainClass>com.example.texttospeech.SynthesizeFile</mainClass> | ||
<cleanupDaemonThreads>false</cleanupDaemonThreads> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
|
||
<!--SynthesizeText--> | ||
<profile> | ||
<id>SynthesizeText</id> | ||
<activation> | ||
<property> | ||
<name>SynthesizeText</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<mainClass>com.example.texttospeech.SynthesizeText</mainClass> | ||
<cleanupDaemonThreads>false</cleanupDaemonThreads> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<speak>Hello there.</speak> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello there! |
75 changes: 75 additions & 0 deletions
75
texttospeech/beta/src/main/java/com/example/texttospeech/ListAllSupportedVoices.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2018 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.texttospeech; | ||
|
||
// Imports the Google Cloud client library | ||
import com.google.cloud.texttospeech.v1beta1.ListVoicesRequest; | ||
import com.google.cloud.texttospeech.v1beta1.ListVoicesResponse; | ||
import com.google.cloud.texttospeech.v1beta1.TextToSpeechClient; | ||
import com.google.cloud.texttospeech.v1beta1.Voice; | ||
import com.google.protobuf.ByteString; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* Google Cloud TextToSpeech API sample application. | ||
* Example usage: mvn package exec:java | ||
* -Dexec.mainClass='com.example.texttospeech.ListAllSupportedVoices' | ||
*/ | ||
public class ListAllSupportedVoices { | ||
|
||
// [START tts_list_voices] | ||
/** | ||
* Demonstrates using the Text to Speech client to list the client's supported voices. | ||
* @throws Exception on TextToSpeechClient Errors. | ||
*/ | ||
public static void listAllSupportedVoices() throws Exception { | ||
// Instantiates a client | ||
try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) { | ||
// Builds the text to speech list voices request | ||
ListVoicesRequest request = ListVoicesRequest.getDefaultInstance(); | ||
|
||
// Performs the list voices request | ||
ListVoicesResponse response = textToSpeechClient.listVoices(request); | ||
List<Voice> voices = response.getVoicesList(); | ||
|
||
for (Voice voice : voices) { | ||
// Display the voice's name. Example: tpc-vocoded | ||
System.out.format("Name: %s\n", voice.getName()); | ||
|
||
// Display the supported language codes for this voice. Example: "en-us" | ||
List<ByteString> languageCodes = voice.getLanguageCodesList().asByteStringList(); | ||
for (ByteString languageCode : languageCodes) { | ||
System.out.format("Supported Language: %s\n", languageCode.toStringUtf8()); | ||
} | ||
|
||
// Display the SSML Voice Gender | ||
System.out.format("SSML Voice Gender: %s\n", voice.getSsmlGender()); | ||
|
||
// Display the natural sample rate hertz for this voice. Example: 24000 | ||
System.out.format("Natural Sample Rate Hertz: %s\n\n", | ||
voice.getNaturalSampleRateHertz()); | ||
} | ||
} | ||
} | ||
// [END tts_list_voices] | ||
|
||
public static void main(String[] args) throws Exception { | ||
listAllSupportedVoices(); | ||
} | ||
} |
Oops, something went wrong.