PHPackages                             ahmadmayahi/php-amazon-polly - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ahmadmayahi/php-amazon-polly

ActiveLibrary[API Development](/categories/api)

ahmadmayahi/php-amazon-polly
============================

An elegant wrapper around Amazon Polly

v1.2.0(3y ago)108401[2 PRs](https://github.com/ahmadmayahi/php-amazon-polly/pulls)MITPHPPHP ^8.1

Since Dec 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ahmadmayahi/php-amazon-polly)[ Packagist](https://packagist.org/packages/ahmadmayahi/php-amazon-polly)[ Docs](https://github.com/ahmadmayahi/php-amazon-polly)[ GitHub Sponsors](https://github.com/AhmadMayahi)[ RSS](/packages/ahmadmayahi-php-amazon-polly/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (13)Used By (0)

 [![PHP Google Vision](art/logo.png)](art/logo.png)---

[![The Latest Version on Packagist](https://camo.githubusercontent.com/ebeff693c2fdf71a248a1aab429f6e64af1ec0e9bb51fbb8e24a01b24232259d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61686d61646d61796168692f7068702d616d617a6f6e2d706f6c6c792e737667)](https://packagist.org/packages/ahmadmayahi/php-amazon-polly)[![Tests](https://github.com/ahmadmayahi/php-amazon-polly/actions/workflows/run-tests.yml/badge.svg)](https://github.com/ahmadmayahi/php-amazon-polly/actions/workflows/run-tests.yml)[![Check & fix styling](https://github.com/ahmadmayahi/php-amazon-polly/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/ahmadmayahi/php-amazon-polly/actions/workflows/php-cs-fixer.yml)[![Test Coverage](https://camo.githubusercontent.com/9f941054042db703af9dbacd7aab00e837a85f0c4889734c6c637b0ac494ba71/68747470733a2f2f636f6465636f762e696f2f67682f61686d61646d61796168692f7068702d616d617a6f6e2d706f6c6c792f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d6861794d796e38744c49)](https://codecov.io/gh/ahmadmayahi/php-amazon-polly)

---

**Requires PHP 8.1+**

For feedback, please [contact me](https://form.jotform.com/201892949858375).

**PHP Amazon Polly** is an easy and elegant wrapper around [Amazon Polly](https://aws.amazon.com/polly/), a service that turns text into lifelike speech.

Contents
========

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
- [Standard vs Neural Voices](#standard-vs-neural-voices)
- [Convenient Voice Methods](#convenient-voice-methods)
- [Speech Marks](#speech-marks)
- [SSML](#ssml)
- [Voice Enums](#voice-enums)
    - [Describe Voice](#describe-voice)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require ahmadmayahi/php-amazon-polly
```

Usage
-----

[](#usage)

First you need to configure the client:

```
use AhmadMayahi\Polly\Config;

$config = (new Config())
    ->setKey('AWS_KEY')
    ->setSecret('AWS_SECRET')
    ->setRegion('eu-west-1'); // default is: us-east-1
```

Save as MP3 file:

```
use AhmadMayahi\Polly\Voices\English\UnitedStates;
use AhmadMayahi\Polly\Polly;

$polly = Polly::init($config);

$speechFile = $polly
    // Desired voice
    ->voiceId(UnitedStates::Joanna)

    // Default is MP3.
    // Available options: asMp3(), asOgg(), asPcm(), asJson()
    ->asOgg()

    // Desired Text
    ->text('Hello World')

    // Convert and return the object
    ->convert();
```

The `convert` method returns an object of type `AhmadMayahi\Polly\Data\SpeechFile` which has three properties:

- `file`: the output file as `SplFileObject`.
- `speechMarks` (if any).
- `took`: how long did it take to convert the text.

By default, the `convert` method saves the file into the default temp. directory; If you want to save the file into a specific directory then you might need to provide the file path as param:

```
convert('/path/to/desire/file/voice.mp3');
```

The `voiceId()` also accepts a string:

```
voiceId('Joanna')
```

Alternatively, you may also specify the output format as an `enum` or a `string`:

```
use AhmadMayahi\Polly\Enums\OutputFormat;
use AhmadMayahi\Polly\Polly;

$polly = Polly::init($config);

$speechFile = $polly
    ->voiceId(UnitedStates::Joanna)

    // As enum
    ->outputFormat(OutputFormat::Ogg)

    // Or as a string
    ->outputFormat('ogg')

    ->text('Hello World')

    ->convert();
```

Speech Marks
------------

[](#speech-marks)

You may also request the [Speech Mark Types](https://docs.aws.amazon.com/polly/latest/dg/speechmarks.html) as follows:

```
use AhmadMayahi\Polly\Enums\SpeechMarkType;
use AhmadMayahi\Polly\Voices\English\UnitedStates;
use AhmadMayahi\Polly\Polly;

$polly = Polly::init($config);

$speechFile = $polly
    ->voiceId(UnitedStates::Joanna)
    ->text('Hello World')
    ->withSpeechMarks(SpeechMarkType::Word, SpeechMarkType::Sentence)
    ->convert();
```

```
Array
(
    [0] => AhmadMayahi\Polly\Data\SpeechMark Object
        (
            [time] => 0
            [type] => AhmadMayahi\Polly\Enums\SpeechMarkType Enum:string
                (
                    [name] => Sentence
                    [value] => sentence
                )

            [start] => 7
            [end] => 18
            [value] => Hello World
        )

    [1] => AhmadMayahi\Polly\Data\SpeechMark Object
        (
            [time] => 6
            [type] => AhmadMayahi\Polly\Enums\SpeechMarkType Enum:string
                (
                    [name] => Word
                    [value] => word
                )

            [start] => 7
            [end] => 12
            [value] => Hello
        )

    [2] => AhmadMayahi\Polly\Data\SpeechMark Object
        (
            [time] => 273
            [type] => AhmadMayahi\Polly\Enums\SpeechMarkType Enum:string
                (
                    [name] => Word
                    [value] => word
                )

            [start] => 13
            [end] => 18
            [value] => World
        )
)
```

SSML
----

[](#ssml)

If the given text starts with `` then the `SSML` will be used while synthesizing:

```
use AhmadMayahi\Polly\Voices\English\UnitedStates;
use AhmadMayahi\Polly\Polly;

$text = convert();
```

> [Read more about SSML](https://docs.aws.amazon.com/polly/latest/dg/ssml.html).

Standard vs Neural Voices
-------------------------

[](#standard-vs-neural-voices)

[Amazon Polly](https://docs.aws.amazon.com/polly/) provides two voice systems `Standard` and `Neural`.

The `Neural` system can produce higher quality voices than the standard voices.

By default, this package will always use the `Standard` voice if available, however, some voices such as `Olivia` (English Australian) is only available as `Neural`.

You may use the `neuralVoice()` or `standardVoice()` methods as follows:

```
use AhmadMayahi\Polly\Voices\English\UnitedStates;
use AhmadMayahi\Polly\Polly;

$polly = Polly::init($config);

$speechFile = $polly
    ->voiceId(UnitedStates::Kendra)
    ->text('Hello World')
    ->neuralVoice()
    ->convert();
```

> Not all the voices support the `nueral` system, for more information please visit [Voices in Amazon Polly](https://docs.aws.amazon.com/polly/latest/dg/voicelist.html) page.

Convenient Voice Methods
------------------------

[](#convenient-voice-methods)

PHP Amazon Polly provides a convenient way to get the appropriate voice id without the need to inspect the documentation.

For example, if you want to use `Joanna` you may use `englishUnitedStatesJoanna()` method as follows:

```
use AhmadMayahi\Polly\Polly;

$polly = Polly::init($config);

$speechFile = $speech
    ->englishUnitedStatesJoanna($neural = true)
    ->text('Hello World')
    ->convert();
```

As you might have noticed, `Joanna` accepts an optional param `$neural`, set it to `true` if you want neural voice.

Here is the full list of voices with their equivalent method:

VoiceMethodArabic (Zeina)`arabicZeina()`Chinese (Zhiyu)`chineseZhiyu()`Danish (Naja)`danishNaja()`Danish (Mads)`danishMads()`Dutch (Lotte)`dutchLotte()`Dutch (Ruben)`dutchRuben()`English Australian (Nicole)`englishAustralianNicole()`English Australian (Olivia)`englishAustralianOlivia($neural = false)`English Australian (Russel)`englishAustralianRussel()`English British (Amy)`englishBritishAmy($neural = false)`English British (Brian)`englishBritishEmma($neural = false)`English Indian (Aditi)`englishIndianAditi()`English Indian (Raveena)`englishIndianRaveena()`English New Zealand (Aria)`englishNewZealandAria()`English South African (Ayanda)`englishSouthAfricanAyanda()`English United States (Ivy)`englishUnitedStatesIvy($neural = false)`English United States (Joanna)`englishUnitedStatesJoanna($neural = false)`English United States (Kendra)`englishUnitedStatesKendra($neural = false)`English United States (Kimberly)`englishUnitedStatesKimberly($neural = false)`English United States (Salli)`englishUnitedStatesSalli($neural = false)`English United States (Joey)`englishUnitedStatesJoey($neural = false)`English United States (Justin)`englishUnitedStatesJustin($neural = false)`English United States (Kevin)`englishUnitedStatesKevin($neural = false)`English United States (Matthew)`englishUnitedStatesMatthew($neural = false)`English Welsh (Geraint)`englishWelsh()`Voice Enums
-----------

[](#voice-enums)

All the [Amazon Polly Voices](https://docs.aws.amazon.com/polly/latest/dg/voicelist.html) are supported as enums:

LanguageEnumArabic`AhmadMayahi\Polly\Voices\Arabic`Chinese, Mandarin`AhmadMayahi\Polly\Voices\Chinese`Danish`AhmadMayahi\Polly\Voices\Danish`Dutch`AhmadMayahi\Polly\Voices\Dutch`English (Australian)`AhmadMayahi\Polly\Voices\English\Australian`English (British)`AhmadMayahi\Polly\Voices\English\British`English (Indian)`AhmadMayahi\Polly\Voices\English\Indian`English (New Zealand)`AhmadMayahi\Polly\Voices\English\NewZealand`English (South African)`AhmadMayahi\Polly\Voices\English\SouthAfrican`English (United States)`AhmadMayahi\Polly\Voices\English\UnitedStates`French`AhmadMayahi\Polly\Voices\French\French`French (Canadian)`AhmadMayahi\Polly\Voices\French\Canadian`German`AhmadMayahi\Polly\Voices\German`Hindi`AhmadMayahi\Polly\Voices\Hindi`Icelandic`AhmadMayahi\Polly\Voices\Icelandic`Italian`AhmadMayahi\Polly\Voices\Italian`Japanese`AhmadMayahi\Polly\Voices\Japanese`Korean`AhmadMayahi\Polly\Voices\Korean`Portuguese (Brazil)`AhmadMayahi\Polly\Voices\Portuguese\Brazil`Portuguese (Portugal)`AhmadMayahi\Polly\Voices\Portuguese\Portugal`Romanian`AhmadMayahi\Polly\Voices\Romanian`Russian`AhmadMayahi\Polly\Voices\Russian`Spanish (Mexican)`AhmadMayahi\Polly\Voices\Spanish\Mexico`Spanish (Spain)`AhmadMayahi\Polly\Voices\Spanish\Spain`Spanish (United States)`AhmadMayahi\Polly\Voices\Spanish\UnitedStates`Swedish`AhmadMayahi\Polly\Voices\Swedish`Turkish`AhmadMayahi\Polly\Voices\Turkish`Welsh`AhmadMayahi\Polly\Voices\Welsh`For example, if you want to get `Nicole` from English (Australian):

```
use AhmadMayahi\Polly\Voices\English\Australian;

Australian::Nicole;
```

### Describe Voice

[](#describe-voice)

You can also describe the voice using the `describe` method as follows:

```
use AhmadMayahi\Polly\Voices\English\Australian;

Australian::Nicole->describe();
```

The `describe` method returns an object of type `AhmadMayahi\Polly\Data\DescribeVoice` with the following properties:

- `gender`: Determines the voice's gender.
- `neural`: Is it Neural Voice?
- `standard`: Is it Standard Voice?
- `bilingual`: Is it bilingual? [Read more](https://docs.aws.amazon.com/polly/latest/dg/bilingual-voices.html).
- `newscaster`: Does it do a newscaster speaking style? [Read more](https://docs.aws.amazon.com/polly/latest/dg/ntts-speakingstyles.html)
- `child`: Child speaker?

> According to Amazon Polly documentation, Aditi (Hindi) she's the only one who speaks both Indian English (en-IN) and Hindi (hi-IN) fluently.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](.github/SECURITY.md) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Ahmad Mayahi](https://github.com/ahmadmayahi)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~35 days

Recently: every ~70 days

Total

10

Last Release

1280d ago

Major Versions

v0.3 → v1.02022-01-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/fdd47a6fbc9b1cf5c5fb2f85520e535b73c29ce99b5c2ac640ddac3fc9a3e987?d=identicon)[ahmad.mayahi](/maintainers/ahmad.mayahi)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (23 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (20 commits)")[![ahmadmayahi](https://avatars.githubusercontent.com/u/1689910?v=4)](https://github.com/ahmadmayahi "ahmadmayahi (11 commits)")

---

Tags

awsphppollyphpamazonpolly

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/ahmadmayahi-php-amazon-polly/health.svg)

```
[![Health](https://phpackages.com/badges/ahmadmayahi-php-amazon-polly/health.svg)](https://phpackages.com/packages/ahmadmayahi-php-amazon-polly)
```

###  Alternatives

[cpigroup/php-amazon-mws

An open-source library to connect to Amazon's MWS web services in an object-oriented manner, with a focus on intuitive usage.

255122.3k2](/packages/cpigroup-php-amazon-mws)[lai3221/amzn_adv_api_php

Amazon Advertising API Client Library V3.0

141.4k](/packages/lai3221-amzn-adv-api-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
