Skip to content

Commit ac6a732

Browse files
galz10gcf-owl-bot[bot]
authored andcommitted
samples: add voice selection (#333)
* samples: add voice selection * added imports * add ssmlvoicegender * lint fix * lint fix * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Added comments * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 5a8c82e commit ac6a732

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

dialogflow-cx/snippets/src/main/java/dialogflow/cx/DetectIntentStream.java

+27
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@
2323
import com.google.cloud.dialogflow.cx.v3beta1.AudioEncoding;
2424
import com.google.cloud.dialogflow.cx.v3beta1.AudioInput;
2525
import com.google.cloud.dialogflow.cx.v3beta1.InputAudioConfig;
26+
import com.google.cloud.dialogflow.cx.v3beta1.OutputAudioConfig;
27+
import com.google.cloud.dialogflow.cx.v3beta1.OutputAudioEncoding;
2628
import com.google.cloud.dialogflow.cx.v3beta1.QueryInput;
2729
import com.google.cloud.dialogflow.cx.v3beta1.QueryResult;
2830
import com.google.cloud.dialogflow.cx.v3beta1.SessionName;
2931
import com.google.cloud.dialogflow.cx.v3beta1.SessionsClient;
3032
import com.google.cloud.dialogflow.cx.v3beta1.SessionsSettings;
33+
import com.google.cloud.dialogflow.cx.v3beta1.SsmlVoiceGender;
3134
import com.google.cloud.dialogflow.cx.v3beta1.StreamingDetectIntentRequest;
3235
import com.google.cloud.dialogflow.cx.v3beta1.StreamingDetectIntentResponse;
36+
import com.google.cloud.dialogflow.cx.v3beta1.SynthesizeSpeechConfig;
37+
import com.google.cloud.dialogflow.cx.v3beta1.VoiceSelectionParams;
3338
import com.google.protobuf.ByteString;
3439
import java.io.FileInputStream;
3540
import java.io.IOException;
@@ -78,11 +83,33 @@ public static void detectIntentStream(
7883
BidiStream<StreamingDetectIntentRequest, StreamingDetectIntentResponse> bidiStream =
7984
sessionsClient.streamingDetectIntentCallable().call();
8085

86+
// Specify sssml name and gender
87+
VoiceSelectionParams voiceSelection =
88+
// Voices that are available https://cloud.google.com/text-to-speech/docs/voices
89+
VoiceSelectionParams.newBuilder()
90+
.setName("en-GB-Standard-A")
91+
.setSsmlGender(SsmlVoiceGender.SSML_VOICE_GENDER_FEMALE)
92+
.build();
93+
94+
SynthesizeSpeechConfig speechConfig =
95+
SynthesizeSpeechConfig.newBuilder().setVoice(voiceSelection).build();
96+
97+
// Setup audio config
98+
OutputAudioConfig audioConfig =
99+
// Output enconding explanation
100+
// https://cloud.google.com/dialogflow/cx/docs/reference/rpc/google.cloud.dialogflow.cx.v3#outputaudioencoding
101+
OutputAudioConfig.newBuilder()
102+
.setAudioEncoding(OutputAudioEncoding.OUTPUT_AUDIO_ENCODING_UNSPECIFIED)
103+
.setAudioEncodingValue(1)
104+
.setSynthesizeSpeechConfig(speechConfig)
105+
.build();
106+
81107
// The first request must **only** contain the audio configuration:
82108
bidiStream.send(
83109
StreamingDetectIntentRequest.newBuilder()
84110
.setSession(session.toString())
85111
.setQueryInput(queryInput)
112+
.setOutputAudioConfig(audioConfig)
86113
.build());
87114

88115
try (FileInputStream audioStream = new FileInputStream(audioFilePath)) {

0 commit comments

Comments
 (0)