PHPackages                             nosun/edge-tts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nosun/edge-tts

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nosun/edge-tts
==============

edge-tts is a laravel package that allows you to use Microsoft Edge's online text-to-speech service from within your laravel code

1.0.0(1mo ago)00[1 issues](https://github.com/nosun/edge-tts/issues)MITPHPPHP ^8.1

Since Apr 29Pushed 1mo agoCompare

[ Source](https://github.com/nosun/edge-tts)[ Packagist](https://packagist.org/packages/nosun/edge-tts)[ RSS](/packages/nosun-edge-tts/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

Edge TTS for Laravel
====================

[](#edge-tts-for-laravel)

edge-tts is a Laravel package that allows you to use Microsoft Edge's online text-to-speech service from within your Laravel code. **No Azure API Key required** - this package uses the free Edge Read Aloud API.

[![Latest Version on Packagist](https://camo.githubusercontent.com/61839464bd35958738b0898695ec7b86b432f9d24633e6d6f32aa487bab2d985/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f73756e2f656467652d7474732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nosun/edge-tts)[![Total Downloads](https://camo.githubusercontent.com/df831f0a6251287b16b57884a35d9189f4eca4ff47568c179f4f42106ba22391/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6f73756e2f656467652d7474732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nosun/edge-tts)[![Tests](https://github.com/nosun/edge-tts/actions/workflows/tests.yml/badge.svg)](https://github.com/nosun/edge-tts/actions/workflows/tests.yml)

Features
--------

[](#features)

- 🎤 **Text to Speech**: Convert text to natural-sounding speech using Microsoft's neural voices
- 🌍 **Multi-language Support**: Support for 100+ languages and locales
- ⚡ **Speech Customization**: Adjust rate, pitch, and volume
- 💾 **Flexible Storage**: Save to local file or Laravel Storage
- 🎮 **Artisan Commands**: Command-line interface for quick usage
- 🔄 **Streaming Support**: Stream audio data in real-time
- 📝 **Metadata Support**: Word and sentence boundary metadata for subtitle generation
- 🔧 **Smart Text Processing**: Automatic text splitting and special character handling
- 🛡️ **Robust Error Handling**: Detailed exception types and automatic retry mechanisms

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 10.0 || &gt;= 11.0
- ext-json

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require nosun/edge-tts
```

Configuration
-------------

[](#configuration)

The package works with default configuration out of the box. If you want to customize the settings, publish the config file:

```
php artisan vendor:publish --provider="Nosun\EdgeTts\EdgeTtsServiceProvider" --tag="config"
```

This will create `config/edge-tts.php` with the following options:

```
return [
    'default' => [
        'voice' => 'en-US-JennyNeural',   // Default voice
        'rate' => '+0%',                     // Speech rate (-100% to +100%)
        'pitch' => '+0Hz',                   // Pitch adjustment
        'volume' => '+0%',                   // Volume (-100% to +100%)
        'format' => 'audio-24khz-96kbitrate-mono-mp3', // Output format
    ],

    'storage' => [
        'disk' => 'public',                  // Storage disk for synthesizeToStorage
        'path' => 'edge-tts',                // Storage path
    ],

    'websocket' => [
        'timeout' => 30,                     // Connection timeout in seconds
        'wss_url' => '...',                  // WebSocket endpoint
        'voices_url' => '...',               // Voices list endpoint
    ],
];
```

Usage
-----

[](#usage)

### Using Facade

[](#using-facade)

```
use Nosun\EdgeTts\Facades\EdgeTts;

// Basic text-to-speech
$result = EdgeTts::synthesize('Hello, World!');

// Get audio data
$audioData = $result->audioData;

// Save to file
$path = EdgeTts::synthesizeToFile('Hello, World!', '/path/to/output.mp3');

// Save to Laravel Storage
$storagePath = EdgeTts::synthesizeToStorage('Hello, World!', 'greeting.mp3');
```

### Customizing Speech Parameters

[](#customizing-speech-parameters)

```
use Nosun\EdgeTts\Facades\EdgeTts;

// With custom voice and parameters
$result = EdgeTts::synthesize('你好世界！', [
    'voice' => 'zh-CN-XiaoxiaoNeural',  // Chinese female voice
    'rate' => '+20%',                     // Slightly faster
    'pitch' => '+10Hz',                   // Higher pitch
    'volume' => '+50%',                   // Louder
]);

// Save with custom options
EdgeTts::synthesizeToFile(
    'Welcome to Laravel!',
    '/path/to/output.mp3',
    [
        'voice' => 'en-US-GuyNeural',
        'rate' => '-10%',
    ]
);
```

### Streaming Audio with Metadata

[](#streaming-audio-with-metadata)

```
use Nosun\EdgeTts\Facades\EdgeTts;

// Stream audio in real-time with metadata
$stream = EdgeTts::stream('This is a long text that will be streamed...', [
    'boundary' => 'WordBoundary', // or 'SentenceBoundary'
]);

foreach ($stream as $chunk) {
    if ($chunk['type'] === 'audio') {
        // Process audio chunk
        file_put_contents('output.mp3', $chunk['data'], FILE_APPEND);
    } elseif ($chunk['type'] === 'WordBoundary' || $chunk['type'] === 'SentenceBoundary') {
        // Process metadata for subtitle generation
        echo "Text: {$chunk['text']}\n";
        echo "Offset: {$chunk['offset']} ticks\n";
        echo "Duration: {$chunk['duration']} ticks\n";
    }
}
```

### Voice Management

[](#voice-management)

```
use Nosun\EdgeTts\Facades\EdgeTts;

// Get all available voices
$voices = EdgeTts::voices();
foreach ($voices as $voice) {
    echo $voice->shortName . ' - ' . $voice->localeName . PHP_EOL;
}

// Filter voices by locale
$chineseVoices = EdgeTts::voicesByLocale('zh-CN');

// Filter voices by gender
$femaleVoices = EdgeTts::voicesByGender('Female');

// Get a specific voice
$voice = EdgeTts::getVoice('en-US-JennyNeural');

// Check if voice exists
if (EdgeTts::voiceExists('zh-CN-YunxiNeural')) {
    // Voice is available
}

// Get all available locales
$locales = EdgeTts::getLocales();
```

### Using Dependency Injection

[](#using-dependency-injection)

```
use Nosun\EdgeTts\EdgeTts;

class TtsController extends Controller
{
    public function synthesize(EdgeTts $edgeTts, Request $request)
    {
        $result = $edgeTts->synthesize($request->input('text'));

        return response($result->audioData)
            ->header('Content-Type', 'audio/mpeg');
    }
}
```

Artisan Commands
----------------

[](#artisan-commands)

### List Available Voices

[](#list-available-voices)

```
# List all voices
php artisan edge-tts:voices

# Filter by locale
php artisan edge-tts:voices --locale=en-US
php artisan edge-tts:voices --locale=zh-CN

# Filter by gender
php artisan edge-tts:voices --gender=Female
php artisan edge-tts:voices --gender=Male
```

### Synthesize Text to Speech

[](#synthesize-text-to-speech)

```
# Basic synthesis (shows info only)
php artisan edge-tts:synthesize "Hello, World!"

# Save to local file
php artisan edge-tts:synthesize "Hello, World!" --output=/path/to/output.mp3

# Save to Laravel Storage
php artisan edge-tts:synthesize "Hello, World!" --storage --output=greeting.mp3

# With custom options
php artisan edge-tts:synthesize "你好！" \
    --voice=zh-CN-XiaoxiaoNeural \
    --rate=+20% \
    --pitch=+10Hz \
    --volume=+50% \
    --output=chinese.mp3
```

Popular Voices
--------------

[](#popular-voices)

Here are some popular voices you can use:

Voice NameLanguageGenderDescription`en-US-JennyNeural`English (US)FemaleWarm, professional`en-US-GuyNeural`English (US)MaleDeep, confident`zh-CN-XiaoxiaoNeural`Chinese (Mandarin)FemaleNatural Chinese`zh-CN-YunxiNeural`Chinese (Mandarin)MaleClear Chinese`en-GB-SoniaNeural`English (UK)FemaleBritish accent`ja-JP-NanamiNeural`JapaneseFemaleJapanese`ko-KR-SunHiNeural`KoreanFemaleKorean`fr-FR-DeniseNeural`FrenchFemaleFrench`de-DE-KatjaNeural`GermanFemaleGerman`es-ES-ElviraNeural`SpanishFemaleSpanishRun `php artisan edge-tts:voices` to see the complete list.

Speech Parameters
-----------------

[](#speech-parameters)

### Rate

[](#rate)

Controls the speaking speed.

- Format: `±X%` (e.g., `+50%`, `-30%`)
- Range: Approximately `-100%` to `+100%`
- Default: `+0%`

### Pitch

[](#pitch)

Controls the voice pitch.

- Format: `±XHz` (e.g., `+10Hz`, `-5Hz`)
- Or relative: `high`, `low`, `default`
- Default: `+0Hz`

### Volume

[](#volume)

Controls the audio volume.

- Format: `±X%` (e.g., `+50%`, `-20%`)
- Range: `-100%` to `+100%`
- Default: `+0%`

### Output Formats

[](#output-formats)

- `audio-24khz-96kbitrate-mono-mp3` (Default)
- `audio-24khz-48kbitrate-mono-mp3`
- `audio-16khz-128kbitrate-mono-mp3`
- `audio-16khz-64kbitrate-mono-mp3`
- `audio-16khz-32kbitrate-mono-mp3`

Examples
--------

[](#examples)

### Controller Example

[](#controller-example)

```
