|
23 | 23 | import com.google.cloud.dialogflow.cx.v3beta1.AudioEncoding;
|
24 | 24 | import com.google.cloud.dialogflow.cx.v3beta1.AudioInput;
|
25 | 25 | 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; |
26 | 28 | import com.google.cloud.dialogflow.cx.v3beta1.QueryInput;
|
27 | 29 | import com.google.cloud.dialogflow.cx.v3beta1.QueryResult;
|
28 | 30 | import com.google.cloud.dialogflow.cx.v3beta1.SessionName;
|
29 | 31 | import com.google.cloud.dialogflow.cx.v3beta1.SessionsClient;
|
30 | 32 | import com.google.cloud.dialogflow.cx.v3beta1.SessionsSettings;
|
| 33 | +import com.google.cloud.dialogflow.cx.v3beta1.SsmlVoiceGender; |
31 | 34 | import com.google.cloud.dialogflow.cx.v3beta1.StreamingDetectIntentRequest;
|
32 | 35 | 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; |
33 | 38 | import com.google.protobuf.ByteString;
|
34 | 39 | import java.io.FileInputStream;
|
35 | 40 | import java.io.IOException;
|
@@ -78,11 +83,33 @@ public static void detectIntentStream(
|
78 | 83 | BidiStream<StreamingDetectIntentRequest, StreamingDetectIntentResponse> bidiStream =
|
79 | 84 | sessionsClient.streamingDetectIntentCallable().call();
|
80 | 85 |
|
| 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 | + |
81 | 107 | // The first request must **only** contain the audio configuration:
|
82 | 108 | bidiStream.send(
|
83 | 109 | StreamingDetectIntentRequest.newBuilder()
|
84 | 110 | .setSession(session.toString())
|
85 | 111 | .setQueryInput(queryInput)
|
| 112 | + .setOutputAudioConfig(audioConfig) |
86 | 113 | .build());
|
87 | 114 |
|
88 | 115 | try (FileInputStream audioStream = new FileInputStream(audioFilePath)) {
|
|
0 commit comments