HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/buyercall/lib/util_boto3_polly.py
import boto3


class AwsPolly():
    polly_client = None

    def __init__(self, config):
        self.polly_client = boto3.Session(
            aws_access_key_id=config['access_key'],
            aws_secret_access_key=config['secret_key'],
            region_name=config['region']).client('polly')

    def synthesize_speech(self, voice_id='Joanna',
                          output_format='mp3',
                          text='',
                          engine='standard'):
        response = self.polly_client.synthesize_speech(
            VoiceId=voice_id, OutputFormat=output_format, Text=text, Engine=engine)

        return response

    def start_speech_synthesis_task(self):
        response = self.polly_client.start_speech_synthesis_task(VoiceId='Joanna',
                                                                 OutputS3BucketName='synth-books-buckets',
                                                                 OutputS3KeyPrefix='key',
                                                                 OutputFormat='mp3',
                                                                 Text='This is a sample text to be synthesized.',
                                                                 Engine='neural')
        taskId = response['SynthesisTask']['TaskId']
        return taskId

    def get_speech_synthesis_task(self, task_id):
        task_status = self.polly_client.get_speech_synthesis_task(TaskId=task_id)
        return task_status