ang3 / aws-polly-bundle
AWS Polly bundle for Symfony apps
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=8.1
- async-aws/async-aws-bundle: ^1.10
- aws/aws-sdk-php: ^3.129
- symfony/config: ^6.0
- symfony/dependency-injection: ^6.0
- symfony/http-kernel: ^6.0
Requires (Dev)
- symfony/test-pack: ^1.0
README
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!