audio

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package audio provides audio processing services including isolation, alignment, and sound effects.

This package combines audio isolation (vocal extraction), forced alignment, and sound effect generation.

Example:

import (
    "github.com/plexusone/elevenlabs-go"
    "github.com/plexusone/elevenlabs-go/audio"
)

client, _ := elevenlabs.NewClient()
isolated, _ := client.Audio().Isolate(ctx, &audio.IsolationRequest{...})
sfx, _ := client.Audio().GenerateSoundEffect(ctx, &audio.SoundEffectRequest{...})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlignmentCharacter

type AlignmentCharacter struct {
	// Text is the character text.
	Text string

	// Start is the start time in seconds.
	Start float64

	// End is the end time in seconds.
	End float64
}

AlignmentCharacter represents a character with timing information.

type AlignmentRequest

type AlignmentRequest struct {
	// File is the audio file to align (required).
	File io.Reader

	// Filename is the name of the file (required).
	Filename string

	// Text is the text to align with the audio (required).
	Text string
}

AlignmentRequest contains options for forced alignment.

type AlignmentResponse

type AlignmentResponse struct {
	// Words contains word-level timing information.
	Words []AlignmentWord

	// Characters contains character-level timing information.
	Characters []AlignmentCharacter

	// Loss is the average alignment confidence score.
	Loss float64
}

AlignmentResponse contains the alignment result.

type AlignmentWord

type AlignmentWord struct {
	// Text is the word text.
	Text string

	// Start is the start time in seconds.
	Start float64

	// End is the end time in seconds.
	End float64

	// Loss is the confidence score for this word.
	Loss float64
}

AlignmentWord represents a word with timing information.

type IsolationRequest

type IsolationRequest struct {
	// Audio is the audio file to process (required).
	Audio io.Reader

	// Filename is the name of the file (required).
	Filename string
}

IsolationRequest contains options for audio isolation.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service handles audio processing including isolation, alignment, and sound effects.

func New

func New(apiClient *api.Client) *Service

New creates a new audio service.

func (*Service) Align

Align performs forced alignment between audio and text. This is useful for generating word-level timestamps for captions and subtitles.

func (*Service) AlignFile

func (s *Service) AlignFile(ctx context.Context, file io.Reader, filename, text string) (*AlignmentResponse, error)

AlignFile is a convenience method to align audio from a file reader with text.

func (*Service) GenerateLoopingSoundEffect

func (s *Service) GenerateLoopingSoundEffect(ctx context.Context, description string, durationSeconds float64) (io.Reader, error)

GenerateLoopingSoundEffect generates a looping sound effect.

func (*Service) GenerateSoundEffect

func (s *Service) GenerateSoundEffect(ctx context.Context, req *SoundEffectRequest) (*SoundEffectResponse, error)

GenerateSoundEffect creates a sound effect from a text description.

func (*Service) Isolate

func (s *Service) Isolate(ctx context.Context, req *IsolationRequest) (io.Reader, error)

Isolate extracts vocals/speech from audio, removing background noise. Returns an io.Reader containing the isolated audio.

func (*Service) IsolateFile

func (s *Service) IsolateFile(ctx context.Context, audio io.Reader, filename string) (io.Reader, error)

IsolateFile is a convenience method to isolate vocals from an audio file.

func (*Service) IsolateStream

func (s *Service) IsolateStream(ctx context.Context, req *IsolationRequest) (io.Reader, error)

IsolateStream extracts vocals/speech from audio with streaming output. Returns an io.Reader for streaming the isolated audio.

func (*Service) SimpleSoundEffect

func (s *Service) SimpleSoundEffect(ctx context.Context, description string) (io.Reader, error)

SimpleSoundEffect generates a sound effect with minimal configuration.

type SoundEffectRequest

type SoundEffectRequest struct {
	// Text is the description of the sound effect to generate.
	// Examples: "car engine starting", "thunder and rain", "crowd cheering"
	Text string

	// DurationSeconds is the target duration (0.5 to 30 seconds).
	// If not set, the optimal duration will be guessed from the prompt.
	DurationSeconds float64

	// PromptInfluence controls how closely the generation follows the prompt (0.0 to 1.0).
	// Higher values = more faithful to prompt but less variation.
	// Default is 0.3.
	PromptInfluence float64

	// Loop creates a sound effect that loops smoothly.
	Loop bool

	// OutputFormat specifies the audio format (e.g., "mp3_44100_128").
	OutputFormat string
}

SoundEffectRequest contains options for generating a sound effect.

func (*SoundEffectRequest) Validate

func (r *SoundEffectRequest) Validate() error

Validate validates the sound effect request.

type SoundEffectResponse

type SoundEffectResponse struct {
	// Audio is the generated sound effect data.
	Audio io.Reader
}

SoundEffectResponse contains the generated sound effect.

Jump to

Keyboard shortcuts

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