moe-mizrak/laravel-google-text-to-speech
Composer 安装命令:
composer require moe-mizrak/laravel-google-text-to-speech
包简介
Laravel package for integrating Gemini Text-to-Speech API and Google Cloud Text-to-Speech API
关键字:
README 文档
README
Laravel package for integrating Gemini Text-to-Speech API and Google Cloud Text-to-Speech API
Requirements
- PHP: 8.4 or higher
- Google Cloud account with access to Gemini API and/or Cloud Text-to-Speech API
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 [ '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 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.credentialsfield.
If you are using Gemini Text-to-Speech API:
- Go to Google Cloud Console 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_keyfield.
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
This is an example of how to use the synthesizeText method:
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);
-
$responsewill 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, GeminiAudioConfigData and GeminiVoiceData classes for more options.
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);
-
$responsewill 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, CloudVoiceData, and CloudAudioConfigData classes for more options.
List Voices
This is an example of how to use the listVoices method:
$response = GoogleTextToSpeech::listVoices(languageCode: 'en-US');
$responsewill 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
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.
moe-mizrak/laravel-google-text-to-speech 适用场景与选型建议
moe-mizrak/laravel-google-text-to-speech 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「laravel」 「text-to-speech」 「Gemini」 「google-cloud」 「php 8」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 moe-mizrak/laravel-google-text-to-speech 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 moe-mizrak/laravel-google-text-to-speech 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 moe-mizrak/laravel-google-text-to-speech 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package creates a shared API to easily use Text to Speech functionalities amongst different TTS providers.
A PSR-7 compatible library for making CRUD API endpoints
IVONA SpeechCloud SDK for PHP
ElevenLabs API client
Alfabank REST API integration
PHP package for translation, spelling correction and text-to-speech (TTS) synthesis using external APIs
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-17