承接 moe-mizrak/laravel-google-text-to-speech 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.credentials field.

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_key field.

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);
  • $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, 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);
  • $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, 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');
  • $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

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 moe-mizrak/laravel-google-text-to-speech 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 31
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-17