PHPackages                             moe-mizrak/laravel-google-text-to-speech - 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. moe-mizrak/laravel-google-text-to-speech

ActivePackage[API Development](/categories/api)

moe-mizrak/laravel-google-text-to-speech
========================================

Laravel package for integrating Gemini Text-to-Speech API and Google Cloud Text-to-Speech API

v1.0.1(5mo ago)015MITPHPPHP ^8.4CI passing

Since Nov 11Pushed 5mo agoCompare

[ Source](https://github.com/moe-mizrak/laravel-google-text-to-speech)[ Packagist](https://packagist.org/packages/moe-mizrak/laravel-google-text-to-speech)[ Docs](https://github.com/moe-mizrak/laravel-google-text-to-speech)[ RSS](/packages/moe-mizrak-laravel-google-text-to-speech/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

Laravel Gemini and Google Cloud Text-to-Speech API Package
==========================================================

[](#laravel-gemini-and-google-cloud-text-to-speech-api-package)

Laravel package for integrating **Gemini Text-to-Speech API** and **Google Cloud Text-to-Speech API**

Requirements
------------

[](#requirements)

- **PHP**: 8.4 or higher
- Google Cloud account with access to **Gemini API** and/or **Cloud Text-to-Speech API**

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

[](#installation)

You can install the package via composer:

```
composer require moe-mizrak/laravel-google-text-to-speech
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-google-text-to-speech"
```

Configuration
-------------

[](#configuration)

After publishing the configuration file, you can set your Google Cloud credentials and other settings in the `config/laravel-google-text-to-speech.php` file.

Published config file will look like this:

```
return [
    'driver' => env('GOOGLE_TEXT_TO_SPEECH_DRIVER', TextToSpeechDriverType::GEMINI->value), // Options: 'gemini', 'cloud'
    'api_endpoint' => env('GOOGLE_TEXT_TO_SPEECH_API_ENDPOINT', 'generativelanguage.googleapis.com'), // For Gemini API use 'generativelanguage.googleapis.com', for Google Cloud API use 'texttospeech.googleapis.com'
    'cloud' => [
        'credentials' => env('GOOGLE_TEXT_TO_SPEECH_CREDENTIALS'), // The path to the Google Cloud credentials JSON file.
    ],
    'gemini' => [
        'api_key' => env('GOOGLE_GEMINI_API_KEY'), // Your Gemini API key
        'model' => env('GOOGLE_GEMINI_MODEL', 'gemini-2.5-flash-preview-tts'), // The Gemini model to use for Text-to-Speech synthesis.
        'temperature' => env('GOOGLE_GEMINI_TEMPERATURE', 0.85),
    ],
];
```

Note

If you are using **Google Cloud Text-to-Speech API**:

- Go to the [Google Cloud Console](https://console.cloud.google.com/apis/api/texttospeech.googleapis.com/credentials) to create and download your service account credentials with proper permissions for **Text-to-Speech API**.
- Save the downloaded JSON file and set its path in the config `cloud.credentials` field.

If you are using **Gemini Text-to-Speech API**:

- Go to [Google Cloud Console](https://console.cloud.google.com/projectselector2/iam-admin/serviceaccounts) and select the project where Gemini API is enabled (or create a project).
- Create a service account with the necessary roles to access Gemini API.
- Add a new key on the **Keys** tab, which will be used in the config `gemini.api_key` field.

Usage
-----

[](#usage)

There are 2 drivers for Google Text-to-Speech API:

- `gemini`: Uses **Gemini Text-to-Speech API**.
- `cloud`: Uses **Google Cloud Text-to-Speech API**.

> Gemini Text-to-Speech API is the newer and more advanced API (premium voices), while Google Cloud Text-to-Speech API is the traditional API.

Note

You can set the driver in the config file so that the package uses the desired API automatically

(You need to set credentials/api\_key, and api\_endpoint accordingly in the config file for the selected driver)

### Synthesize Text

[](#synthesize-text)

This is an example of how to use the `synthesizeText` method:

##### For Gemini Text-to-Speech API:

[](#for-gemini-text-to-speech-api)

```
$textData = new GeminiTextData(
    text: 'Laplace Demon: the hypothetical entity that, with perfect knowledge of the present, could predict all future events based on causal determinism.',
);

$voiceData = new GeminiVoiceData(
    voiceName: 'Algieba',
    modelName: 'gemini-2.5-flash-preview-tts',
);

$audioConfigData = new GeminiAudioConfigData;

$geminiSynthesizeData = new GeminiSynthesizeData(
    $textData,
    $voiceData,
    $audioConfigData,
);

$response = GoogleTextToSpeech::synthesizeSpeech($geminiSynthesizeData);
```

- `$response` will contain the synthesized audio content (bytes). it can be saved as an audio file as follows:

    ```
    file_put_contents('output.pcm', $response);
    ```

Note

Gemini Text-to-Speech API currently supports only **.pcm** audio format.

After saving the output as a `.pcm` file, you can convert it to other audio formats (like `.wav` or `.mp3`) using tools like `ffmpeg`.

Tip

Check [`GeminiTextData`](src/Data/GeminiTextData.php), [`GeminiAudioConfigData`](src/Data/GeminiAudioConfigData.php) and [`GeminiVoiceData`](src/Data/GeminiVoiceData.php) classes for more options.

#### For Cloud Text-to-Speech API:

[](#for-cloud-text-to-speech-api)

```
$textData = new CloudTextData(
    text: 'Laplace Demon: the hypothetical entity that, with perfect knowledge of the present, could predict all future events based on causal determinism.',
    isSsml: false,
);

$voiceData = new CloudVoiceData(
    languageCode: 'en-US',
    voiceName: 'en-US-Wavenet-D',
);

$audioConfigData = new CloudAudioConfigData(
    audioEncoding: AudioEncoding::MP3,
);

$cloudSynthesizeData = new CloudSynthesizeData(
    $textData,
    $voiceData,
    $audioConfigData
);

$response = GoogleTextToSpeech::synthesizeSpeech($cloudSynthesizeData);
```

- `$response` will contain the synthesized audio content (bytes). it can be saved as an audio file as follows:

    ```
    file_put_contents('output.mp3', $response);
    ```

Tip

Check [`CloudTextData`](src/Data/CloudTextData.php), [`CloudVoiceData`](src/Data/CloudVoiceData.php), and [`CloudAudioConfigData`](src/Data/CloudAudioConfigData.php) classes for more options.

### List Voices

[](#list-voices)

This is an example of how to use the `listVoices` method:

```
$response = GoogleTextToSpeech::listVoices(languageCode: 'en-US');
```

- `$response` will contain a list/array of available voices for the specified language code.

Warning

`listVoices` method only works with **Google Cloud Text-to-Speech API**. It is not supported for **Gemini Text-to-Speech API**.

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

[](#contributing)

> **Your contributions are welcome!** If you'd like to improve this project, simply create a pull request with your changes. Your efforts help enhance its functionality and documentation.

> If you find this project useful, please consider ⭐ it to show your support!

Authors
-------

[](#authors)

This project is created and maintained by [Moe Mizrak](https://github.com/moe-mizrak).

License
-------

[](#license)

Laravel Package Template is an open-sourced software licensed under the **[MIT license](LICENSE)**.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance70

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~3 days

Total

3

Last Release

176d ago

Major Versions

v0.0.1 → v1.0.02025-11-17

### Community

Maintainers

![](https://www.gravatar.com/avatar/178c884a892aaf6813e8af8e2cb685bc987a168d9a0ebe9336455a795247ff96?d=identicon)[moe-mizrak](/maintainers/moe-mizrak)

---

Top Contributors

[![moe-mizrak](https://avatars.githubusercontent.com/u/12977885?v=4)](https://github.com/moe-mizrak "moe-mizrak (21 commits)")

---

Tags

aiai-voiceai-voice-generationapigeminigemini-apigemini-text-to-speech-apigoogle-cloudgoogle-cloud-text-to-speech-apilaravelphp8text-to-speechttsapilaravelGeminiphp-8google cloudtext-to-speechMoe Mizraklaravel-google-text-to-speechai-voice

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/moe-mizrak-laravel-google-text-to-speech/health.svg)

```
[![Health](https://phpackages.com/badges/moe-mizrak-laravel-google-text-to-speech/health.svg)](https://phpackages.com/packages/moe-mizrak-laravel-google-text-to-speech)
```

###  Alternatives

[google-gemini-php/laravel

Google Gemini PHP for Laravel is a supercharged PHP API client that allows you to interact with the Google Gemini AI API

614397.1k4](/packages/google-gemini-php-laravel)[moe-mizrak/laravel-openrouter

Laravel package for OpenRouter (A unified interface for LLMs)

153107.2k2](/packages/moe-mizrak-laravel-openrouter)[hosseinhezami/laravel-gemini

A production-ready Laravel package to integrate with the Google Gemini API. Supports text, image, video, audio, long-context, structured output, files, caching, function-calling and understanding capabilities.

14010.8k1](/packages/hosseinhezami-laravel-gemini)[gemini-api-php/laravel

Gemini API client for Laravel

8915.7k](/packages/gemini-api-php-laravel)

PHPackages © 2026

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