mycroft-core/mycroft/tts/__init__.py

71 lines
1.9 KiB
Python
Raw Normal View History

In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
import abc
from os.path import dirname, exists, isdir
from mycroft.util.log import getLogger
__author__ = 'jdorleans'
LOGGER = getLogger(__name__)
class TTS(object):
"""
TTS abstract class to be implemented by all TTS engines.
It aggregates the minimum required parameters and exposes ``execute(sentence)`` function.
"""
def __init__(self, lang, voice, filename='/tmp/tts.wav'):
super(TTS, self).__init__()
self.lang = lang
self.voice = voice
self.filename = filename
@abc.abstractmethod
def execute(self, sentence):
pass
class TTSValidator(object):
"""
TTS Validator abstract class to be implemented by all TTS engines.
It exposes and implements ``validate(tts)`` function as a template to validate the TTS engines.
"""
def __init__(self):
pass
def validate(self, tts):
self.__validate_instance(tts)
self.__validate_filename(tts.filename)
self.validate_lang(tts.lang)
self.validate_connection(tts)
def __validate_instance(self, tts):
instance = self.get_instance()
if not isinstance(tts, instance):
raise AttributeError('tts must be instance of ' + instance.__name__)
LOGGER.debug('TTS: ' + str(instance))
def __validate_filename(self, filename):
if not (filename and filename.endswith('.wav')):
raise AttributeError('filename: ' + filename + ' must be a .wav file!')
dir_path = dirname(filename)
if not (exists(dir_path) and isdir(dir_path)):
raise AttributeError('filename: ' + filename + ' is not a valid file path!')
LOGGER.debug('Filename: ' + filename)
@abc.abstractmethod
def validate_lang(self, lang):
pass
@abc.abstractmethod
def validate_connection(self, tts):
pass
@abc.abstractmethod
def get_instance(self):
pass