Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_windows_platform() -> bool:
- return platform.system() == 'Windows'
- class SpeakerInitializeError(Exception):
- """ Represent speaker initialization errors"""
- class JarvisStatus:
- """initialize speaker and other settings"""
- debugSwitchOffSpeaker = False
- engine = None
- isRunning = True
- engineUsed = ""
- countErrors = 0
- wikifound = []
- speak = None
- @staticmethod
- def initializePyTTSSpeaker() -> bool:
- try:
- JarvisStatus.engine = pyttsx3.init()
- voices = JarvisStatus.engine.getProperty('voices')
- JarvisStatus.engine.setProperty('voice', voices[0].id)
- except (RuntimeError, Exception):
- print("Sorry, pyttsx3 is not working.")
- traceback.print_exc(limit=2, file=sys.stdout)
- JarvisStatus.engine = None
- return False
- return True
- @staticmethod
- def initializeSpVoiceSpeaker() -> bool:
- if not is_windows_platform():
- raise SpeakerInitializeError("Cannot initialize SpVoice. Windows platform required")
- from win32com.client import Dispatch
- try:
- JarvisStatus.speak = Dispatch("SAPI.SpVoice").Speak
- except Exception:
- traceback.print_exc(limit=2, file=sys.stdout)
- raise SpeakerInitializeError("Cannot initialize SpVoice")
- return True
- #
- @staticmethod
- def initializeSpeaker() -> bool:
- """setup of speaking functionality"""
- try:
- # second member will be evaluated only if first will fail
- return JarvisStatus.initializePyTTSSpeaker() or JarvisStatus.initializeSpVoiceSpeaker()
- except SpeakerInitializeError:
- JarvisStatus.debugSwitchOffSpeaker = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement