elevenlabs

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 0 Imported by: 0

README

OmniVoice ElevenLabs Provider

Build Status Lint Status Go Report Card Docs License

ElevenLabs provider implementation for OmniVoice - the voice abstraction layer for AgentPlexus.

Features

  • TTS Provider: Text-to-Speech with streaming support via WebSocket
  • STT Provider: Speech-to-Text with real-time transcription
  • Agent Provider: Voice agent orchestration combining TTS and STT

Installation

go get github.com/agentplexus/omnivoice-elevenlabs

Quick Start

TTS (Text-to-Speech)
package main

import (
    "context"
    "fmt"
    "os"

    "github.com/agentplexus/omnivoice/tts"
    eleventts "github.com/agentplexus/omnivoice-elevenlabs/tts"
)

func main() {
    // Create ElevenLabs TTS provider
    provider, err := eleventts.New()
    if err != nil {
        panic(err)
    }

    // Use with OmniVoice client for fallback support
    client := tts.NewClient(provider)

    // Generate speech
    result, err := client.Synthesize(context.Background(), "Hello from OmniVoice!", tts.SynthesisConfig{
        VoiceID:      "21m00Tcm4TlvDq8ikWAM", // Rachel voice
        OutputFormat: "mp3",
    })
    if err != nil {
        panic(err)
    }

    // Save to file
    os.WriteFile("hello.mp3", result.Audio, 0644)
    fmt.Println("Audio saved to hello.mp3")
}
Streaming TTS (for LLM integration)
// Stream text chunks to TTS (perfect for LLM output)
stream, err := provider.SynthesizeStream(ctx, "Hello world!", tts.SynthesisConfig{
    VoiceID: "21m00Tcm4TlvDq8ikWAM",
})
if err != nil {
    panic(err)
}

for chunk := range stream {
    if chunk.Error != nil {
        log.Printf("Error: %v", chunk.Error)
        break
    }
    // Play or save audio chunk
    player.Write(chunk.Audio)
}
STT (Speech-to-Text)
package main

import (
    "context"
    "fmt"
    "os"

    "github.com/agentplexus/omnivoice/stt"
    elevenstt "github.com/agentplexus/omnivoice-elevenlabs/stt"
)

func main() {
    // Create ElevenLabs STT provider
    provider, err := elevenstt.New()
    if err != nil {
        panic(err)
    }

    // Use with OmniVoice client
    client := stt.NewClient(provider)

    // Transcribe audio file
    result, err := client.TranscribeFile(context.Background(), "recording.mp3", stt.TranscriptionConfig{
        EnableWordTimestamps: true,
    })
    if err != nil {
        panic(err)
    }

    fmt.Printf("Transcript: %s\n", result.Text)
}
Streaming STT (Real-Time)
// Start streaming transcription
writer, events, err := provider.TranscribeStream(ctx, stt.TranscriptionConfig{
    SampleRate:           16000,
    EnableWordTimestamps: true,
})
if err != nil {
    panic(err)
}

// Send audio in a goroutine
go func() {
    defer writer.Close()
    for audioChunk := range microphoneInput {
        writer.Write(audioChunk)
    }
}()

// Receive transcripts
for event := range events {
    if event.IsFinal {
        fmt.Println("Final:", event.Transcript)
    } else {
        fmt.Printf("\rPartial: %s", event.Transcript)
    }
}
Voice Agent
package main

import (
    "context"
    "fmt"

    "github.com/agentplexus/omnivoice/agent"
    elevenagent "github.com/agentplexus/omnivoice-elevenlabs/agent"
)

func main() {
    // Create ElevenLabs Agent provider
    provider, err := elevenagent.New()
    if err != nil {
        panic(err)
    }

    // Create a voice session
    session, err := provider.CreateSession(context.Background(), agent.Config{
        Name:     "Assistant",
        VoiceID:  "21m00Tcm4TlvDq8ikWAM",
        Language: "en",
    })
    if err != nil {
        panic(err)
    }
    defer session.Stop(context.Background())

    // Start the session
    if err := session.Start(context.Background()); err != nil {
        panic(err)
    }

    // Handle events
    go func() {
        for event := range session.Events() {
            switch event.Type {
            case agent.EventUserTranscript:
                fmt.Printf("User: %s\n", event.Data)
            case agent.EventAgentTranscript:
                fmt.Printf("Agent: %s\n", event.Data)
            }
        }
    }()

    // Send audio from microphone
    for audioChunk := range microphoneInput {
        session.SendAudio(audioChunk)
    }

    // Play agent audio
    for audio := range session.ReceiveAudio() {
        player.Write(audio)
    }
}

Configuration

Environment Variables
export ELEVENLABS_API_KEY="your-api-key"
Explicit Configuration
provider, err := eleventts.New(
    eleventts.WithAPIKey("your-api-key"),
    eleventts.WithBaseURL("https://api.elevenlabs.io"), // optional
)
Using Existing Client
import elevenlabs "github.com/agentplexus/go-elevenlabs"

client, _ := elevenlabs.NewClient()

// Share client across providers
ttsProvider := eleventts.NewWithClient(client)
sttProvider := elevenstt.NewWithClient(client)
agentProvider := elevenagent.NewWithClient(client)

Multi-Provider Setup

import (
    "github.com/agentplexus/omnivoice/tts"
    eleventts "github.com/agentplexus/omnivoice-elevenlabs/tts"
    // opentts "github.com/agentplexus/omnivoice-openai/tts" // future
)

// Create multiple providers
elevenlabs, _ := eleventts.New()
// openai, _ := opentts.New()

// OmniVoice client with fallback
client := tts.NewClient(elevenlabs /*, openai */)
client.SetPrimary("elevenlabs")
// client.SetFallbacks("openai")

// Automatic fallback if primary fails
result, err := client.Synthesize(ctx, "Hello!", config)

Voice Listing

voices, err := provider.ListVoices(ctx)
for _, voice := range voices {
    fmt.Printf("%s: %s (%s)\n", voice.ID, voice.Name, voice.Gender)
}

Requirements

License

MIT

Documentation

Overview

Package elevenlabs provides OmniVoice provider implementations using the ElevenLabs API.

This package implements the OmniVoice interfaces (tts.Provider, stt.Provider, agent.Provider) using the go-elevenlabs SDK as the underlying client.

Installation

go get github.com/agentplexus/omnivoice-elevenlabs

Quick Start

import (
    "github.com/agentplexus/omnivoice/tts"
    eleventts "github.com/agentplexus/omnivoice-elevenlabs/tts"
)

// Create provider
provider, err := eleventts.New()
if err != nil {
    log.Fatal(err)
}

// Use with OmniVoice client
client := tts.NewClient(provider)
result, err := client.Synthesize(ctx, "Hello world", tts.SynthesisConfig{
    VoiceID: "21m00Tcm4TlvDq8ikWAM",
})

Environment Variables

The providers use the ELEVENLABS_API_KEY environment variable for authentication by default. You can also provide the API key explicitly using WithAPIKey.

Index

Constants

View Source
const ProviderName = "elevenlabs"

ProviderName is the name used to identify this provider in OmniVoice.

View Source
const Version = "0.1.0"

Version is the SDK version.

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
Package agent provides an OmniVoice Agent provider implementation using ElevenLabs.
Package agent provides an OmniVoice Agent provider implementation using ElevenLabs.
internal
convert
Package convert provides type conversion utilities between OmniVoice and ElevenLabs types.
Package convert provides type conversion utilities between OmniVoice and ElevenLabs types.
Package stt provides an OmniVoice STT provider implementation using ElevenLabs.
Package stt provides an OmniVoice STT provider implementation using ElevenLabs.
Package tts provides an OmniVoice TTS provider implementation using ElevenLabs.
Package tts provides an OmniVoice TTS provider implementation using ElevenLabs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL