Skip to content

Commit c10a605

Browse files
galz10busunkim96
andauthored
docs(samples): add voice selection (#184)
* docs(samples): add voice selection * lint fix * Update samples/snippets/detect_intent_stream.py Co-authored-by: Bu Sun Kim <[email protected]> * Update samples/snippets/detect_intent_stream.py Co-authored-by: Bu Sun Kim <[email protected]> Co-authored-by: Bu Sun Kim <[email protected]>
1 parent 4e97dda commit c10a605

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Dialogflow-CX/detect_intent_stream.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,23 @@ def detect_intent_stream(agent, session_id, audio_file_path, language_code):
7373
def request_generator():
7474
audio_input = session.AudioInput(config=input_audio_config)
7575
query_input = session.QueryInput(audio=audio_input, language_code=language_code)
76+
voice_selection = audio_config.VoiceSelectionParams()
77+
synthesize_speech_config = audio_config.SynthesizeSpeechConfig()
78+
output_audio_config = audio_config.OutputAudioConfig()
79+
80+
# Sets the voice name and gender
81+
voice_selection.name = "en-GB-Standard-A"
82+
voice_selection.ssml_gender = audio_config.SsmlVoiceGender.SSML_VOICE_GENDER_FEMALE
83+
84+
synthesize_speech_config.voice = voice_selection
85+
86+
# Sets the audio encoding
87+
output_audio_config.audio_encoding = audio_config.OutputAudioEncoding.OUTPUT_AUDIO_ENCODING_UNSPECIFIED
88+
output_audio_config.synthesize_speech_config = synthesize_speech_config
7689

7790
# The first request contains the configuration.
7891
yield session.StreamingDetectIntentRequest(
79-
session=session_path, query_input=query_input
92+
session=session_path, query_input=query_input, output_audio_config=output_audio_config
8093
)
8194

8295
# Here we are reading small chunks of audio data from a local

0 commit comments

Comments
 (0)