mirror of
https://github.com/home-assistant/core.git
synced 2025-08-18 12:02:07 +02:00
Fixed some ci/circleci: pylint errors
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
"""Support for the Google Cloud TTS service."""
|
"""Support for the Google Cloud TTS service."""
|
||||||
import logging
|
|
||||||
import async_timeout
|
|
||||||
import voluptuous as vol
|
|
||||||
import os
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.components.tts import CONF_LANG, PLATFORM_SCHEMA, Provider
|
|
||||||
|
|
||||||
from google.cloud import texttospeech
|
from google.cloud import texttospeech
|
||||||
|
from homeassistant.components.tts import CONF_LANG, PLATFORM_SCHEMA, Provider
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import async_timeout
|
||||||
|
import asyncio
|
||||||
|
import voluptuous as vol
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -87,33 +87,36 @@ class GoogleCloudTTSProvider(Provider):
|
|||||||
"""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
|
_language = language or self._lang
|
||||||
voice = self._voice
|
_gender = self._gender
|
||||||
|
_voice = self._voice
|
||||||
if options:
|
if options:
|
||||||
if CONF_GENDER in options:
|
if CONF_GENDER in options:
|
||||||
gender = options[CONF_GENDER].lower().capitalize()
|
_gender = options[CONF_GENDER].lower().capitalize()
|
||||||
if CONF_VOICE in options:
|
if CONF_VOICE in options:
|
||||||
voice = options[CONF_VOICE]
|
_voice = options[CONF_VOICE]
|
||||||
self.voice = texttospeech.types.VoiceSelectionParams(
|
voice = texttospeech.types.VoiceSelectionParams(
|
||||||
language_code=language or self._lang,
|
language_code=_language,
|
||||||
name=voice,
|
|
||||||
ssml_gender={
|
ssml_gender={
|
||||||
'Neutral': texttospeech.enums.SsmlVoiceGender.NEUTRAL,
|
'Neutral': texttospeech.enums.SsmlVoiceGender.NEUTRAL,
|
||||||
'Female': texttospeech.enums.SsmlVoiceGender.FEMALE,
|
'Female': texttospeech.enums.SsmlVoiceGender.FEMALE,
|
||||||
'Male': texttospeech.enums.SsmlVoiceGender.MALE,
|
'Male': texttospeech.enums.SsmlVoiceGender.MALE,
|
||||||
}.get(gender, DEFAULT_GENDER)
|
}.get(_gender, DEFAULT_GENDER),
|
||||||
|
name=_voice
|
||||||
)
|
)
|
||||||
synthesis_input = texttospeech.types.SynthesisInput(
|
synthesis_input = texttospeech.types.SynthesisInput(
|
||||||
text=message
|
text=message
|
||||||
)
|
)
|
||||||
response = self.client.synthesize_speech(
|
response = self.client.synthesize_speech(
|
||||||
synthesis_input,
|
synthesis_input,
|
||||||
self.voice,
|
voice,
|
||||||
self.audio_config
|
self.audio_config
|
||||||
)
|
)
|
||||||
|
|
||||||
return "mp3", response.audio_content
|
return "mp3", response.audio_content
|
||||||
|
|
||||||
except Exception as e:
|
except asyncio.TimeoutError as ex:
|
||||||
_LOGGER.error("Timeout for google speech or other problem.", e)
|
_LOGGER.error("Timeout for Google Cloud TTS: %s", ex)
|
||||||
|
except Exception as ex:
|
||||||
|
_LOGGER.error("Error occured during Google Cloud TTS call: %s", ex)
|
||||||
|
|
||||||
return None, None
|
return None, None
|
||||||
|
Reference in New Issue
Block a user