Let the user audition voices and choose one by index. Args: language: Spoken language code passed to Speech. Returns: int: The chosen voice index.
(self, language)
| 81 | |
| 82 | |
| 83 | def _select_voice_interactively(self, language): |
| 84 | """Let the user audition voices and choose one by index. |
| 85 | Args: |
| 86 | language: Spoken language code passed to Speech. |
| 87 | Returns: |
| 88 | int: The chosen voice index. |
| 89 | """ |
| 90 | voice_count = Speech().available_voice_count(language) |
| 91 | if voice_count <= 1: |
| 92 | return 0 |
| 93 | |
| 94 | SAMPLE_LINE = "Hello, this is how I sound. Should I use this voice?" |
| 95 | idx = 0 |
| 96 | preview = Speech(enable=True, language=language, voice_idx=idx) |
| 97 | while True: |
| 98 | pretty_print(f"Voice {idx + 1}/{voice_count}", color="status") |
| 99 | preview.set_voice(idx) |
| 100 | preview.speak(SAMPLE_LINE) |
| 101 | choice = self._prompt_voice_choice(idx, voice_count) |
| 102 | if choice == "accept": |
| 103 | return idx |
| 104 | idx = self._next_voice_index(choice, idx, voice_count) |
| 105 | |
| 106 | |
| 107 | def _prompt_voice_choice(self, current_idx, voice_count): |
no test coverage detected