Skip to content

Commit cdd66e8

Browse files
averikitschlesv
authored andcommitted
samples: update shared config (#2443)
* update shared config * Update to 1.0.13 * lint * Fix linting * lint * fix imports Co-authored-by: Les Vogel <[email protected]>
1 parent 00449b5 commit cdd66e8

File tree

9 files changed

+61
-87
lines changed

9 files changed

+61
-87
lines changed

texttospeech/snippets/src/main/java/com/example/texttospeech/ListAllSupportedVoices.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@
2222
import com.google.cloud.texttospeech.v1.TextToSpeechClient;
2323
import com.google.cloud.texttospeech.v1.Voice;
2424
import com.google.protobuf.ByteString;
25-
2625
import java.util.List;
2726

28-
2927
/**
30-
* Google Cloud TextToSpeech API sample application.
31-
* Example usage: mvn package exec:java
32-
* -Dexec.mainClass='com.example.texttospeech.ListAllSupportedVoices'
28+
* Google Cloud TextToSpeech API sample application. Example usage: mvn package exec:java
29+
* -Dexec.mainClass='com.example.texttospeech.ListAllSupportedVoices'
3330
*/
3431
public class ListAllSupportedVoices {
3532

3633
// [START tts_list_voices]
3734
/**
3835
* Demonstrates using the Text to Speech client to list the client's supported voices.
36+
*
3937
* @throws Exception on TextToSpeechClient Errors.
4038
*/
4139
public static List<Voice> listAllSupportedVoices() throws Exception {
@@ -62,11 +60,10 @@ public static List<Voice> listAllSupportedVoices() throws Exception {
6260
System.out.format("SSML Voice Gender: %s\n", voice.getSsmlGender());
6361

6462
// Display the natural sample rate hertz for this voice. Example: 24000
65-
System.out.format("Natural Sample Rate Hertz: %s\n\n",
66-
voice.getNaturalSampleRateHertz());
63+
System.out.format("Natural Sample Rate Hertz: %s\n\n", voice.getNaturalSampleRateHertz());
6764
}
6865
return voices;
6966
}
7067
}
7168
// [END tts_list_voices]
72-
}
69+
}

texttospeech/snippets/src/main/java/com/example/texttospeech/QuickstartSample.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,39 +30,34 @@
3030
import java.io.OutputStream;
3131

3232
/**
33-
* Google Cloud TextToSpeech API sample application.
34-
* Example usage: mvn package exec:java
35-
* -Dexec.mainClass='com.example.texttospeech.QuickstartSample'
33+
* Google Cloud TextToSpeech API sample application. Example usage: mvn package exec:java
34+
* -Dexec.mainClass='com.example.texttospeech.QuickstartSample'
3635
*/
3736
public class QuickstartSample {
3837

39-
/**
40-
* Demonstrates using the Text-to-Speech API.
41-
*/
38+
/** Demonstrates using the Text-to-Speech API. */
4239
public static void main(String... args) throws Exception {
4340
// Instantiates a client
4441
try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
4542
// Set the text input to be synthesized
46-
SynthesisInput input = SynthesisInput.newBuilder()
47-
.setText("Hello, World!")
48-
.build();
43+
SynthesisInput input = SynthesisInput.newBuilder().setText("Hello, World!").build();
4944

5045
// Build the voice request, select the language code ("en-US") and the ssml voice gender
5146
// ("neutral")
52-
VoiceSelectionParams voice = VoiceSelectionParams.newBuilder()
53-
.setLanguageCode("en-US")
54-
.setSsmlGender(SsmlVoiceGender.NEUTRAL)
55-
.build();
47+
VoiceSelectionParams voice =
48+
VoiceSelectionParams.newBuilder()
49+
.setLanguageCode("en-US")
50+
.setSsmlGender(SsmlVoiceGender.NEUTRAL)
51+
.build();
5652

5753
// Select the type of audio file you want returned
58-
AudioConfig audioConfig = AudioConfig.newBuilder()
59-
.setAudioEncoding(AudioEncoding.MP3)
60-
.build();
54+
AudioConfig audioConfig =
55+
AudioConfig.newBuilder().setAudioEncoding(AudioEncoding.MP3).build();
6156

6257
// Perform the text-to-speech request on the text input with the selected voice parameters and
6358
// audio file type
64-
SynthesizeSpeechResponse response = textToSpeechClient.synthesizeSpeech(input, voice,
65-
audioConfig);
59+
SynthesizeSpeechResponse response =
60+
textToSpeechClient.synthesizeSpeech(input, voice, audioConfig);
6661

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

texttospeech/snippets/src/main/java/com/example/texttospeech/SsmlAddresses.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.io.OutputStream;
3333
import java.nio.file.Files;
3434
import java.nio.file.Paths;
35+
3536
// [END tts_ssml_address_imports]
3637

3738
/**

texttospeech/snippets/src/main/java/com/example/texttospeech/SynthesizeFile.java

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,49 @@
2525
import com.google.cloud.texttospeech.v1.TextToSpeechClient;
2626
import com.google.cloud.texttospeech.v1.VoiceSelectionParams;
2727
import com.google.protobuf.ByteString;
28-
2928
import java.io.FileOutputStream;
3029
import java.io.OutputStream;
3130
import java.nio.file.Files;
3231
import java.nio.file.Paths;
3332

34-
3533
/**
36-
* Google Cloud TextToSpeech API sample application.
37-
* Example usage: mvn package exec:java -Dexec.mainClass='com.example.texttospeech.SynthesizeFile'
38-
* -Dexec.args='--text resources/hello.txt'
34+
* Google Cloud TextToSpeech API sample application. Example usage: mvn package exec:java
35+
* -Dexec.mainClass='com.example.texttospeech.SynthesizeFile' -Dexec.args='--text
36+
* resources/hello.txt'
3937
*/
4038
public class SynthesizeFile {
4139

4240
// [START tts_synthesize_text_file]
4341
/**
4442
* Demonstrates using the Text to Speech client to synthesize a text file or ssml file.
43+
*
4544
* @param textFile the text file to be synthesized. (e.g., hello.txt)
4645
* @throws Exception on TextToSpeechClient Errors.
4746
*/
48-
public static ByteString synthesizeTextFile(String textFile)
49-
throws Exception {
47+
public static ByteString synthesizeTextFile(String textFile) throws Exception {
5048
// Instantiates a client
5149
try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
5250
// Read the file's contents
5351
String contents = new String(Files.readAllBytes(Paths.get(textFile)));
5452
// Set the text input to be synthesized
55-
SynthesisInput input = SynthesisInput.newBuilder()
56-
.setText(contents)
57-
.build();
53+
SynthesisInput input = SynthesisInput.newBuilder().setText(contents).build();
5854

5955
// Build the voice request
60-
VoiceSelectionParams voice = VoiceSelectionParams.newBuilder()
61-
.setLanguageCode("en-US") // languageCode = "en_us"
62-
.setSsmlGender(SsmlVoiceGender.FEMALE) // ssmlVoiceGender = SsmlVoiceGender.FEMALE
63-
.build();
56+
VoiceSelectionParams voice =
57+
VoiceSelectionParams.newBuilder()
58+
.setLanguageCode("en-US") // languageCode = "en_us"
59+
.setSsmlGender(SsmlVoiceGender.FEMALE) // ssmlVoiceGender = SsmlVoiceGender.FEMALE
60+
.build();
6461

6562
// Select the type of audio file you want returned
66-
AudioConfig audioConfig = AudioConfig.newBuilder()
67-
.setAudioEncoding(AudioEncoding.MP3) // MP3 audio.
68-
.build();
63+
AudioConfig audioConfig =
64+
AudioConfig.newBuilder()
65+
.setAudioEncoding(AudioEncoding.MP3) // MP3 audio.
66+
.build();
6967

7068
// Perform the text-to-speech request
71-
SynthesizeSpeechResponse response = textToSpeechClient.synthesizeSpeech(input, voice,
72-
audioConfig);
69+
SynthesizeSpeechResponse response =
70+
textToSpeechClient.synthesizeSpeech(input, voice, audioConfig);
7371

7472
// Get the audio contents from the response
7573
ByteString audioContents = response.getAudioContent();
@@ -84,38 +82,37 @@ public static ByteString synthesizeTextFile(String textFile)
8482
}
8583
// [END tts_synthesize_text_file]
8684

87-
8885
// [START tts_synthesize_ssml_file]
8986
/**
9087
* Demonstrates using the Text to Speech client to synthesize a text file or ssml file.
88+
*
9189
* @param ssmlFile the ssml document to be synthesized. (e.g., hello.ssml)
9290
* @throws Exception on TextToSpeechClient Errors.
9391
*/
94-
public static ByteString synthesizeSsmlFile(String ssmlFile)
95-
throws Exception {
92+
public static ByteString synthesizeSsmlFile(String ssmlFile) throws Exception {
9693
// Instantiates a client
9794
try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
9895
// Read the file's contents
9996
String contents = new String(Files.readAllBytes(Paths.get(ssmlFile)));
10097
// Set the ssml input to be synthesized
101-
SynthesisInput input = SynthesisInput.newBuilder()
102-
.setSsml(contents)
103-
.build();
98+
SynthesisInput input = SynthesisInput.newBuilder().setSsml(contents).build();
10499

105100
// Build the voice request
106-
VoiceSelectionParams voice = VoiceSelectionParams.newBuilder()
107-
.setLanguageCode("en-US") // languageCode = "en_us"
108-
.setSsmlGender(SsmlVoiceGender.FEMALE) // ssmlVoiceGender = SsmlVoiceGender.FEMALE
109-
.build();
101+
VoiceSelectionParams voice =
102+
VoiceSelectionParams.newBuilder()
103+
.setLanguageCode("en-US") // languageCode = "en_us"
104+
.setSsmlGender(SsmlVoiceGender.FEMALE) // ssmlVoiceGender = SsmlVoiceGender.FEMALE
105+
.build();
110106

111107
// Select the type of audio file you want returned
112-
AudioConfig audioConfig = AudioConfig.newBuilder()
113-
.setAudioEncoding(AudioEncoding.MP3) // MP3 audio.
114-
.build();
108+
AudioConfig audioConfig =
109+
AudioConfig.newBuilder()
110+
.setAudioEncoding(AudioEncoding.MP3) // MP3 audio.
111+
.build();
115112

116113
// Perform the text-to-speech request
117-
SynthesizeSpeechResponse response = textToSpeechClient.synthesizeSpeech(input, voice,
118-
audioConfig);
114+
SynthesizeSpeechResponse response =
115+
textToSpeechClient.synthesizeSpeech(input, voice, audioConfig);
119116

120117
// Get the audio contents from the response
121118
ByteString audioContents = response.getAudioContent();
@@ -129,4 +126,4 @@ public static ByteString synthesizeSsmlFile(String ssmlFile)
129126
}
130127
}
131128
// [END tts_synthesize_ssml_file]
132-
}
129+
}

texttospeech/snippets/src/main/java/com/example/texttospeech/SynthesizeText.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@
2525
import com.google.cloud.texttospeech.v1.TextToSpeechClient;
2626
import com.google.cloud.texttospeech.v1.VoiceSelectionParams;
2727
import com.google.protobuf.ByteString;
28-
2928
import java.io.FileOutputStream;
3029
import java.io.OutputStream;
3130

3231
/**
33-
* Google Cloud TextToSpeech API sample application.
34-
* Example usage: mvn package exec:java -Dexec.mainClass='com.example.texttospeech.SynthesizeText'
35-
* -Dexec.args='--text "hello"'
32+
* Google Cloud TextToSpeech API sample application. Example usage: mvn package exec:java
33+
* -Dexec.mainClass='com.example.texttospeech.SynthesizeText' -Dexec.args='--text "hello"'
3634
*/
3735
public class SynthesizeText {
3836

texttospeech/snippets/src/test/java/com/example/texttospeech/ListAllSupportedVoicesIT.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@
2121
import com.google.cloud.texttospeech.v1.Voice;
2222
import java.io.ByteArrayOutputStream;
2323
import java.io.PrintStream;
24-
2524
import java.util.List;
2625
import org.junit.After;
2726
import org.junit.Before;
2827
import org.junit.Test;
2928
import org.junit.runner.RunWith;
3029
import org.junit.runners.JUnit4;
3130

32-
/**
33-
* Tests for ListAllSupportedVoices sample.
34-
*/
31+
/** Tests for ListAllSupportedVoices sample. */
3532
@RunWith(JUnit4.class)
3633
@SuppressWarnings("checkstyle:abbreviationaswordinname")
3734
public class ListAllSupportedVoicesIT {
@@ -40,7 +37,6 @@ public class ListAllSupportedVoicesIT {
4037
private PrintStream out;
4138
private ListAllSupportedVoices listAllSupportedVoices;
4239

43-
4440
@Before
4541
public void setUp() {
4642
bout = new ByteArrayOutputStream();
@@ -66,4 +62,4 @@ public void testListAllSupportedVoices() throws Exception {
6662
assertThat(got).contains("SSML Voice Gender: MALE");
6763
assertThat(got).contains("SSML Voice Gender: FEMALE");
6864
}
69-
}
65+
}

texttospeech/snippets/src/test/java/com/example/texttospeech/SsmlAddressesIT.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,17 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020

21-
import com.google.protobuf.ByteString;
2221
import java.io.ByteArrayOutputStream;
2322
import java.io.File;
2423
import java.io.PrintStream;
2524
import java.nio.file.Files;
2625
import java.nio.file.Paths;
27-
import org.junit.After;
2826
import org.junit.Before;
2927
import org.junit.Test;
3028
import org.junit.runner.RunWith;
3129
import org.junit.runners.JUnit4;
3230

33-
/**
34-
* Tests for SsmlAddresses sample.
35-
*/
31+
/** Tests for SsmlAddresses sample. */
3632
@RunWith(JUnit4.class)
3733
@SuppressWarnings("checkstyle:abbreviationaswordinname")
3834
public class SsmlAddressesIT {
@@ -77,4 +73,4 @@ public void testSsmlToAudio() throws Exception {
7773
// After
7874
outputFile.delete();
7975
}
80-
}
76+
}

texttospeech/snippets/src/test/java/com/example/texttospeech/SynthesizeFileIT.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@
2121
import com.google.protobuf.ByteString;
2222
import java.io.ByteArrayOutputStream;
2323
import java.io.File;
24-
2524
import java.io.PrintStream;
2625
import org.junit.After;
2726
import org.junit.Before;
2827
import org.junit.Test;
2928
import org.junit.runner.RunWith;
3029
import org.junit.runners.JUnit4;
3130

32-
/**
33-
* Tests for SynthesizeFile sample.
34-
*/
31+
/** Tests for SynthesizeFile sample. */
3532
@RunWith(JUnit4.class)
3633
@SuppressWarnings("checkstyle:abbreviationaswordinname")
3734
public class SynthesizeFileIT {
@@ -81,4 +78,4 @@ public void testSynthesizeSsml() throws Exception {
8178
String got = bout.toString();
8279
assertThat(got).contains("Audio content written to file \"output.mp3\"");
8380
}
84-
}
81+
}

texttospeech/snippets/src/test/java/com/example/texttospeech/SynthesizeTextIT.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@
2121
import com.google.protobuf.ByteString;
2222
import java.io.ByteArrayOutputStream;
2323
import java.io.File;
24-
2524
import java.io.PrintStream;
2625
import org.junit.After;
2726
import org.junit.Before;
2827
import org.junit.Test;
2928
import org.junit.runner.RunWith;
3029
import org.junit.runners.JUnit4;
3130

32-
/**
33-
* Tests for SynthesizeText sample.
34-
*/
31+
/** Tests for SynthesizeText sample. */
3532
@RunWith(JUnit4.class)
3633
@SuppressWarnings("checkstyle:abbreviationaswordinname")
3734
public class SynthesizeTextIT {
@@ -95,4 +92,4 @@ public void testSynthesizeTextWithAudioProfile() throws Exception {
9592
String got = bout.toString();
9693
assertThat(got).contains("Audio content written to file \"output.mp3\"");
9794
}
98-
}
95+
}

0 commit comments

Comments
 (0)