mirror of
https://github.com/home-assistant/core.git
synced 2025-08-24 15:01:36 +02:00
Fixed some ci/circleci: static-check errors
This commit is contained in:
@@ -33,6 +33,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
vol.Optional(CONF_KEY_FILE, default=''): cv.string,
|
vol.Optional(CONF_KEY_FILE, default=''): cv.string,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
async def async_get_engine(hass, config):
|
async def async_get_engine(hass, config):
|
||||||
"""Set up Google Cloud TTS component."""
|
"""Set up Google Cloud TTS component."""
|
||||||
return GoogleCloudTTSProvider(
|
return GoogleCloudTTSProvider(
|
||||||
@@ -57,8 +58,9 @@ class GoogleCloudTTSProvider(Provider):
|
|||||||
path = hass.config.path(key_file)
|
path = hass.config.path(key_file)
|
||||||
if key_file and os.path.isfile(path):
|
if key_file and os.path.isfile(path):
|
||||||
os.environ[GOOGLE_APPLICATION_CREDENTIALS] = path
|
os.environ[GOOGLE_APPLICATION_CREDENTIALS] = path
|
||||||
if not GOOGLE_APPLICATION_CREDENTIALS in os.environ:
|
if GOOGLE_APPLICATION_CREDENTIALS not in os.environ:
|
||||||
_LOGGER.error("You need to specify valid GOOGLE_APPLICATION_CREDENTIALS file location.")
|
_LOGGER.error("You need to specify valid"
|
||||||
|
" GOOGLE_APPLICATION_CREDENTIALS file location.")
|
||||||
self.client = texttospeech.TextToSpeechClient()
|
self.client = texttospeech.TextToSpeechClient()
|
||||||
self.audio_config = texttospeech.types.AudioConfig(
|
self.audio_config = texttospeech.types.AudioConfig(
|
||||||
audio_encoding=texttospeech.enums.AudioEncoding.MP3
|
audio_encoding=texttospeech.enums.AudioEncoding.MP3
|
||||||
@@ -81,7 +83,6 @@ class GoogleCloudTTSProvider(Provider):
|
|||||||
|
|
||||||
async def async_get_tts_audio(self, message, language, options=None):
|
async def async_get_tts_audio(self, message, language, options=None):
|
||||||
"""Load TTS from google."""
|
"""Load TTS from google."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with async_timeout.timeout(10, loop=self.hass.loop):
|
with async_timeout.timeout(10, loop=self.hass.loop):
|
||||||
gender = self._gender
|
gender = self._gender
|
||||||
@@ -94,14 +95,15 @@ class GoogleCloudTTSProvider(Provider):
|
|||||||
self.voice = texttospeech.types.VoiceSelectionParams(
|
self.voice = texttospeech.types.VoiceSelectionParams(
|
||||||
language_code=language or self._lang,
|
language_code=language or self._lang,
|
||||||
name=voice,
|
name=voice,
|
||||||
ssml_gender=
|
ssml_gender={
|
||||||
texttospeech.enums.SsmlVoiceGender.NEUTRAL if gender==GENDERS[0] else
|
'Neutral': texttospeech.enums.SsmlVoiceGender.NEUTRAL,
|
||||||
(
|
'Female': texttospeech.enums.SsmlVoiceGender.FEMALE,
|
||||||
texttospeech.enums.SsmlVoiceGender.FEMALE if gender==GENDERS[1] else
|
'Male': texttospeech.enums.SsmlVoiceGender.MALE,
|
||||||
texttospeech.enums.SsmlVoiceGender.MALE
|
}.get(gender, DEFAULT_GENDER)
|
||||||
)
|
)
|
||||||
|
synthesis_input = texttospeech.types.SynthesisInput(
|
||||||
|
text=message
|
||||||
)
|
)
|
||||||
synthesis_input = texttospeech.types.SynthesisInput(text=message)
|
|
||||||
response = self.client.synthesize_speech(
|
response = self.client.synthesize_speech(
|
||||||
synthesis_input,
|
synthesis_input,
|
||||||
self.voice,
|
self.voice,
|
||||||
@@ -111,5 +113,5 @@ class GoogleCloudTTSProvider(Provider):
|
|||||||
return "mp3", response.audio_content
|
return "mp3", response.audio_content
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_LOGGER.error("Timeout for google speech or some other problem.", e)
|
_LOGGER.error("Timeout for google speech or other problem.", e)
|
||||||
return None, None
|
return None, None
|
||||||
|
Reference in New Issue
Block a user