diff --git a/texttospeech/beta/README.md b/texttospeech/beta/README.md deleted file mode 100644 index 4ac4aeb7790..00000000000 --- a/texttospeech/beta/README.md +++ /dev/null @@ -1,78 +0,0 @@ -# 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/main/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/main/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/main/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/main/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/main/texttospeech/cloud-client/src/main/java/com/example/texttospeech/SynthesizeText.java) -``` -mvn exec:java -DSynthesizeText -Dexec.args='--ssml "Hello there."' -``` - -## Synthesize File -This sample synthesizes a text file to an output audio file. [Java Code](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/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/main/texttospeech/cloud-client/src/main/java/com/example/texttospeech/SynthesizeFile.java) -``` -mvn exec:java -DSynthesizeFile -Dexec.args='--ssml resources/hello.ssml' -``` diff --git a/texttospeech/beta/pom.xml b/texttospeech/beta/pom.xml deleted file mode 100644 index d726cff2c3f..00000000000 --- a/texttospeech/beta/pom.xml +++ /dev/null @@ -1,202 +0,0 @@ - - - 4.0.0 - com.example.texttospeech - tts-samples - jar - - - - com.google.cloud.samples - shared-configuration - 1.2.0 - - - - 1.8 - 1.8 - UTF-8 - - - - - - - - com.google.cloud - libraries-bom - 26.32.0 - pom - import - - - - - - - com.google.cloud - google-cloud-texttospeech - - - net.sourceforge.argparse4j - argparse4j - 0.9.0 - - - - - - junit - junit - 4.13.2 - test - - - com.google.truth - truth - 1.4.0 - test - - - - - - - - - - Quickstart - - - Quickstart - - - - - - org.codehaus.mojo - exec-maven-plugin - 3.1.1 - - - - java - - - - - com.example.texttospeech.QuickstartSample - false - - - - - - - - - ListVoices - - - ListVoices - - - - - - org.codehaus.mojo - exec-maven-plugin - 3.1.1 - - - - java - - - - - com.example.texttospeech.ListAllSupportedVoices - false - - - - - - - - - SynthesizeFile - - - SynthesizeFile - - - - - - org.codehaus.mojo - exec-maven-plugin - 3.1.1 - - - - java - - - - - com.example.texttospeech.SynthesizeFile - false - - - - - - - - - SynthesizeText - - - SynthesizeText - - - - - - org.codehaus.mojo - exec-maven-plugin - 3.1.1 - - - - java - - - - - com.example.texttospeech.SynthesizeText - false - - - - - - - diff --git a/texttospeech/beta/resources/hello.ssml b/texttospeech/beta/resources/hello.ssml deleted file mode 100644 index df7bf9eee37..00000000000 --- a/texttospeech/beta/resources/hello.ssml +++ /dev/null @@ -1 +0,0 @@ -Hello there. diff --git a/texttospeech/beta/resources/hello.txt b/texttospeech/beta/resources/hello.txt deleted file mode 100644 index 495cc9fa8f9..00000000000 --- a/texttospeech/beta/resources/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Hello there! diff --git a/texttospeech/beta/src/main/java/com/example/texttospeech/SynthesizeText.java b/texttospeech/beta/src/main/java/com/example/texttospeech/SynthesizeText.java deleted file mode 100644 index 211d8b0cb50..00000000000 --- a/texttospeech/beta/src/main/java/com/example/texttospeech/SynthesizeText.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * 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.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; -import net.sourceforge.argparse4j.ArgumentParsers; -import net.sourceforge.argparse4j.inf.ArgumentParser; -import net.sourceforge.argparse4j.inf.ArgumentParserException; -import net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup; -import net.sourceforge.argparse4j.inf.Namespace; - -/** - * Google Cloud TextToSpeech API sample application. Example usage: mvn package - * exec:java-Dexec.mainClass='com.example.texttospeech.SynthesizeText' -Dexec.args='--text "hello"' - */ -public class SynthesizeText { - - // [START tts_synthesize_text] - /** - * Demonstrates using the Text to Speech client to synthesize text or ssml. - * - * @param text the raw text to be synthesized. (e.g., "Hello there!") - * @throws Exception on TextToSpeechClient Errors. - */ - public static void synthesizeText(String text) throws Exception { - // Instantiates a client - try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) { - // Set the text input to be synthesized - SynthesisInput input = SynthesisInput.newBuilder().setText(text).build(); - - // Build the voice request - VoiceSelectionParams voice = - VoiceSelectionParams.newBuilder() - .setLanguageCode("en-US") // languageCode = "en_us" - .setSsmlGender(SsmlVoiceGender.FEMALE) // ssmlVoiceGender = SsmlVoiceGender.FEMALE - .build(); - - // Select the type of audio file you want returned - AudioConfig audioConfig = - AudioConfig.newBuilder() - .setAudioEncoding(AudioEncoding.MP3) // MP3 audio. - .build(); - - // Perform the text-to-speech request - 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_synthesize_text] - - /** - * Demonstrates using the Text to Speech client with audio profiles to synthesize text or ssml - * - * @param text the raw text to be synthesized. (e.g., "Hello there!") - * @param effectsProfile audio profile to be used for synthesis. (e.g., - * "telephony-class-application") - * @throws Exception on TextToSpeechClient Errors. - */ - public static void synthesizeTextWithAudioProfile(String text, String effectsProfile) - throws Exception { - // Instantiates a client - try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) { - // Set the text input to be synthesized - SynthesisInput input = SynthesisInput.newBuilder().setText(text).build(); - - // Build the voice request - VoiceSelectionParams voice = - VoiceSelectionParams.newBuilder() - .setLanguageCode("en-US") // languageCode = "en_us" - .setSsmlGender(SsmlVoiceGender.FEMALE) // ssmlVoiceGender = SsmlVoiceGender.FEMALE - .build(); - - // Select the type of audio file you want returned and the audio profile - AudioConfig audioConfig = - AudioConfig.newBuilder() - .setAudioEncoding(AudioEncoding.MP3) // MP3 audio. - .addEffectsProfileId(effectsProfile) // audio profile - .build(); - - // Perform the text-to-speech request - 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\""); - } - } - } - - // [START tts_synthesize_ssml] - /** - * Demonstrates using the Text to Speech client to synthesize text or ssml. - * - *

Note: ssml must be well-formed according to: (https://www.w3.org/TR/speech-synthesis/ - * Example: Hello there. - * - * @param ssml the ssml document to be synthesized. (e.g., "Hello there."; - private static String EFFECTSPROFILE = "telephony-class-application"; - - private ByteArrayOutputStream bout; - private PrintStream out; - private File outputFile; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - System.setOut(out); - } - - @After - public void tearDown() { - outputFile.delete(); - } - - @Test - public void testSynthesizeText() throws Exception { - // Act - SynthesizeText.synthesizeText(TEXT); - - // Assert - outputFile = new File(OUTPUT); - assertThat(outputFile.isFile()).isTrue(); - String got = bout.toString(); - assertThat(got).contains("Audio content written to file \"output.mp3\""); - } - - @Test - public void testSynthesizeSsml() throws Exception { - // Act - SynthesizeText.synthesizeSsml(SSML); - - // Assert - outputFile = new File(OUTPUT); - assertThat(outputFile.isFile()).isTrue(); - String got = bout.toString(); - assertThat(got).contains("Audio content written to file \"output.mp3\""); - } - - @Test - public void testSynthesizeTextWithAudioProfile() throws Exception { - // Act - SynthesizeText.synthesizeTextWithAudioProfile(TEXT, EFFECTSPROFILE); - - // Assert - outputFile = new File(OUTPUT); - assertThat(outputFile.isFile()).isTrue(); - String got = bout.toString(); - assertThat(got).contains("Audio content written to file \"output.mp3\""); - } -} diff --git a/texttospeech/snippets/src/main/java/com/example/texttospeech/SynthesizeTextBeta.java b/texttospeech/snippets/src/main/java/com/example/texttospeech/SynthesizeTextBeta.java deleted file mode 100644 index d4087a05d9e..00000000000 --- a/texttospeech/snippets/src/main/java/com/example/texttospeech/SynthesizeTextBeta.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * 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.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; -import net.sourceforge.argparse4j.ArgumentParsers; -import net.sourceforge.argparse4j.inf.ArgumentParser; -import net.sourceforge.argparse4j.inf.ArgumentParserException; -import net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup; -import net.sourceforge.argparse4j.inf.Namespace; - -/** - * Google Cloud TextToSpeech API sample application. Example usage: mvn package - * exec:java-Dexec.mainClass='com.example.texttospeech.SynthesizeTextBeta' -Dexec.args='--text - * "hello"' - */ -public class SynthesizeTextBeta { - - // [START tts_synthesize_text] - /** - * Demonstrates using the Text to Speech client to synthesize text or ssml. - * - * @param text the raw text to be synthesized. (e.g., "Hello there!") - * @throws Exception on TextToSpeechClient Errors. - */ - public static void synthesizeText(String text) throws Exception { - // Instantiates a client - try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) { - // Set the text input to be synthesized - SynthesisInput input = SynthesisInput.newBuilder().setText(text).build(); - - // Build the voice request - VoiceSelectionParams voice = - VoiceSelectionParams.newBuilder() - .setLanguageCode("en-US") // languageCode = "en_us" - .setSsmlGender(SsmlVoiceGender.FEMALE) // ssmlVoiceGender = SsmlVoiceGender.FEMALE - .build(); - - // Select the type of audio file you want returned - AudioConfig audioConfig = - AudioConfig.newBuilder() - .setAudioEncoding(AudioEncoding.MP3) // MP3 audio. - .build(); - - // Perform the text-to-speech request - 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_synthesize_text] - - // [START tts_synthesize_text_audio_profile_beta] - /** - * Demonstrates using the Text to Speech client with audio profiles to synthesize text or ssml - * - * @param text the raw text to be synthesized. (e.g., "Hello there!") - * @param effectsProfile audio profile to be used for synthesis. (e.g., - * "telephony-class-application") - * @throws Exception on TextToSpeechClient Errors. - */ - public static void synthesizeTextWithAudioProfile(String text, String effectsProfile) - throws Exception { - // Instantiates a client - try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) { - // Set the text input to be synthesized - SynthesisInput input = SynthesisInput.newBuilder().setText(text).build(); - - // Build the voice request - VoiceSelectionParams voice = - VoiceSelectionParams.newBuilder() - .setLanguageCode("en-US") // languageCode = "en_us" - .setSsmlGender(SsmlVoiceGender.FEMALE) // ssmlVoiceGender = SsmlVoiceGender.FEMALE - .build(); - - // Select the type of audio file you want returned and the audio profile - AudioConfig audioConfig = - AudioConfig.newBuilder() - .setAudioEncoding(AudioEncoding.MP3) // MP3 audio. - .addEffectsProfileId(effectsProfile) // audio profile - .build(); - - // Perform the text-to-speech request - 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_synthesize_text_audio_profile_beta] - - // [START tts_synthesize_ssml] - /** - * Demonstrates using the Text to Speech client to synthesize text or ssml. - * - *

Note: ssml must be well-formed according to: (https://www.w3.org/TR/speech-synthesis/ - * Example: Hello there. - * - * @param ssml the ssml document to be synthesized. (e.g., "Hello there."; - private static String EFFECTSPROFILE = "telephony-class-application"; - - private ByteArrayOutputStream bout; - private PrintStream out; - private File outputFile; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - System.setOut(out); - } - - @After - public void tearDown() { - outputFile.delete(); - } - - @Test - public void testSynthesizeText() throws Exception { - // Act - SynthesizeTextBeta.synthesizeText(TEXT); - - // Assert - outputFile = new File(OUTPUT); - assertThat(outputFile.isFile()).isTrue(); - String got = bout.toString(); - assertThat(got).contains("Audio content written to file \"output.mp3\""); - } - - @Test - public void testSynthesizeSsml() throws Exception { - // Act - SynthesizeTextBeta.synthesizeSsml(SSML); - - // Assert - outputFile = new File(OUTPUT); - assertThat(outputFile.isFile()).isTrue(); - String got = bout.toString(); - assertThat(got).contains("Audio content written to file \"output.mp3\""); - } - - @Test - public void testSynthesizeTextWithAudioProfile() throws Exception { - // Act - SynthesizeTextBeta.synthesizeTextWithAudioProfile(TEXT, EFFECTSPROFILE); - - // Assert - outputFile = new File(OUTPUT); - assertThat(outputFile.isFile()).isTrue(); - String got = bout.toString(); - assertThat(got).contains("Audio content written to file \"output.mp3\""); - } -}