Merge pull request #2514 from MycroftAI/bugfix/watson-tts
Add configurable API url to Watson TTS along with ability to opt out of data collection.pull/2515/head
commit
13defa162a
|
@ -23,13 +23,17 @@ class WatsonTTS(RemoteTTS):
|
|||
PARAMS = {'accept': 'audio/wav'}
|
||||
|
||||
def __init__(self, lang, config,
|
||||
url="https://stream.watsonplatform.net/text-to-speech/api"):
|
||||
super(WatsonTTS, self).__init__(lang, config, url, '/v1/synthesize',
|
||||
url='https://stream.watsonplatform.net/text-to-speech/api',
|
||||
api_path='/v1/synthesize'):
|
||||
super(WatsonTTS, self).__init__(lang, config, url, api_path,
|
||||
WatsonTTSValidator(self))
|
||||
self.type = "wav"
|
||||
user = self.config.get("user") or self.config.get("username")
|
||||
password = self.config.get("password")
|
||||
api_key = self.config.get("apikey")
|
||||
if self.url.endswith(api_path):
|
||||
self.url = self.url[:-len(api_path)]
|
||||
|
||||
if api_key is None:
|
||||
self.auth = HTTPBasicAuth(user, password)
|
||||
else:
|
||||
|
@ -39,6 +43,8 @@ class WatsonTTS(RemoteTTS):
|
|||
params = self.PARAMS.copy()
|
||||
params['LOCALE'] = self.lang
|
||||
params['voice'] = self.voice
|
||||
params['X-Watson-Learning-Opt-Out'] = self.config.get(
|
||||
'X-Watson-Learning-Opt-Out', 'true')
|
||||
params['text'] = sentence.encode('utf-8')
|
||||
return params
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import re
|
|||
from requests_futures.sessions import FuturesSession
|
||||
|
||||
from .tts import TTS
|
||||
from mycroft.util import remove_last_slash, play_wav
|
||||
from mycroft.util import play_wav
|
||||
from mycroft.util.log import LOG
|
||||
|
||||
|
||||
|
@ -41,7 +41,7 @@ class RemoteTTS(TTS):
|
|||
super(RemoteTTS, self).__init__(lang, config, validator)
|
||||
self.api_path = api_path
|
||||
self.auth = None
|
||||
self.url = remove_last_slash(url)
|
||||
self.url = config.get('url', url).rstrip('/')
|
||||
self.session = FuturesSession()
|
||||
|
||||
def execute(self, sentence, ident=None, listen=False):
|
||||
|
|
Loading…
Reference in New Issue