Update google-cloud-texttospeech to 2.10.0 (#66746)

This commit is contained in:
Franck Nijhof 2022-03-01 10:19:13 +01:00 committed by GitHub
parent e4c62a2037
commit 82948cc6c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 36 deletions

View File

@ -2,7 +2,7 @@
"domain": "google_cloud", "domain": "google_cloud",
"name": "Google Cloud Platform", "name": "Google Cloud Platform",
"documentation": "https://www.home-assistant.io/integrations/google_cloud", "documentation": "https://www.home-assistant.io/integrations/google_cloud",
"requirements": ["google-cloud-texttospeech==0.4.0"], "requirements": ["google-cloud-texttospeech==2.10.0"],
"codeowners": ["@lufton"], "codeowners": ["@lufton"],
"iot_class": "cloud_push" "iot_class": "cloud_push"
} }

View File

@ -122,13 +122,9 @@ SUPPORTED_OPTIONS = [
CONF_TEXT_TYPE, CONF_TEXT_TYPE,
] ]
GENDER_SCHEMA = vol.All( GENDER_SCHEMA = vol.All(vol.Upper, vol.In(texttospeech.SsmlVoiceGender.__members__))
vol.Upper, vol.In(texttospeech.enums.SsmlVoiceGender.__members__)
)
VOICE_SCHEMA = cv.matches_regex(VOICE_REGEX) VOICE_SCHEMA = cv.matches_regex(VOICE_REGEX)
SCHEMA_ENCODING = vol.All( SCHEMA_ENCODING = vol.All(vol.Upper, vol.In(texttospeech.AudioEncoding.__members__))
vol.Upper, vol.In(texttospeech.enums.AudioEncoding.__members__)
)
SPEED_SCHEMA = vol.All(vol.Coerce(float), vol.Clamp(min=MIN_SPEED, max=MAX_SPEED)) SPEED_SCHEMA = vol.All(vol.Coerce(float), vol.Clamp(min=MIN_SPEED, max=MAX_SPEED))
PITCH_SCHEMA = vol.All(vol.Coerce(float), vol.Clamp(min=MIN_PITCH, max=MAX_PITCH)) PITCH_SCHEMA = vol.All(vol.Coerce(float), vol.Clamp(min=MIN_PITCH, max=MAX_PITCH))
GAIN_SCHEMA = vol.All(vol.Coerce(float), vol.Clamp(min=MIN_GAIN, max=MAX_GAIN)) GAIN_SCHEMA = vol.All(vol.Coerce(float), vol.Clamp(min=MIN_GAIN, max=MAX_GAIN))
@ -263,27 +259,32 @@ class GoogleCloudTTSProvider(Provider):
try: try:
params = {options[CONF_TEXT_TYPE]: message} params = {options[CONF_TEXT_TYPE]: message}
# pylint: disable=no-member synthesis_input = texttospeech.SynthesisInput(**params)
synthesis_input = texttospeech.types.SynthesisInput(**params)
voice = texttospeech.types.VoiceSelectionParams( voice = texttospeech.VoiceSelectionParams(
language_code=language, language_code=language,
ssml_gender=texttospeech.enums.SsmlVoiceGender[options[CONF_GENDER]], ssml_gender=texttospeech.SsmlVoiceGender[options[CONF_GENDER]],
name=_voice, name=_voice,
) )
audio_config = texttospeech.types.AudioConfig( audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.enums.AudioEncoding[_encoding], audio_encoding=texttospeech.AudioEncoding[_encoding],
speaking_rate=options[CONF_SPEED], speaking_rate=options[CONF_SPEED],
pitch=options[CONF_PITCH], pitch=options[CONF_PITCH],
volume_gain_db=options[CONF_GAIN], volume_gain_db=options[CONF_GAIN],
effects_profile_id=options[CONF_PROFILES], effects_profile_id=options[CONF_PROFILES],
) )
# pylint: enable=no-member
request = {
"voice": voice,
"audio_config": audio_config,
"input": synthesis_input,
}
async with async_timeout.timeout(10): async with async_timeout.timeout(10):
assert self.hass
response = await self.hass.async_add_executor_job( response = await self.hass.async_add_executor_job(
self._client.synthesize_speech, synthesis_input, voice, audio_config self._client.synthesize_speech, request
) )
return _encoding, response.audio_content return _encoding, response.audio_content

View File

@ -6,7 +6,7 @@ import json
import logging import logging
import os import os
from google.cloud import pubsub_v1 from google.cloud.pubsub_v1 import PublisherClient
import voluptuous as vol import voluptuous as vol
from homeassistant.const import EVENT_STATE_CHANGED, STATE_UNAVAILABLE, STATE_UNKNOWN from homeassistant.const import EVENT_STATE_CHANGED, STATE_UNAVAILABLE, STATE_UNKNOWN
@ -52,9 +52,7 @@ def setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool:
entities_filter = config[CONF_FILTER] entities_filter = config[CONF_FILTER]
publisher = pubsub_v1.PublisherClient.from_service_account_json( publisher = PublisherClient.from_service_account_json(service_principal_path)
service_principal_path
)
topic_path = publisher.topic_path( # pylint: disable=no-member topic_path = publisher.topic_path( # pylint: disable=no-member
project_id, topic_name project_id, topic_name

View File

@ -719,7 +719,7 @@ google-api-python-client==2.38.0
google-cloud-pubsub==2.9.0 google-cloud-pubsub==2.9.0
# homeassistant.components.google_cloud # homeassistant.components.google_cloud
google-cloud-texttospeech==0.4.0 google-cloud-texttospeech==2.10.0
# homeassistant.components.nest # homeassistant.components.nest
google-nest-sdm==1.7.1 google-nest-sdm==1.7.1

View File

@ -3,7 +3,7 @@ PIP_CACHE=$1
# Number of existing dependency conflicts # Number of existing dependency conflicts
# Update if a PR resolve one! # Update if a PR resolve one!
DEPENDENCY_CONFLICTS=6 DEPENDENCY_CONFLICTS=5
PIP_CHECK=$(pip check --cache-dir=$PIP_CACHE) PIP_CHECK=$(pip check --cache-dir=$PIP_CACHE)
LINE_COUNT=$(echo "$PIP_CHECK" | wc -l) LINE_COUNT=$(echo "$PIP_CHECK" | wc -l)

View File

@ -42,10 +42,9 @@ async def test_nested():
@pytest.fixture(autouse=True, name="mock_client") @pytest.fixture(autouse=True, name="mock_client")
def mock_client_fixture(): def mock_client_fixture():
"""Mock the pubsub client.""" """Mock the pubsub client."""
with mock.patch(f"{GOOGLE_PUBSUB_PATH}.pubsub_v1") as client: with mock.patch(f"{GOOGLE_PUBSUB_PATH}.PublisherClient") as client:
client.PublisherClient = mock.MagicMock()
setattr( setattr(
client.PublisherClient, client,
"from_service_account_json", "from_service_account_json",
mock.MagicMock(return_value=mock.MagicMock()), mock.MagicMock(return_value=mock.MagicMock()),
) )
@ -83,10 +82,10 @@ async def test_minimal_config(hass, mock_client):
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.bus.listen.called assert hass.bus.listen.called
assert hass.bus.listen.call_args_list[0][0][0] == EVENT_STATE_CHANGED assert hass.bus.listen.call_args_list[0][0][0] == EVENT_STATE_CHANGED
assert mock_client.PublisherClient.from_service_account_json.call_count == 1 assert mock_client.from_service_account_json.call_count == 1
assert mock_client.PublisherClient.from_service_account_json.call_args[0][ assert mock_client.from_service_account_json.call_args[0][0] == os.path.join(
0 hass.config.config_dir, "creds"
] == os.path.join(hass.config.config_dir, "creds") )
async def test_full_config(hass, mock_client): async def test_full_config(hass, mock_client):
@ -110,10 +109,10 @@ async def test_full_config(hass, mock_client):
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.bus.listen.called assert hass.bus.listen.called
assert hass.bus.listen.call_args_list[0][0][0] == EVENT_STATE_CHANGED assert hass.bus.listen.call_args_list[0][0][0] == EVENT_STATE_CHANGED
assert mock_client.PublisherClient.from_service_account_json.call_count == 1 assert mock_client.from_service_account_json.call_count == 1
assert mock_client.PublisherClient.from_service_account_json.call_args[0][ assert mock_client.from_service_account_json.call_args[0][0] == os.path.join(
0 hass.config.config_dir, "creds"
] == os.path.join(hass.config.config_dir, "creds") )
def make_event(entity_id): def make_event(entity_id):
@ -154,7 +153,7 @@ async def test_allowlist(hass, mock_client):
"include_entities": ["binary_sensor.included"], "include_entities": ["binary_sensor.included"],
}, },
) )
publish_client = mock_client.PublisherClient.from_service_account_json("path") publish_client = mock_client.from_service_account_json("path")
tests = [ tests = [
FilterTest("climate.excluded", False), FilterTest("climate.excluded", False),
@ -184,7 +183,7 @@ async def test_denylist(hass, mock_client):
"exclude_entities": ["binary_sensor.excluded"], "exclude_entities": ["binary_sensor.excluded"],
}, },
) )
publish_client = mock_client.PublisherClient.from_service_account_json("path") publish_client = mock_client.from_service_account_json("path")
tests = [ tests = [
FilterTest("climate.excluded", False), FilterTest("climate.excluded", False),
@ -216,7 +215,7 @@ async def test_filtered_allowlist(hass, mock_client):
"exclude_entities": ["light.excluded"], "exclude_entities": ["light.excluded"],
}, },
) )
publish_client = mock_client.PublisherClient.from_service_account_json("path") publish_client = mock_client.from_service_account_json("path")
tests = [ tests = [
FilterTest("light.included", True), FilterTest("light.included", True),
@ -246,7 +245,7 @@ async def test_filtered_denylist(hass, mock_client):
"exclude_entities": ["light.excluded"], "exclude_entities": ["light.excluded"],
}, },
) )
publish_client = mock_client.PublisherClient.from_service_account_json("path") publish_client = mock_client.from_service_account_json("path")
tests = [ tests = [
FilterTest("climate.excluded", False), FilterTest("climate.excluded", False),