| 30 | |
| 31 | |
| 32 | def init_tts_engine(): |
| 33 | if win32com_client is not None: |
| 34 | try: |
| 35 | voice = win32com_client.Dispatch("SAPI.SpVoice") |
| 36 | voices = voice.GetVoices() |
| 37 | if voices.Count: |
| 38 | voice.Voice = voices.Item(0) |
| 39 | return voice |
| 40 | except Exception as exc: |
| 41 | print(f"SAPI voice disabled: {exc}") |
| 42 | if pyttsx3 is None: |
| 43 | return None |
| 44 | try: |
| 45 | engine = pyttsx3.init() |
| 46 | voices = engine.getProperty("voices") |
| 47 | if voices: |
| 48 | engine.setProperty("voice", voices[0].id) |
| 49 | engine.setProperty("rate", 165) |
| 50 | return engine |
| 51 | except Exception as exc: |
| 52 | print(f"TTS engine disabled: {exc}") |
| 53 | return None |
| 54 | |
| 55 | |
| 56 | def set_tts_engine(engine): |