承接 pascalkleindienst/laravel-text-to-speech 相关项目开发

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

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

pascalkleindienst/laravel-text-to-speech

最新稳定版本:v0.3.0

Composer 安装命令:

composer require pascalkleindienst/laravel-text-to-speech

包简介

This is my package laravel-text-to-speech

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A simple and elegant Laravel package that converts text to speech using various TTS engines. Easily integrate voice synthesis into your Laravel applications with support for multiple languages, voices, and audio formats.

Features

  • 🎤 Multiple TTS engine support
  • 🌍 Multi-language compatibility
  • 🔊 Customizable voice options
  • ⚡️ Simple, fluent API
  • 🚀 Easy Laravel integration

Perfect for creating accessible applications, voice notifications, audiobooks, or any project requiring speech synthesis.

📖️ Installation

You can install the package via composer:

composer require pascalkleindienst/laravel-text-to-speech

You can publish the config file with:

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

This is the contents of the published config file:

return [
    'driver' => env('TEXT_TO_SPEECH_DRIVER'),
    'language' => env('TEXT_TO_SPEECH_LANGUAGE'),

    'audio' => [
        'path' => env('TEXT_TO_SPEECH_AUDIO_PATH', 'audio'),
        'format' => env('TEXT_TO_SPEECH_AUDIO_FORMAT', 'mp3'),
        'disk' => env('TEXT_TO_SPEECH_AUDIO_DISK', 'local'),
    ],

    'google' => [
        'private_key' => env('TEXT_TO_SPEECH_GOOGLE_PRIVATE_KEY'),
        'type' => env('TEXT_TO_SPEECH_GOOGLE_TYPE', 'service_account'),
        'client_email' => env('TEXT_TO_SPEECH_GOOGLE_CLIENT_EMAIL'),
        'voice' => env('TEXT_TO_SPEECH_GOOGLE_VOICE', 'de-DE-Chirp3-HD-Achernar'),
    ],
    
    'polly' => [
        'key' => env('TEXT_TO_SPEECH_POLLY_KEY'),
        'secret' => env('TEXT_TO_SPEECH_POLLY_SECRET'),
        'token' => env('TEXT_TO_SPEECH_POLLY_TOKEN', false),
        'version' => env('TEXT_TO_SPEECH_POLLY_VERSION', 'latest'),
        'region' => env('TEXT_TO_SPEECH_POLLY_REGION', 'us-east-1'),
        'format' => env('TEXT_TO_SPEECH_POLLY_FORMAT', 'mp3'),
        'engine' => env('TEXT_TO_SPEECH_POLLY_ENGINE', 'standard'),
        'voice' => env('TEXT_TO_SPEECH_POLLY_VOICE', 'Joanna'),
        'text_type' => env('TEXT_TO_SPEECH_POLLY_TEXT_TYPE', 'text'),
    ],

    'system' => [
        'rate' => env('TEXT_TO_SPEECH_SYSTEM_RATE', 175),
        'pitch' => env('TEXT_TO_SPEECH_SYSTEM_PITCH', 50),
        'volume' => env('TEXT_TO_SPEECH_SYSTEM_VOLUME', 100),
        'voice' => env('TEXT_TO_SPEECH_SYSTEM_VOICE', 'german-mbrola-1'),
    ],
];

Driver Prequisites

System Driver

When using the system driver, you need to install the following packages:

Google Driver

When using the google driver, you need to install the following packages:

composer require google/cloud-text-to-speech

💻 Usage

use PascalKleindienst\LaravelTextToSpeech\Facades\TextToSpeech;
use PascalKleindienst\LaravelTextToSpeech\Source;

// The text is converted to speech and stored in a file (configured in the "audio" config).
TextToSpeech::convert('Hello World!'); 

// The text is converted to speech and additionallystored in the given file.
TextToSpeech::convert('Hello World!')->save('path/to/file.mp3'); 

// Store the converted text on a different disk
TextToSpeech::convert('Hello World!')->disk('s3')->save('path/to/file.txt');

// convert text from a file
TextToSpeech::from(Source::File)->convert('path/to/file.txt');

/**
 * Change the language and/or voice used for the speech. 
 * NOTE: 
 *   This will overwrite the language and voice settings in the config file.
 *   Also the format for the language might be different for each engine, e.g. de vs de-DE
 */
TextToSpeech::language('de-DE')->voice('male')->convert('Hallo Welt!');

// Use the system engine to convert text to speech, needs espeak-ng to be installed
TextToSpeech::engine('system')->convert('Hello System Engine!');

// Use the Google engine to convert text to speech, needs google cloud sdk to be installed
TextToSpeech::engine('google')->convert('Hello Google Engine!');

👨‍🔬 Testing

composer test

📝 Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-30