scReader

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Options)

Option is the type for a function option

func Callback

func Callback(cb audio.OnDataCb) Option

Callback is a functional option to set the callback which will be executed whenever new data has been read from the audio device (e.g. microphone).

func Channels

func Channels(chs int) Option

Channels is a functional option to set the amount of channels to be used with the audio device. Typically this is either Mono (1) or Stereo (2). Make sure that your audio device supports the specified amount of channels.

func DeviceName

func DeviceName(name string) Option

DeviceName is a functional option to specify the name of the Audio device

func FramesPerBuffer

func FramesPerBuffer(s int) Option

FramesPerBuffer is a functional option which sets the amount of sample frames our audio device will request / provide when executing the callback. Example: A buffer with 960 frames at 48000kHz / stereo contains 1920 samples and results in 20ms Audio.

func HostAPI

func HostAPI(hostAPI string) Option

HostAPI is a functional option to enforce the usage of a particular audio host API

func Latency

func Latency(t time.Duration) Option

Latency is a functional option to set the latency of the audio device.

func Samplerate

func Samplerate(s float64) Option

Samplerate is a functional option to set the sampling rate of the audio device. Make sure your audio device supports the specified sampling rate.

type Options

type Options struct {
	HostAPI         string
	DeviceName      string
	Channels        int
	Samplerate      float64
	FramesPerBuffer int
	Latency         time.Duration
	Callback        audio.OnDataCb
}

Options contains the parameters for initializing a soundcard reader.

type ScReader

type ScReader struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ScReader implements the audio.Source interface and is used to read (record) audio from a local sound card (e.g. microphone).

func NewScReader

func NewScReader(opts ...Option) (*ScReader, error)

NewScReader returns a soundcard reader which steams audio asynchronously from an a local audio device (e.g. a microphone).

func (*ScReader) Close

func (r *ScReader) Close() error

Close shutsdown properly the soundcard reader.

func (*ScReader) SetCb

func (r *ScReader) SetCb(cb audio.OnDataCb)

SetCb sets the callback which will be executed to provide audio buffers.

func (*ScReader) Start

func (r *ScReader) Start() error

Start will start streaming audio from a local soundcard device. The read audio buffers will be provided through the callback.

func (*ScReader) Stop

func (r *ScReader) Stop() error

Stop stops streaming audio.

Jump to

Keyboard shortcuts

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