diff --git a/helper/exercises.py b/helper/exercises.py index 2fb168b..d3d409b 100644 --- a/helper/exercises.py +++ b/helper/exercises.py @@ -278,6 +278,7 @@ def generate_listening_1_conversation(topic: str): GEN_QUESTION_TEMPERATURE ) + chosen_voices = [] name_to_voice = {} for segment in processed['conversation']: if 'voice' not in segment: @@ -285,10 +286,17 @@ def generate_listening_1_conversation(topic: str): if name in name_to_voice: voice = name_to_voice[name] else: - if segment['gender'].lower() == 'male': - voice = random.choice(MALE_NEURAL_VOICES)['Id'] - else: - voice = random.choice(FEMALE_NEURAL_VOICES)['Id'] + voice = None + while voice is None: + if segment['gender'].lower() == 'male': + available_voices = MALE_NEURAL_VOICES + else: + available_voices = FEMALE_NEURAL_VOICES + + chosen_voice = random.choice(available_voices)['Id'] + if chosen_voice not in chosen_voices: + voice = chosen_voice + chosen_voices.append(voice) name_to_voice[name] = voice segment['voice'] = voice return response, processed