__init__.py 746 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from mods.BaseMod import BaseMod
  4. import os
  5. import platform
  6. class WindowsSay(BaseMod):
  7. _isActive:bool=True
  8. speaker=None
  9. def __init__(self):
  10. self.sys = platform.system()
  11. if self.sys=="Windows":
  12. self._isActive=True
  13. else:
  14. self._isActive=False
  15. def IsActive(self) -> bool:
  16. return self._isActive
  17. def onSay(self, text):
  18. import win32com.client
  19. if self.speaker == None:
  20. self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
  21. if self.speaker != None:
  22. self.speaker.Rate = 0.0
  23. self.speaker.Speak(text)
  24. else:
  25. print("Failed to speak - Speaker is none")