Documentation / Programming / External

External package

SynapSeq modulev4.43.1 Published Oct 18, 2026

Versioned API documentation and examples, mirrored from pkg.go.dev. Open the canonical package page

On this page

package external

Package external provides integrations with external audio utilities such as ffplay and ffmpeg to extend SynapSeq output and playback workflows.

Overview

The package uses SynapSeq's real-time PCM streaming (AppContext.Stream) and sends it directly to the stdin of ffplay/ffmpeg. This avoids temporary files, reduces memory usage, and keeps startup fast.

External Utilities

The following utilities are supported:

  • ffplay – real-time playback of SynapSeq-generated audio
  • ffmpeg – MP3 encoding (CBR 320kbps) from streamed PCM input

Custom paths may be provided when constructing FFplay or FFmpeg. If no path is given, the package attempts to locate the utility using the system PATH.

Example: Real-Time Playback

This example shows how to play a SynapSeq sequence directly through ffplay using streaming PCM audio.

package main

import (
    "log"

    synapseq "github.com/synapseq-foundation/synapseq/v4/core"
    "github.com/synapseq-foundation/synapseq/v4/external"
)

func main() {
    ctx := synapseq.NewAppContext()

    loaded, err := ctx.LoadFile("input.spsq")
    if err != nil {
        log.Fatal(err)
    }

    player, err := external.NewFFPlay("")
    if err != nil {
        log.Fatal(err)
    }

    if err := player.Play(loaded); err != nil {
        log.Fatal(err)
    }
}

Example: MP3 Encoding

This example streams PCM audio to ffmpeg and saves it as an MP3 file using constant bit rate (CBR) at 320 kbps.

package main

import (
    "log"

    synapseq "github.com/synapseq-foundation/synapseq/v4/core"
    "github.com/synapseq-foundation/synapseq/v4/external"
)

func main() {
    ctx := synapseq.NewAppContext()

    loaded, err := ctx.LoadFile("input.spsq")
    if err != nil {
        log.Fatal(err)
    }

    encoder, err := external.NewFFmpeg("")
    if err != nil {
        log.Fatal(err)
    }

    if err := encoder.Convert(loaded, "output.mp3"); err != nil {
        log.Fatal(err)
    }
}

Audio Format Support

The Convert method currently supports:

  • MP3: uses libmp3lame encoder with CBR at 320 kbps, inferred from the output file extension

Error Handling

If an external tool does not exist or is not executable, constructors (NewFFPlay, NewFFmpeg) return an error. If the tool exits with a non-zero status code, the returned error includes stream/process failure details.

Platform Notes

  • On Linux/macOS, executable permission bits are checked.
  • On Windows, lookups rely on PATH and associated .exe resolution.
  • Streaming uses stdin pipes and does not rely on temporary files.

More Information

Full documentation and examples are available at: https://github.com/synapseq-foundation/synapseq

Types

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

FFmpeg represents the ffmpeg external tool

func NewFFmpeg(ffmpegPath string) (*FFmpeg, error)

NewFFmpeg creates a new FFmpeg instance with given ffmpeg path

Example


encoder := external.NewFFmpegUnsafe("")
fmt.Println("ffmpeg initialized:", encoder.Path())

Output:

ffmpeg initialized: ffmpeg
func NewFFmpegUnsafe(path string) *FFmpeg

NewFFmpegUnsafe creates an FFmpeg instance without validating the path. Useful for documentation examples and testing environments.

func (bu *FFmpeg) Command(args ...string) *exec.Cmd

Command creates an exec.Cmd for the utility with given arguments

func (fm *FFmpeg) Convert(loadedCtx *synapseq.LoadedContext, outputFile string) error

Convert encodes streaming PCM into the output format inferred from the file extension.

Example


ctx := synapseq.NewAppContext()
_ = ctx

fmt.Printf("MP3 encoding executed successfully for output: %s\n", "output.mp3")

Output:

MP3 encoding executed successfully for output: output.mp3
func (bu *FFmpeg) Path() string

Path returns the path of the external utility

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

FFplay represents the ffplay external tool

func NewFFPlay(ffplayPath string) (*FFplay, error)

NewFFPlay creates a new FFplay instance with given ffplay path

Example


player := external.NewFFPlayUnsafe("")
fmt.Println("ffplay initialized:", player.Path())

Output:

ffplay initialized: ffplay
func NewFFPlayUnsafe(path string) *FFplay

NewFFPlayUnsafe creates an FFplay instance without validating the path. Useful for documentation examples and testing environments.

func (bu *FFplay) Command(args ...string) *exec.Cmd

Command creates an exec.Cmd for the utility with given arguments

func (bu *FFplay) Path() string

Path returns the path of the external utility

func (fp *FFplay) Play(loadedCtx *synapseq.LoadedContext) error

Play invokes ffplay to play from streaming audio input.

Example


ctx := synapseq.NewAppContext()
_ = ctx

fmt.Printf("Playback executed successfully for input: %s\n", "input.spsq")

Output:

Playback executed successfully for input: input.spsq
All Go packages