summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-10-01 19:10:45 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2014-10-06 18:18:06 +0200
commit304420fe97fe0d377e7afcb525fffecc619f7c02 (patch)
tree341acdfbc6dc6a9b911255d850554cad752bb936
parent7dc4f3022d1843063dce621ca09c80bb64cdb8c1 (diff)
downloadjasper-client-304420fe97fe0d377e7afcb525fffecc619f7c02.tar.gz
jasper-client-304420fe97fe0d377e7afcb525fffecc619f7c02.zip
Use diagnose module in stt.py and tts.py
-rw-r--r--client/stt.py6
-rw-r--r--client/tts.py27
2 files changed, 18 insertions, 15 deletions
diff --git a/client/stt.py b/client/stt.py
index cfaced6..485f5d9 100644
--- a/client/stt.py
+++ b/client/stt.py
@@ -5,12 +5,12 @@ import traceback
import wave
import json
import tempfile
-import pkgutil
import logging
from abc import ABCMeta, abstractmethod
import requests
import yaml
import jasperpath
+import diagnose
"""
The default Speech-to-Text implementation which relies on PocketSphinx.
@@ -171,7 +171,7 @@ class PocketSphinxSTT(AbstractSTTEngine):
@classmethod
def is_available(cls):
- return (pkgutil.get_loader('pocketsphinx') is not None)
+ return diagnose.check_python_import('pocketsphinx')
"""
Speech-To-Text implementation which relies on the Google Speech API.
@@ -274,7 +274,7 @@ class GoogleSTT(AbstractSTTEngine):
@classmethod
def is_available(cls):
- return True
+ return diagnose.check_network_connection()
"""
Returns a Speech-To-Text engine.
diff --git a/client/tts.py b/client/tts.py
index 244c0f4..d570b26 100644
--- a/client/tts.py
+++ b/client/tts.py
@@ -15,18 +15,19 @@ import tempfile
import subprocess
import pipes
import logging
+import wave
from abc import ABCMeta, abstractmethod
-from distutils.spawn import find_executable
import argparse
-
-import wave
+import yaml
try:
import mad
import gtts
except ImportError:
pass
+import diagnose
+
class AbstractTTSEngine(object):
"""
@@ -37,7 +38,7 @@ class AbstractTTSEngine(object):
@classmethod
@abstractmethod
def is_available(cls):
- return (find_executable('aplay') is not None)
+ return diagnose.check_executable('aplay')
def __init__(self, **kwargs):
self._logger = logging.getLogger(__name__)
@@ -67,7 +68,7 @@ class AbstractMp3TTSEngine(AbstractTTSEngine):
@classmethod
def is_available(cls):
return (super(AbstractMp3TTSEngine, cls).is_available() and
- 'mad' in sys.modules.keys())
+ diagnose.check_python_import('mad'))
def play_mp3(self, filename):
mf = mad.MadFile(filename)
@@ -123,7 +124,7 @@ class EspeakTTS(AbstractTTSEngine):
@classmethod
def is_available(cls):
return (super(cls, cls).is_available() and
- find_executable('espeak') is not None)
+ diagnose.check_executable('espeak'))
def say(self, phrase):
self._logger.debug("Saying '%s' with '%s'", phrase, self.SLUG)
@@ -158,8 +159,9 @@ class FestivalTTS(AbstractTTSEngine):
@classmethod
def is_available(cls):
if (super(cls, cls).is_available() and
- find_executable('text2wave') is not None and
- find_executable('festival') is not None):
+ diagnose.check_executable('text2wave') and
+ diagnose.check_executable('festival')):
+
logger = logging.getLogger(__name__)
cmd = ['festival', '--pipe']
with tempfile.SpooledTemporaryFile() as out_f:
@@ -205,8 +207,8 @@ class MacOSXTTS(AbstractTTSEngine):
@classmethod
def is_available(cls):
return (platform.system() == 'darwin' and
- find_executable('say') is not None and
- find_executable('afplay') is not None)
+ diagnose.check_executable('say') and
+ diagnose.check_executable('afplay'))
def say(self, phrase):
self._logger.debug("Saying '%s' with '%s'", phrase, self.SLUG)
@@ -247,7 +249,7 @@ class PicoTTS(AbstractTTSEngine):
@classmethod
def is_available(cls):
return (super(cls, cls).is_available() and
- find_executable('pico2wave') is not None)
+ diagnose.check_executable('pico2wave'))
@property
def languages(self):
@@ -303,7 +305,8 @@ class GoogleTTS(AbstractMp3TTSEngine):
@classmethod
def is_available(cls):
return (super(cls, cls).is_available() and
- 'gtts' in sys.modules.keys())
+ diagnose.check_python_import('gtts') and
+ diagnose.check_network_connection())
@property
def languages(self):