in tts/src/tts/amazonpolly.py [0:0]
def _get_polly_client(self, aws_access_key_id=None, aws_secret_access_key=None, aws_session_token=None,
region_name=None, with_service_model_patch=False):
"""Note we get a new botocore session each time this function is called.
This is to avoid potential problems caused by inner state of the session.
"""
botocore_session = get_session()
if with_service_model_patch:
# Older versions of botocore don't have polly. We can possibly fix it by appending
# extra path with polly service model files to the search path.
current_dir = os.path.dirname(os.path.abspath(__file__))
service_model_path = os.path.join(current_dir, 'data', 'models')
botocore_session.set_config_variable('data_path', service_model_path)
rospy.loginfo('patching service model data path: {}'.format(service_model_path))
botocore_session.get_component('credential_provider').insert_after('boto-config', AwsIotCredentialProvider())
botocore_session.user_agent_extra = self._generate_user_agent_suffix()
session = Session(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key,
aws_session_token=aws_session_token, region_name=region_name,
botocore_session=botocore_session)
try:
return session.client("polly")
except UnknownServiceError:
# the first time we reach here, we try to fix the problem
if not with_service_model_patch:
return self._get_polly_client(aws_access_key_id, aws_secret_access_key, aws_session_token, region_name,
with_service_model_patch=True)
else:
# we have tried our best, time to panic
rospy.logerr('Amazon Polly is not available. Please install the latest boto3.')
raise