-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding TTS Beta samples : Audio profile #1152
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
659d146
Adding TTS Beta samples : Audio profile
nirupa-kumar 6c81453
Updated based on comments : Adding TTS Beta samples - Audio profile
nirupa-kumar 9959361
Updated based on comments : TTS Beta samples - Audio profile
nirupa-kumar 18d679d
Updated based on comments : TTS Beta samples - Audio profile
nirupa-kumar 9c0ca8a
Merge branch 'master' of https://github.com/GoogleCloudPlatform/java-…
nirupa-kumar 7c1ddae
Updates after review
nirupa-kumar c4d8ec0
Merge branch 'master' of https://github.com/GoogleCloudPlatform/java-…
nirupa-kumar 3b92678
Updates after review
nirupa-kumar ffe276e
Updates after review : Please let this be the last one :)
nirupa-kumar e1292ad
Update to released client library
nirupa-kumar f412b1f
Update SynthesizeText.java
nnegrey 88f53cf
Update SynthesizeText.java
nnegrey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.53.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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: new line