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

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

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:package

pkg:composer/moe-mizrak/laravel-google-text-to-speech

v0.0.1 2025-11-11 14:11 UTC

This package is not auto-updated.

Last update: 2025-11-12 12:38:11 UTC


README

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

Requirements

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

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 [
    'api_endpoint' => env('GOOGLE_TEXT_TO_SPEECH_API_ENDPOINT', 'texttospeech.googleapis.com'),
    'credentials' => env('GOOGLE_TEXT_TO_SPEECH_CREDENTIALS'),
];
  • GOOGLE_TEXT_TO_SPEECH_API_ENDPOINT: The API endpoint for Google Cloud Text-to-Speech. Default is texttospeech.googleapis.com.
  • GOOGLE_TEXT_TO_SPEECH_CREDENTIALS: The path to your Google Cloud service account credentials JSON file.

Note

Go to the Google Cloud Console to create and download your service account credentials with proper permissions for Text-to-Speech API.

Usage

There are 2 methods:

  • synthesizeText: Synthesize speech from plain text.
  • listVoices: List available voices.

Synthesize Text

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

$textData = new TextData(
    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 VoiceData(
    languageCode: 'en-US',
    voiceName: 'en-US-Wavenet-D',
);

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

$response = GoogleTextToSpeech::synthesizeSpeech($textData, $voiceData, $audioConfigData);
  • $response will contain the synthesized audio content in base64 format. it can be saved as an audio file as follows:

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

Tip

Check TextData, VoiceData, and AudioConfigData classes for more options.

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.

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

This project is created and maintained by Moe Mizrak.

License

Laravel Package Template is an open-sourced software licensed under the MIT license.