MozillaTTS
Implement TTS module that works with Mozilla-TTS server. ==== Environment Notes ==== Requires a Mozilla-TTS server running preferably in your local network.pull/2713/head
parent
b4a0c51a5f
commit
5be3b54b27
|
@ -285,8 +285,8 @@
|
||||||
// Text to Speech parameters
|
// Text to Speech parameters
|
||||||
// Override: REMOTE
|
// Override: REMOTE
|
||||||
"tts": {
|
"tts": {
|
||||||
// Engine. Options: "mimic", "google", "marytts", "fatts", "espeak",
|
// Engine. Options: "mimic", "mimic2", "google", "marytts", "fatts", "espeak",
|
||||||
// "spdsay", "responsive_voice", "yandex", "polly"
|
// "spdsay", "responsive_voice", "yandex", "polly", "mozilla"
|
||||||
"pulse_duck": false,
|
"pulse_duck": false,
|
||||||
"module": "mimic",
|
"module": "mimic",
|
||||||
"polly": {
|
"polly": {
|
||||||
|
@ -306,6 +306,10 @@
|
||||||
"espeak": {
|
"espeak": {
|
||||||
"lang": "english-us",
|
"lang": "english-us",
|
||||||
"voice": "m1"
|
"voice": "m1"
|
||||||
|
},
|
||||||
|
"mozilla": {
|
||||||
|
"lang": "de",
|
||||||
|
"url": "http://10.0.0.1:5002/api/tts?text="
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
# Copyright 2020 Mycroft AI Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
import hashlib
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from .tts import TTS, TTSValidator
|
||||||
|
from .remote_tts import RemoteTTSException, RemoteTTSTimeoutException
|
||||||
|
from mycroft.util.log import LOG
|
||||||
|
from mycroft.tts import cache_handler
|
||||||
|
from mycroft.util import get_cache_directory
|
||||||
|
from requests_futures.sessions import FuturesSession
|
||||||
|
from requests.exceptions import (
|
||||||
|
ReadTimeout, ConnectionError, ConnectTimeout, HTTPError
|
||||||
|
)
|
||||||
|
from urllib import parse
|
||||||
|
from .mimic_tts import VISIMES
|
||||||
|
import math
|
||||||
|
import base64
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class MozillaTTS(TTS):
|
||||||
|
def __init__(self, lang="en-us", config=None):
|
||||||
|
config = config or Configuration.get().get("tts", {}).get("mozilla", {})
|
||||||
|
super(MozillaTTS, self).__init__(lang, config, MozillaTTSValidator(self))
|
||||||
|
self.url = config['url']
|
||||||
|
self.type = 'wav'
|
||||||
|
|
||||||
|
def get_tts(self, sentence, wav_file):
|
||||||
|
wav_name = hashlib.sha1(sentence.encode('utf-8')).hexdigest() + ".wav"
|
||||||
|
wav_file = "/tmp/" + wav_name
|
||||||
|
if os.path.exists(wav_file) and os.path.getsize(wav_file) > 0:
|
||||||
|
LOG.info('local response wav found.')
|
||||||
|
else:
|
||||||
|
req_route = self.url + sentence
|
||||||
|
response = requests.get(req_route)
|
||||||
|
with open(wav_file, 'wb') as f:
|
||||||
|
f.write(response.content)
|
||||||
|
return (wav_file, None) # No phonemes
|
||||||
|
|
||||||
|
|
||||||
|
class MozillaTTSValidator(TTSValidator):
|
||||||
|
def __init__(self, tts):
|
||||||
|
super(MozillaTTSValidator, self).__init__(tts)
|
||||||
|
|
||||||
|
def validate_dependencies(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def validate_lang(self):
|
||||||
|
# TODO
|
||||||
|
pass
|
||||||
|
|
||||||
|
def validate_connection(self):
|
||||||
|
# TODO
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_tts_class(self):
|
||||||
|
return MozillaTTS
|
|
@ -479,6 +479,7 @@ class TTSFactory:
|
||||||
from mycroft.tts.yandex_tts import YandexTTS
|
from mycroft.tts.yandex_tts import YandexTTS
|
||||||
from mycroft.tts.dummy_tts import DummyTTS
|
from mycroft.tts.dummy_tts import DummyTTS
|
||||||
from mycroft.tts.polly_tts import PollyTTS
|
from mycroft.tts.polly_tts import PollyTTS
|
||||||
|
from mycroft.tts.mozilla_tts import MozillaTTS
|
||||||
|
|
||||||
CLASSES = {
|
CLASSES = {
|
||||||
"mimic": Mimic,
|
"mimic": Mimic,
|
||||||
|
@ -494,6 +495,7 @@ class TTSFactory:
|
||||||
"responsive_voice": ResponsiveVoice,
|
"responsive_voice": ResponsiveVoice,
|
||||||
"yandex": YandexTTS,
|
"yandex": YandexTTS,
|
||||||
"polly": PollyTTS,
|
"polly": PollyTTS,
|
||||||
|
"mozilla": MozillaTTS,
|
||||||
"dummy": DummyTTS
|
"dummy": DummyTTS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue