import logging import re import subprocess import tempfile from jeeves import diagnose from jeeves import plugin from . import juliusvocab if not diagnose.check_executable('julius'): raise ImportError("Can't find julius executable") RE_SENTENCE = re.compile(r'sentence(\d+): <s> (.+) </s>') class JuliusSTTPlugin(plugin.STTPlugin): """ A very basic Speech-to-Text engine using Julius. """ def __init__(self, *args, **kwargs): plugin.STTPlugin.__init__(self, *args, **kwargs) self._logger = logging.getLogger(__name__) self._logger.warning("This STT plugin doesn't have multilanguage " + "support!") vocabulary_path = self.compile_vocabulary( juliusvocab.compile_vocabulary) self._dfa_file = juliusvocab.get_dfa_path(vocabulary_path) self._dict_file = juliusvocab.get_dict_path(vocabulary_path)
import collections import logging import pipes import re import subprocess import tempfile from jeeves import diagnose from jeeves import plugin if not diagnose.check_executable('espeak'): raise ImportError("espeak executable not found!") RE_PATTERN = re.compile(r'(?P<pty>\d+)\s+' + r'(?P<lang>[a-z-]+)\s+' + r'(?P<gender>[MF-])\s+' + r'(?P<name>[\w-]+)\s+\S+\s+' + r'(?P<other>(?:\([a-z-]+\s+\d+\))*)') RE_OTHER = re.compile(r'\((?P<lang>[a-z-]+)\s+(?P<pty>\d+)\)') Voice = collections.namedtuple( 'Voice', ['name', 'gender', 'priority', 'language']) class EspeakTTSPlugin(plugin.TTSPlugin): """ Uses the eSpeak speech synthesizer included in the disk image Requires espeak to be available """ def __init__(self, *args, **kwargs):
import logging import pipes import subprocess import tempfile from jeeves import diagnose from jeeves import plugin if not all(diagnose.check_executable(e) for e in ('text2wave', 'festival')): raise ImportError('Executables "text2wave" and/or "festival" not found!') class FestivalTTSPlugin(plugin.TTSPlugin): """ Uses the festival speech synthesizer Requires festival (text2wave) to be available """ def __init__(self, *args, **kwargs): plugin.TTSPlugin.__init__(self, *args, **kwargs) self._logger = logging.getLogger(__name__) available_voices = self.get_voices() if len(available_voices) == 0: raise ValueError('No voices available!') self._logger.warning("This TTS plugin doesn't have multilanguage " + "support!") self._logger.info('Available voices: %s', ', '.join(available_voices)) try: voice = self.profile['festival-tts']['voice']
import logging import os import pipes import platform import subprocess import tempfile from jeeves import diagnose from jeeves import plugin EXECUTABLE = 'say' if not platform.system().lower() == 'darwin': raise ImportError('Invalid platform!') if not diagnose.check_executable(EXECUTABLE): raise ImportError("Executable '%s' not found!" % EXECUTABLE) class MacOSXTTSPlugin(plugin.TTSPlugin): """ Uses the OS X built-in 'say' command """ def __init__(self, *args, **kwargs): plugin.TTSPlugin.__init__(self, *args, **kwargs) self._logger = logging.getLogger(__name__) self._logger.warning("This TTS plugin doesn't have multilanguage " + "support!") def say(self, phrase): with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f: fname = f.name