Beispiel #1
0
    def test_speak(self):
        mary = MaryTTS()

        audio = mary.speak("Hello World")
        waves = wave.open(BytesIO(audio))

        self.assertEqual(waves.getnchannels(), 1)
        self.assertEqual(waves.getframerate(), 48000)
        self.assertGreater(waves.getnframes(), 10000)
Beispiel #2
0
    def test_speak_with_effects(self):
        mary = MaryTTS()

        audio = mary.speak("Hello World", {
            "volume": "amount:2.0;",
            "robot": "amount:100.0;"
        })
        waves = wave.open(BytesIO(audio))

        self.assertEqual(waves.getnchannels(), 1)
        self.assertEqual(waves.getframerate(), 48000)
        self.assertGreater(waves.getnframes(), 10000)
Beispiel #3
0
class MaryTTSProvider(Provider):
    """MaryTTS speech api provider."""

    def __init__(self, hass, conf):
        """Init MaryTTS TTS service."""
        self.hass = hass
        self._mary = MaryTTS(
            conf.get(CONF_HOST),
            conf.get(CONF_PORT),
            conf.get(CONF_CODEC),
            conf.get(CONF_LANG),
            conf.get(CONF_VOICE),
        )
        self._effects = conf.get(CONF_EFFECT)
        self.name = "MaryTTS"

    @property
    def default_language(self):
        """Return the default language."""
        return self._mary.locale

    @property
    def supported_languages(self):
        """Return list of supported languages."""
        return SUPPORT_LANGUAGES

    @property
    def default_options(self):
        """Return dict include default options."""
        return {CONF_EFFECT: self._effects}

    @property
    def supported_options(self):
        """Return a list of supported options."""
        return SUPPORT_OPTIONS

    def get_tts_audio(self, message, language, options=None):
        """Load TTS from MaryTTS."""
        effects = options[CONF_EFFECT]

        data = self._mary.speak(message, effects)
        audiotype = MAP_MARYTTS_CODEC[self._mary.codec]

        return audiotype, data
Beispiel #4
0
    def test_speak_as_emotionalxml(self):
        mary = MaryTTS(input_type="EMOTIONML")

        xml = """
        <emotionml version="1.0" xmlns="http://www.w3.org/2009/10/emotionml" 
        category-set="http://www.w3.org/TR/emotion-voc/xml#everyday-categories">        
            <emotion><category name="angry"/>
                Hello World
            </emotion>
        </emotionml>
        """

        audio = mary.speak(xml)
        waves = wave.open(BytesIO(audio))

        self.assertEqual(waves.getnchannels(), 1)
        self.assertEqual(waves.getframerate(), 48000)
        self.assertGreater(waves.getnframes(), 10000)
        # Make sure only "Hello World" is in the output, not the whole xml
        self.assertLess(len(audio), 200000)