Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
DGrothe-PhD committed Jun 28, 2024
1 parent 43e984f commit 1a21bff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
33 changes: 15 additions & 18 deletions jarvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@

listener = sr.Recognizer()

# pylint: disable=C0103
# pylint: disable=W0718
# pylint: disable=R0903
# pylint: disable=E0211
# pylint: disable=invalid-name
# pylint: disable=broad-exception-caught
# pylint: disable=too-few-public-methods

### disable false positives of not callable
# pylint: disable=E1102

# pylint: disable=E0401
### E0401 as pylint (GitHub/Linux) cannot install Windows package

def is_windows_platform() -> bool:
"""True if system is Windows"""
return platform.system() == 'Windows'

class SpeakerInitializeError(Exception):
""" Represent speaker initialization errors"""
"""Represent speaker initialization errors"""


class JarvisStatus:
Expand All @@ -50,6 +52,7 @@ class JarvisStatus:

@staticmethod
def initializePyTTSSpeaker() -> bool:
"""Tries to initialize py3-tts speaker"""
try:
JarvisStatus.engine = pyttsx3.init()
voices = JarvisStatus.engine.getProperty('voices')
Expand All @@ -64,14 +67,15 @@ def initializePyTTSSpeaker() -> bool:

@staticmethod
def initializeSpVoiceSpeaker() -> bool:
"""Tries to initialize Windows speaker"""
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:
except Exception as exc:
traceback.print_exc(limit=2, file=sys.stdout)
raise SpeakerInitializeError("Cannot initialize SpVoice")
raise SpeakerInitializeError("Cannot initialize SpVoice") from exc
return True

@staticmethod
Expand All @@ -95,13 +99,6 @@ def talk(text):
JarvisStatus.engine.runAndWait()
elif JarvisStatus.speak:
JarvisStatus.speak(text)
''' legacy code
if JarvisStatus.debugSwitchOffSpeaker and JarvisStatus.speak:
JarvisStatus.speak(text)
elif not JarvisStatus.debugSwitchOffSpeaker:
JarvisStatus.engine.say(text)
JarvisStatus.engine.runAndWait()
'''

def makeReadable(text):
"""Replace for better speaker functionality:
Expand Down Expand Up @@ -234,10 +231,10 @@ def runJarvis():
except Exception as e:
talk(f"Entschuldigung, {JarvisStatus.engineUsed} konnte es nicht finden.")
print(e)
# pylint: enable=C0103
# pylint: enable=W0718
# pylint: enable=R0903
# pylint: enable=E0211

# pylint: disable=invalid-name
# pylint: enable=broad-exception-caught
# pylint: enable=too-few-public-methods
# pylint: enable=E1102
# pylint: enable=E0401
### no issue on a real system though
4 changes: 3 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ class-naming-style=PascalCase
module-naming-style=camelCase

disable=missing-final-newline,
missing-module-docstring
missing-module-docstring,
import-outside-toplevel,
no-method-argument

0 comments on commit 1a21bff

Please sign in to comment.