Make sure that we set the credential files environment variable

This commit is contained in:
Fabio Manganiello 2018-10-14 10:45:25 +02:00
parent c640093139
commit b6fcdf75f4

View file

@ -1,3 +1,4 @@
import os
import subprocess import subprocess
import tempfile import tempfile
@ -17,7 +18,8 @@ class TtsGooglePlugin(Plugin):
* **mplayer** - see your distribution docs on how to install the mplayer package * **mplayer** - see your distribution docs on how to install the mplayer package
""" """
def __init__(self, language='en-US', voice='en-US-Wavenet-C', gender='FEMALE'): def __init__(self, language='en-US', voice='en-US-Wavenet-C',
gender='FEMALE', credentials_file='~/.credentials/platypush/google/platypush-tts.json'):
""" """
:param language: Language code, see https://cloud.google.com/text-to-speech/docs/basics for supported languages :param language: Language code, see https://cloud.google.com/text-to-speech/docs/basics for supported languages
:type language: str :type language: str
@ -27,12 +29,16 @@ class TtsGooglePlugin(Plugin):
:param gender: Voice gender (MALE, FEMALE or NEUTRAL) :param gender: Voice gender (MALE, FEMALE or NEUTRAL)
:type gender: str :type gender: str
:param credentials_file: Where your GCloud credentials for TTS are stored, see https://cloud.google.com/text-to-speech/docs/basics
:type credentials_file: str
""" """
super().__init__() super().__init__()
self.language = language self.language = language
self.voice = voice self.voice = voice
self.gender = getattr(texttospeech.enums.SsmlVoiceGender, gender.upper()) self.gender = getattr(texttospeech.enums.SsmlVoiceGender, gender.upper())
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = os.path.expanduser(credentials_file)
@action @action
def say(self, text, language=None, voice=None, gender=None): def say(self, text, language=None, voice=None, gender=None):