aac

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 5 Imported by: 0

README

aac

Go Reference tests Go Report Card

This package provides a simple way to encode audio from gopxl/beep's Streamer interface directly to AAC format using the gen2brain/aac-go encoder.

Installation

go get -u github.com/thde/aac

Usage

package main

import (
    "os"

    "github.com/gopxl/beep/v2"
    "github.com/gopxl/beep/v2/wav"
    "github.com/thde/aac"
)

func main() {
    f, err := os.Open("input.wav")
    if err != nil {
        panic(err)
    }
    defer f.Close()

    streamer, format, err := wav.Decode(f)
    if err != nil {
        panic(err)
    }
    defer streamer.Close()

    out, err := os.Create("output.aac")
    if err != nil {
        panic(err)
    }
    defer out.Close()

    err = aac.Encode(out, streamer, aac.EncodeOptions{
        Format:  format,
        BitRate: 128000, // 128 kbps
    })
    if err != nil {
        panic(err)
    }
}

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Documentation

Overview

Package aac provides AAC encoding functionality for beep audio streams.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(w io.Writer, s beep.Streamer, opts EncodeOptions) error

Encode writes a beep.Streamer to an io.Writer in AAC format. Returns an error if encoding fails, if the format has an unsupported precision, or if the format has more than 2 channels.

Example

Example demonstrates encoding generated audio (sine wave).

format := beep.Format{
	SampleRate:  44100,
	NumChannels: 2,
	Precision:   2,
}

// Generate a 440 Hz sine wave (A4 note) for 3 seconds
sine, err := generators.SineTone(format.SampleRate, 440)
if err != nil {
	log.Fatal(err)
}
limited := beep.Take(format.SampleRate.N(3*time.Second), sine)

// Create output file
out, err := os.Create("sine.aac")
if err != nil {
	log.Fatal(err)
}
defer out.Close()

// Encode to AAC
if err = aac.Encode(out, limited, aac.EncodeOptions{
	Format:  format,
	BitRate: 128000,
}); err != nil {
	log.Fatal(err)
}

Types

type EncodeOptions

type EncodeOptions struct {
	// Embed the source audio format. Precision must be 2 (16-bit PCM) to match the AAC encoder requirements.
	beep.Format
	// BitRate in bits/sec.
	// If 0, defaults to 64000 bits/sec.
	BitRate int
}

EncodeOptions defines the options for AAC encoding.

Jump to

Keyboard shortcuts

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