Skip to content
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

migrate code from googleapis/java-texttospeech #7423

Merged
merged 108 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
3162416
samples: Adding TTS Beta samples : Audio profile (#1152)
nirupa-kumar Jul 20, 2018
f3e156a
samples: TTS region tag update (#1190)
alixhami Aug 21, 2018
dbfcdcd
samples: scaffold pom.xml files (#86)
yoshi-automation Mar 17, 2020
ba98017
chore(deps): update dependency com.google.cloud:libraries-bom to v4.3…
renovate-bot Mar 23, 2020
2b969db
deps: update dependency com.google.cloud.samples:shared-configuration…
renovate-bot Mar 26, 2020
af40430
samples: update shared config (#2443)
averikitsch Mar 27, 2020
eb3cf8d
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Mar 30, 2020
65adb18
chore(deps): update dependency com.google.cloud:libraries-bom to v4.4…
renovate-bot Apr 1, 2020
7a02623
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 6, 2020
f206d5f
chore(deps): update dependency com.google.cloud:libraries-bom to v4.4…
renovate-bot Apr 6, 2020
6b9b298
chore(deps): update dependency com.google.cloud:libraries-bom to v5 (…
renovate-bot Apr 14, 2020
b3acdd5
chore(deps): update dependency com.google.cloud:libraries-bom to v5.1…
renovate-bot Apr 14, 2020
9a46f61
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 16, 2020
0107693
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 17, 2020
d8c82bb
chore(deps): update dependency com.google.cloud:libraries-bom to v5.2…
renovate-bot Apr 23, 2020
af5452a
chore(deps): update dependency com.google.cloud:libraries-bom to v5.3…
renovate-bot Apr 28, 2020
997b5b1
chore(deps): update dependency com.google.cloud:libraries-bom to v5.4…
renovate-bot May 19, 2020
4919baf
chore(deps): update dependency com.google.cloud:libraries-bom to v5.5…
renovate-bot May 29, 2020
e2850cb
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Jun 10, 2020
203bdbc
chore(deps): update dependency com.google.cloud:libraries-bom to v5.7…
renovate-bot Jun 10, 2020
6fed381
chore(deps): update dependency com.google.cloud:libraries-bom to v6 (…
renovate-bot Jun 16, 2020
15104eb
chore(deps): update dependency com.google.cloud:libraries-bom to v7 (…
renovate-bot Jun 17, 2020
fb445f2
chore(deps): update dependency com.google.cloud:libraries-bom to v7.0…
renovate-bot Jun 22, 2020
e55f373
chore(deps): update dependency com.google.cloud:libraries-bom to v8 (…
renovate-bot Jun 26, 2020
9a89688
Merge remote-tracking branch 'dpe/master' into samples-texttospeech-beta
chingor13 Aug 3, 2020
d4801af
chore(deps): update dependency com.google.cloud:libraries-bom to v8.1…
renovate-bot Aug 7, 2020
9df3b2e
chore(deps): update dependency com.google.cloud:libraries-bom to v9 (…
renovate-bot Aug 14, 2020
bdfd7de
samples: fix dependencies and resources
chingor13 Aug 15, 2020
f4c5c0c
samples: Add Text-To-Speech Beta samples (#1069)
nnegrey Mar 27, 2018
4e60489
samples: Bump samples to ga (#1124)
nnegrey Jun 7, 2018
c317ce6
samples: Revert changes (#1143)
nnegrey Jun 22, 2018
e545997
samples: Update library for texttospeech sample (#1149)
nnegrey Jul 14, 2018
748be1b
samples: Adding TTS Beta samples : Audio profile (#1152)
nirupa-kumar Jul 20, 2018
aaff776
samples: Update Audio Profiles to beta (#1332)
nnegrey Feb 24, 2019
1108fcb
samples: Java samples for SSML Addresses tutorial (#1556)
crowdus Aug 23, 2019
1866d51
samples: Fix region tag (#1583)
nnegrey Sep 16, 2019
06c042d
samples: Lint fix (#1594)
nnegrey Oct 1, 2019
00449b5
samples: Removed unused dependencies (#1607)
nnegrey Oct 9, 2019
cdd66e8
samples: update shared config (#2443)
averikitsch Mar 27, 2020
cc651fe
Merge branch 'master' into samples-texttospeech-beta
chingor13 Aug 17, 2020
eb2b4b5
chore(deps): update dependency com.google.cloud:libraries-bom to v9.1…
renovate-bot Aug 17, 2020
4ba36d1
samples: add presubmit lint check (#216)
yoshi-automation Aug 27, 2020
d2319f6
chore(deps): update dependency com.google.cloud:libraries-bom to v10 …
renovate-bot Sep 14, 2020
b37b021
chore(deps): update dependency com.google.cloud:libraries-bom to v11 …
renovate-bot Sep 24, 2020
9206205
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Oct 2, 2020
7ccc936
chore(deps): update dependency com.google.cloud:libraries-bom to v12 …
renovate-bot Oct 6, 2020
efce515
test(deps): update dependency junit:junit to v4.13.1
renovate-bot Oct 12, 2020
69b8162
chore(deps): update dependency com.google.cloud:libraries-bom to v12.…
renovate-bot Oct 15, 2020
be3e3aa
chore(deps): update dependency com.google.cloud:libraries-bom to v13 …
renovate-bot Oct 20, 2020
8ef2c08
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 21, 2020
52cf765
test(deps): update dependency com.google.truth:truth to v1.1 (#266)
renovate-bot Oct 22, 2020
315e7e7
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 23, 2020
75d183e
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 26, 2020
3f19cf6
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot Oct 30, 2020
941e92f
chore(deps): update dependency com.google.cloud:libraries-bom to v14 …
renovate-bot Nov 4, 2020
336f2c3
chore(deps): update dependency com.google.cloud:libraries-bom to v15 …
renovate-bot Nov 5, 2020
6f6e81c
chore: added missing region tag in pom.xml (#294)
munkhuushmgl Nov 10, 2020
511fe03
chore(deps): update dependency com.google.cloud:libraries-bom to v16 …
renovate-bot Nov 19, 2020
1422924
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Dec 15, 2020
84d2a43
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Jan 7, 2021
b611042
test(deps): update dependency com.google.truth:truth to v1.1.2 (#349)
renovate-bot Jan 25, 2021
cfc5dc7
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot Feb 2, 2021
95fcb88
test(deps): update dependency junit:junit to v4.13.2 (#368)
renovate-bot Feb 16, 2021
4d6dcc1
chore(deps): update dependency com.google.cloud:libraries-bom to v17 …
renovate-bot Feb 24, 2021
5bcef2c
chore(deps): update dependency com.google.cloud:libraries-bom to v18 …
renovate-bot Feb 25, 2021
996e2e7
chore(deps): update dependency com.google.cloud:libraries-bom to v18.…
renovate-bot Mar 3, 2021
e19a615
chore(deps): update dependency com.google.cloud:libraries-bom to v19 …
renovate-bot Mar 4, 2021
6a3ec42
chore(deps): update dependency com.google.cloud:libraries-bom to v19.…
renovate-bot Mar 17, 2021
c77d6c6
chore(deps): update dependency com.google.cloud:libraries-bom to v19.…
renovate-bot Mar 19, 2021
3f839ea
chore(deps): update dependency com.google.cloud:libraries-bom to v20 …
renovate-bot Apr 12, 2021
1743477
deps: update dependency net.sourceforge.argparse4j:argparse4j to v0.9…
renovate-bot Apr 12, 2021
a0310fb
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Apr 12, 2021
260281b
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Apr 19, 2021
26de4d1
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Apr 29, 2021
7fd8e80
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot May 13, 2021
83b9a9f
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot May 17, 2021
a610095
test(deps): update dependency com.google.truth:truth to v1.1.3 (#469)
renovate-bot May 26, 2021
cf58bc1
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot May 26, 2021
f49faed
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Jun 7, 2021
efdbca9
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jun 7, 2021
17de7cd
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jul 5, 2021
d69e4d0
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jul 9, 2021
2b73eec
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot Jul 27, 2021
931c4de
chore(deps): update dependency com.google.cloud:libraries-bom to v21 …
renovate-bot Aug 17, 2021
19aa36d
chore(deps): update dependency com.google.cloud:libraries-bom to v22 …
renovate-bot Aug 27, 2021
8748265
chore(deps): update dependency com.google.cloud:libraries-bom to v23 …
renovate-bot Sep 13, 2021
853445b
chore(deps): update dependency com.google.cloud:libraries-bom to v23.…
renovate-bot Oct 1, 2021
50f4de7
chore(deps): update dependency com.google.cloud:libraries-bom to v24 …
renovate-bot Oct 27, 2021
d54bd34
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot Dec 6, 2021
2fa9a23
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Dec 8, 2021
b8d814f
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Dec 28, 2021
14f3606
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Jan 7, 2022
fce6459
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Jan 12, 2022
69c45a5
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Feb 8, 2022
62da87b
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Mar 3, 2022
225c7e0
chore(deps): update dependency com.google.cloud:libraries-bom to v25 …
renovate-bot Mar 14, 2022
0a44fd9
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Apr 1, 2022
87ee655
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Apr 27, 2022
9a30783
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot May 16, 2022
20a6cfe
chore(deps): update dependency com.google.cloud:libraries-bom to v26 …
renovate-bot Jul 11, 2022
8bdad56
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Aug 16, 2022
78d5177
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Aug 31, 2022
ff96a55
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Sep 20, 2022
ae856b4
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Oct 7, 2022
1f2a041
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Nov 8, 2022
9f3cdbd
Merge remote-tracking branch 'migration/main' into java-texttospeech-…
charlieyu1996 Nov 15, 2022
c091c17
Update pom.xml
charlieyu1996 Nov 15, 2022
a304534
Update pom.xml
charlieyu1996 Nov 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions texttospeech/snippets/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version='1.0' encoding='UTF-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.texttospeech</groupId>
<artifactId>texttospeech-snippets</artifactId>
<packaging>jar</packaging>
<name>Google Cloud Text-to-Speech Snippets</name>
<url>https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/texttospeech</url>

<!--
The parent pom defines common style checks and testing strategies for our samples.
Removing or replacing it should not affect the execution of the samples in anyway.
-->
<parent>
<groupId>com.google.cloud.samples</groupId>
<artifactId>shared-configuration</artifactId>
<version>1.2.0</version>
</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>

<!-- [START tts_java_dependencies] -->
<!-- [START tts_install_with_bom] -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.1.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-texttospeech</artifactId>
</dependency>
<!-- [END tts_java_dependencies] -->
<!-- [START_EXCLUDE] -->
<dependency>
<groupId>net.sourceforge.argparse4j</groupId>
<artifactId>argparse4j</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.1.3</version>
<scope>test</scope>
</dependency>
<!-- [END_EXCLUDE] -->
<!-- [START tts_java_dependencies] -->
</dependencies>
<!-- [END tts_java_dependencies] -->
<!-- [END tts_install_with_bom] -->
</project>
4 changes: 4 additions & 0 deletions texttospeech/snippets/resources/example.ssml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<speak>123 Street Ln, Small Town, IL 12345 USA
<break time='2s'/>1 Jenny St &amp; Number St, Tutone City, CA 86753
<break time='2s'/>1 Piazza del Fibonacci, 12358 Pisa, Italy
<break time='2s'/></speak>
3 changes: 3 additions & 0 deletions texttospeech/snippets/resources/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
123 Street Ln, Small Town, IL 12345 USA
1 Jenny St & Number St, Tutone City, CA 86753
1 Piazza del Fibonacci, 12358 Pisa, Italy
Binary file not shown.
1 change: 1 addition & 0 deletions texttospeech/snippets/resources/hello.ssml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<speak>Hello there.</speak>
1 change: 1 addition & 0 deletions texttospeech/snippets/resources/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello there!
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.v1.ListVoicesRequest;
import com.google.cloud.texttospeech.v1.ListVoicesResponse;
import com.google.cloud.texttospeech.v1.TextToSpeechClient;
import com.google.cloud.texttospeech.v1.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 List<Voice> 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());
}
return voices;
}
}
// [END tts_list_voices]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.ListAllSupportedVoicesBeta'
*/
public class ListAllSupportedVoicesBeta {

// [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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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;

// [START tts_quickstart]
// Imports the Google Cloud client library
import com.google.cloud.texttospeech.v1.AudioConfig;
import com.google.cloud.texttospeech.v1.AudioEncoding;
import com.google.cloud.texttospeech.v1.SsmlVoiceGender;
import com.google.cloud.texttospeech.v1.SynthesisInput;
import com.google.cloud.texttospeech.v1.SynthesizeSpeechResponse;
import com.google.cloud.texttospeech.v1.TextToSpeechClient;
import com.google.cloud.texttospeech.v1.VoiceSelectionParams;
import com.google.protobuf.ByteString;
import java.io.FileOutputStream;
import java.io.OutputStream;

/**
* Google Cloud TextToSpeech API sample application. Example usage: mvn package exec:java
* -Dexec.mainClass='com.example.texttospeech.QuickstartSample'
*/
public class QuickstartSample {

/** Demonstrates using the Text-to-Speech API. */
public static void main(String... args) throws Exception {
// Instantiates a client
try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
// Set the text input to be synthesized
SynthesisInput input = SynthesisInput.newBuilder().setText("Hello, World!").build();

// Build the voice request, select the language code ("en-US") and the ssml voice gender
// ("neutral")
VoiceSelectionParams voice =
VoiceSelectionParams.newBuilder()
.setLanguageCode("en-US")
.setSsmlGender(SsmlVoiceGender.NEUTRAL)
.build();

// Select the type of audio file you want returned
AudioConfig audioConfig =
AudioConfig.newBuilder().setAudioEncoding(AudioEncoding.MP3).build();

// Perform the text-to-speech request on the text input with the selected voice parameters and
// audio file type
SynthesizeSpeechResponse response =
textToSpeechClient.synthesizeSpeech(input, voice, audioConfig);

// Get the audio contents from the response
ByteString audioContents = response.getAudioContent();

// Write the response to the output file.
try (OutputStream out = new FileOutputStream("output.mp3")) {
out.write(audioContents.toByteArray());
System.out.println("Audio content written to file \"output.mp3\"");
}
}
}
}
// [END tts_quickstart]
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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;

// [START tts_quickstart]
// Imports the Google Cloud client library
import com.google.cloud.texttospeech.v1beta1.AudioConfig;
import com.google.cloud.texttospeech.v1beta1.AudioEncoding;
import com.google.cloud.texttospeech.v1beta1.SsmlVoiceGender;
import com.google.cloud.texttospeech.v1beta1.SynthesisInput;
import com.google.cloud.texttospeech.v1beta1.SynthesizeSpeechResponse;
import com.google.cloud.texttospeech.v1beta1.TextToSpeechClient;
import com.google.cloud.texttospeech.v1beta1.VoiceSelectionParams;
import com.google.protobuf.ByteString;
import java.io.FileOutputStream;
import java.io.OutputStream;

/**
* Google Cloud TextToSpeech API sample application. Example usage: mvn package exec:java
* -Dexec.mainClass='com.example.texttospeech.QuickstartSampleBeta'
*/
public class QuickstartSampleBeta {

/** Demonstrates using the Text-to-Speech API. */
public static void main(String... args) throws Exception {
// Instantiates a client
try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
// Set the text input to be synthesized
SynthesisInput input = SynthesisInput.newBuilder().setText("Hello, World!").build();

// Build the voice request, select the language code ("en-US") and the ssml voice gender
// ("neutral")
VoiceSelectionParams voice =
VoiceSelectionParams.newBuilder()
.setLanguageCode("en-US")
.setSsmlGender(SsmlVoiceGender.NEUTRAL)
.build();

// Select the type of audio file you want returned
AudioConfig audioConfig =
AudioConfig.newBuilder().setAudioEncoding(AudioEncoding.MP3).build();

// Perform the text-to-speech request on the text input with the selected voice parameters and
// audio file type
SynthesizeSpeechResponse response =
textToSpeechClient.synthesizeSpeech(input, voice, audioConfig);

// Get the audio contents from the response
ByteString audioContents = response.getAudioContent();

// Write the response to the output file.
try (OutputStream out = new FileOutputStream("output.mp3")) {
out.write(audioContents.toByteArray());
System.out.println("Audio content written to file \"output.mp3\"");
}
}
}
}
// [END tts_quickstart]
Loading