定制 back2ops/elevenlabs 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

back2ops/elevenlabs

Composer 安装命令:

composer require back2ops/elevenlabs

包简介

A Laravel package for the ElevenLabs Voice API — text-to-speech, speech-to-text, and sound effects.

README 文档

README

A clean, well-tested Laravel package for the ElevenLabs Voice API.
Supports Text to Speech, Speech to Text, and Sound Effects with a fluent API and Laravel Facade.

Table of Contents

  1. Requirements
  2. Installation
  3. Configuration
  4. Usage
  5. Available Models
  6. Testing
  7. Publishing to Packagist
  8. Package Architecture Explained

Requirements

Installation

composer require back2ops/elevenlabs

Laravel's package auto-discovery will automatically register the service provider and ElevenLabs facade — no manual setup needed.

If you have auto-discovery disabled, add these to config/app.php:

'providers' => [
    Back2ops\ElevenLabs\ElevenLabsServiceProvider::class,
],

'aliases' => [
    'ElevenLabs' => Back2ops\ElevenLabs\Facades\ElevenLabs::class,
],

Configuration

1. Publish the config file

php artisan vendor:publish --tag=elevenlabs-config

This creates config/elevenlabs.php in your application.

2. Add your API key to .env

ELEVENLABS_API_KEY=your_api_key_here

# Optional overrides (these have sensible defaults in the config):
ELEVENLABS_VOICE_ID=21m00Tcm4TlvDq8ikWAM   # Rachel (default)
ELEVENLABS_TTS_MODEL=eleven_multilingual_v2
ELEVENLABS_STT_MODEL=scribe_v2
ELEVENLABS_SFX_MODEL=eleven_text_to_sound_v2
ELEVENLABS_OUTPUT_FORMAT=mp3_44100_128
ELEVENLABS_DISK=                            # Leave blank to use default filesystem disk

Usage

You can use the ElevenLabs facade anywhere, or inject Back2ops\ElevenLabs\ElevenLabs directly.

Text to Speech

Get raw audio bytes

use ElevenLabs;

$audioBytes = ElevenLabs::textToSpeech('Hello, welcome to our platform!');

// Store it yourself
Storage::put('audio/welcome.mp3', $audioBytes);

// Or stream it back to the browser
return response($audioBytes, 200)->header('Content-Type', 'audio/mpeg');

With custom options

$audioBytes = ElevenLabs::textToSpeech(
    text: 'Bonjour tout le monde!',
    voiceId: 'EXAVITQu4vr4xnSDxMaL',    // Override voice
    modelId: 'eleven_flash_v2_5',          // Ultra-low latency model
    outputFormat: 'mp3_44100_128',
    voiceSettings: [
        'stability'        => 0.8,
        'similarity_boost' => 0.9,
        'style'            => 0.2,
    ],
    languageCode: 'fr',                    // Force French
);

Generate and store in one call

// Returns the storage path 'audio/greeting.mp3'
$path = ElevenLabs::textToSpeechAndStore(
    text: 'Welcome back!',
    path: 'audio/greeting.mp3',
    disk: 's3',                           // Optional: override filesystem disk
);

// Get the public URL
$url = Storage::disk('s3')->url($path);

Speech to Text

Transcribe a file on disk

// Full response — includes word-level timestamps
$result = ElevenLabs::transcribeFile('/path/to/recording.mp3');

echo $result['text'];           // Full transcript string
echo $result['language_code']; // 'en'

foreach ($result['words'] as $word) {
    echo "{$word['text']} ({$word['start']}s – {$word['end']}s)\n";
}

Just the text

$transcript = ElevenLabs::transcribeToText('/path/to/recording.mp3');
echo $transcript; // "Hello, this is the transcribed content."

From an uploaded file (Controller example)

public function transcribe(Request $request): JsonResponse
{
    $request->validate(['audio' => 'required|file|mimes:mp3,wav,webm,m4a|max:51200']);

    $file = $request->file('audio');

    $result = ElevenLabs::transcribeBytes(
        bytes: file_get_contents($file->getRealPath()),
        filename: $file->getClientOriginalName(),
        language: $request->input('language'),  // e.g. 'en', 'es' — optional
    );

    return response()->json([
        'transcript' => $result['text'],
        'language'   => $result['language_code'],
    ]);
}

Sound Effects

Generate and return bytes

$sfx = ElevenLabs::soundEffect('a heavy wooden door creaking open slowly');

Storage::put('sfx/door-creak.mp3', $sfx);

With options

$sfx = ElevenLabs::soundEffect(
    prompt: 'gentle rain on a tin roof',
    durationSeconds: 10.0,        // 0.5–30 seconds (null = auto-detect)
    promptInfluence: 0.5,         // 0.0–1.0 (default 0.3)
    loopable: true,               // Seamless loop (eleven_text_to_sound_v2 only)
);

Generate and store

$path = ElevenLabs::soundEffectAndStore(
    prompt: 'crowd cheering in a stadium',
    path: 'sfx/crowd-cheer.mp3',
    options: [
        'duration_seconds' => 8.0,
        'loopable'         => false,
    ],
);

Listing Voices

// All voices on your account
$voices = ElevenLabs::voices();

foreach ($voices as $voice) {
    echo $voice['voice_id'] . '' . $voice['name'] . "\n";
}

// Single voice details
$voice = ElevenLabs::voice('21m00Tcm4TlvDq8ikWAM');

// All available models
$models = ElevenLabs::models();

Available Models

Text to Speech

Model ID Description
eleven_multilingual_v2 Highest quality, 32 languages (default)
eleven_flash_v2_5 Ultra-low ~75ms latency, great for real-time
eleven_turbo_v2_5 Balanced speed & quality

Speech to Text

Model ID Description
scribe_v2 State-of-the-art accuracy (default)
scribe_v1 Legacy model

Sound Effects

Model ID Description
eleven_text_to_sound_v2 Latest, supports looping (default)

Output Formats

Format Description
mp3_44100_128 MP3 44.1kHz 128kbps (default)
mp3_22050_32 MP3 22kHz 32kbps (smaller files)
mp3_44100_192 MP3 44.1kHz 192kbps (Creator tier+)
pcm_16000 PCM 16kHz (lossless)
pcm_44100 PCM 44.1kHz (lossless, large)

back2ops/elevenlabs 适用场景与选型建议

back2ops/elevenlabs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「text-to-speech」 「tts」 「elevenlabs」 「speech-to-text」 「stt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 back2ops/elevenlabs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 back2ops/elevenlabs 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-15