Skip to content

Commit

Permalink
Improve error handling and logging in SAPI5 is_engine_available()
Browse files Browse the repository at this point in the history
It is now in-line with the is_engine_available functions for the
natlink and sphinx engines: using _log.info() instead of
_log.exception() for import errors.
  • Loading branch information
drmfinlay committed Nov 13, 2018
1 parent a542488 commit 22a73d7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions dragonfly/engines/backend_sapi5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,26 @@ def is_engine_available():
# Attempt to import win32 package required for COM.
try:
from win32com.client import Dispatch
except ImportError as e:
_log.info("Failed to import from win32com package: %s. Is it "
"installed?" % e)
return False

try:
from pywintypes import com_error
except Exception as e:
_log.exception("COM error during dispatch: %s" % (e,))
except ImportError as e:
_log.info("Failed to import from the pywintypes package: %s. Is it "
"installed?" % e)
return False

# Attempt to connect to SAPI.
try:
Dispatch("SAPI.SpSharedRecognizer")
except com_error as e:
_log.exception("COM error during dispatch: %s" % (e,))
_log.exception("COM error during dispatch: %s" % e)
return False
except Exception as e:
_log.exception("Exception during Sapi5.isNatSpeakRunning(): %s" % (e,))
_log.exception("Exception during Sapi5.isNatSpeakRunning(): %s" % e)
return False
return True

Expand Down

0 comments on commit 22a73d7

Please sign in to comment.