ang3/aws-polly-bundle

AWS Polly bundle for Symfony apps

v1.0.0 2023-02-01 15:52 UTC

This package is auto-updated.

Last update: 2024-04-09 11:31:01 UTC


README

Code Quality PHPUnit Tests Symfony Bundle Latest Stable Version Latest Unstable Version Total Downloads

This bundle integrates AWS Polly to your project. It installs the AWS SDK for PHP for the client and the AsyncAws Bundle for credentials.

Features

  • Client
  • Speech synthesizer

Installation

Step 1: Download the Bundle

Open a command console, enter your app directory and execute the following command to download the latest stable version of this bundle:

composer require ang3/aws-polly-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Configure the bundle

Make sure you have configured the bundle AsyncAws, especially for authentication.

Create the file config/packages/ang3_aws_polly.yaml, and add the contents below:

# config/packages/ang3_aws_polly.yaml
ang3_aws_polly:
  region: 'YOUR_REGION'

Make sure to replace YOUR_REGION by your AWS settings.

Be aware some voices are available only on specific regions or engine. Please refer to the AWS documentation.

Usage

Client

Public service ID: ang3.aws_polly.client

To use the Polly client, get it by dependency injection:

namespace App\Service;

use Aws\Polly\PollyClient;

class MyService
{
    public function __construct(private PollyClient $client)
    {
    }
}

Speech synthesizer

Public service ID: ang3.aws_polly.speech_synthesizer

To synthesize a speech, use dependency injection:

namespace App\Service;

use Ang3\Bundle\AwsBundle\Service\SpeechSynthesizer;

class MyService
{
    public function __construct(private SpeechSynthesizer $speechSynthesizer)
    {
    }
}

Then, synthesize a speech with your text (mp3):

use Ang3\Bundle\AwsPollyBundle\Enum\Voice;

/** @var \Ang3\Bundle\AwsBundle\Service\SpeechSynthesizer $speechSynthesizer */

$audioFileUrl = $speechSynthesizer->create('Hello world!', Voice::AMY);

The function returns a secured URL to the MP3 file.

That's it!