mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 01:07:10 +00:00
Set amazon polly network timeout settings (#44185)
* Change network timeout settings * Change network timeout settings
This commit is contained in:
parent
b7d4c1826c
commit
af6dd698c9
@ -2,6 +2,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
|
import botocore
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.tts import PLATFORM_SCHEMA, Provider
|
from homeassistant.components.tts import PLATFORM_SCHEMA, Provider
|
||||||
@ -125,6 +126,10 @@ DEFAULT_TEXT_TYPE = "text"
|
|||||||
|
|
||||||
DEFAULT_SAMPLE_RATES = {"mp3": "22050", "ogg_vorbis": "22050", "pcm": "16000"}
|
DEFAULT_SAMPLE_RATES = {"mp3": "22050", "ogg_vorbis": "22050", "pcm": "16000"}
|
||||||
|
|
||||||
|
AWS_CONF_CONNECT_TIMEOUT = 10
|
||||||
|
AWS_CONF_READ_TIMEOUT = 5
|
||||||
|
AWS_CONF_MAX_POOL_CONNECTIONS = 1
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
vol.Optional(CONF_REGION, default=DEFAULT_REGION): vol.In(SUPPORTED_REGIONS),
|
vol.Optional(CONF_REGION, default=DEFAULT_REGION): vol.In(SUPPORTED_REGIONS),
|
||||||
@ -167,6 +172,11 @@ def get_engine(hass, config, discovery_info=None):
|
|||||||
CONF_REGION: config[CONF_REGION],
|
CONF_REGION: config[CONF_REGION],
|
||||||
CONF_ACCESS_KEY_ID: config.get(CONF_ACCESS_KEY_ID),
|
CONF_ACCESS_KEY_ID: config.get(CONF_ACCESS_KEY_ID),
|
||||||
CONF_SECRET_ACCESS_KEY: config.get(CONF_SECRET_ACCESS_KEY),
|
CONF_SECRET_ACCESS_KEY: config.get(CONF_SECRET_ACCESS_KEY),
|
||||||
|
"config": botocore.config.Config(
|
||||||
|
connect_timeout=AWS_CONF_CONNECT_TIMEOUT,
|
||||||
|
read_timeout=AWS_CONF_READ_TIMEOUT,
|
||||||
|
max_pool_connections=AWS_CONF_MAX_POOL_CONNECTIONS,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
del config[CONF_REGION]
|
del config[CONF_REGION]
|
||||||
@ -229,6 +239,7 @@ class AmazonPollyProvider(Provider):
|
|||||||
_LOGGER.error("%s does not support the %s language", voice_id, language)
|
_LOGGER.error("%s does not support the %s language", voice_id, language)
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
_LOGGER.debug("Requesting TTS file for text: %s", message)
|
||||||
resp = self.client.synthesize_speech(
|
resp = self.client.synthesize_speech(
|
||||||
Engine=self.config[CONF_ENGINE],
|
Engine=self.config[CONF_ENGINE],
|
||||||
OutputFormat=self.config[CONF_OUTPUT_FORMAT],
|
OutputFormat=self.config[CONF_OUTPUT_FORMAT],
|
||||||
@ -238,6 +249,7 @@ class AmazonPollyProvider(Provider):
|
|||||||
VoiceId=voice_id,
|
VoiceId=voice_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_LOGGER.debug("Reply received for TTS: %s", message)
|
||||||
return (
|
return (
|
||||||
CONTENT_TYPE_EXTENSIONS[resp.get("ContentType")],
|
CONTENT_TYPE_EXTENSIONS[resp.get("ContentType")],
|
||||||
resp.get("AudioStream").read(),
|
resp.get("AudioStream").read(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user