Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Edge Tts Laravel Package

afaya/edge-tts

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require afaya/edge-tts
    

    Add the service provider to config/app.php:

    'providers' => [
        // ...
        Afaya\EdgeTTS\EdgeTTSPackage::class,
    ],
    
  2. First Use Case: Basic TTS Conversion

    use Afaya\EdgeTTS\EdgeTTS;
    
    $edgeTTS = new EdgeTTS();
    $audio = $edgeTTS->textToSpeech('Hello, world!');
    file_put_contents('output.mp3', $audio);
    
  3. Where to Look First

    • Documentation: Check the GitHub README for feature details.
    • CLI: Run php artisan edge-tts:help for command-line usage.
    • Config: Publish config with php artisan vendor:publish --provider="Afaya\EdgeTTS\EdgeTTSPackage".

Implementation Patterns

Core Workflows

  1. Programmatic TTS

    $edgeTTS = new EdgeTTS(['voice' => 'en-US-JennyNeural']);
    $audio = $edgeTTS->textToSpeech('Your text here');
    $edgeTTS->save($audio, 'output.wav'); // Save to file
    
  2. Streaming with Callbacks

    $edgeTTS->stream('Streaming text...', function ($chunk) {
        // Process audio chunks in real-time (e.g., send to a client)
        echo $chunk;
    });
    
  3. Word Boundaries Metadata

    $result = $edgeTTS->textToSpeechWithMetadata('Text with words');
    foreach ($result['wordBoundaries'] as $word) {
        echo "Word: {$word['text']}, Start: {$word['start']}ms\n";
    }
    
  4. CLI Integration

    php artisan edge-tts:generate "Hello via CLI" --voice en-US-AriaNeural --output hello.mp3
    

Integration Tips

  • Laravel Queues: Dispatch TTS jobs for async processing:
    use Afaya\EdgeTTS\Jobs\TextToSpeechJob;
    
    TextToSpeechJob::dispatch('Queue text')->onQueue('tts');
    
  • API Endpoints: Return audio streams in real-time:
    Route::get('/tts', function () {
        return response()->stream(function () {
            $edgeTTS = new EdgeTTS();
            $edgeTTS->stream('Live stream text', function ($chunk) {
                echo $chunk;
            });
        }, 200, ['Content-Type' => 'audio/wav']);
    });
    
  • Voice Management: Fetch available voices dynamically:
    $voices = $edgeTTS->getVoices();
    dd($voices); // Array of supported voices (e.g., 'en-US-JennyNeural')
    

Gotchas and Tips

Pitfalls

  1. Rate Limiting

    • Microsoft Edge's TTS may throttle requests. Implement retries with exponential backoff:
      $edgeTTS->setRetryOptions(3, 1000); // Retry 3 times with 1s delay
      
  2. Voice Availability

    • Not all voices are available for all regions. Validate voices before use:
      if (!in_array('en-US-JennyNeural', $edgeTTS->getVoices())) {
          throw new \RuntimeException('Voice not available');
      }
      
  3. Memory Limits

    • Large audio files may exceed PHP’s memory_limit. Use streaming for long texts:
      $edgeTTS->stream('Long text...', function ($chunk) {
          // Process chunk-by-chunk
      });
      
  4. CLI Timeouts

    • Long-running CLI commands may hit PHP’s max_execution_time. Increase it or use streaming:
      php -d max_execution_time=300 artisan edge-tts:generate "Long text..."
      

Debugging

  • Enable Verbose Logging Add to config/edge-tts.php:

    'debug' => true,
    

    Logs will appear in storage/logs/edge-tts.log.

  • Check HTTP Headers Use curl to inspect raw requests:

    curl -v -X POST https://speech.platform.bing.com/synthesize ...
    

Extension Points

  1. Custom Voices Extend the Voice class to support additional metadata:

    namespace Afaya\EdgeTTS\Extensions;
    
    class CustomVoice extends \Afaya\EdgeTTS\Voice {
        public function getCustomProperty() { ... }
    }
    
  2. Audio Format Conversion Hook into the afterGenerate event to convert formats:

    $edgeTTS->on('afterGenerate', function ($audio) {
        return convertToMp3($audio); // Custom logic
    });
    
  3. Proxy Support Configure proxy settings in config/edge-tts.php:

    'proxy' => [
        'http'  => 'tcp://proxy.example.com:8080',
        'https' => 'tcp://proxy.example.com:8080',
    ],
    

Configuration Quirks

  • Default Voice: Set a fallback voice in config/edge-tts.php:
    'default_voice' => 'en-US-GuyNeural',
    
  • SSH/Remote Execution: For CLI scripts, ensure curl is available on the remote server:
    # On remote server:
    apt-get install curl
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium