Documentation ¶
Overview ¶
Package audio contains structs and functions to allow operating on audio data
Index ¶
Constants ¶
const ( BufSize = 1 << 10 SilentThresh = 1 << 10 SampleRate = 16000 NumChannels = 1 )
const ( // DefaultNumChannels is 1 (mono audio) DefaultNumChannels uint16 = 1 // DefaultSampleRate is 16KHz DefaultSampleRate uint32 = 16000 // DefaultAudioFormat is 1 (raw, uncompressed PCM waveforms) DefaultAudioFormat uint16 = 1 // DefaultBitsPerSample is 16 (2 bytes per sample). DefaultBitsPerSample uint16 = 16 )
WAV-related constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct { AudioData *WAV // contains filtered or unexported fields }
File represents an audio file. It wraps the raw WAV data and allows you to operate with it using high-level operations, such as padding, trimming, playback, writing to file, recording, etc.
func NewFileFromBytes ¶
NewFileFromBytes creates a new audio.File from WAV data
func NewFileFromFile ¶
NewFileFromFile creates a new audio.File from an os.File
func NewFileFromFileName ¶
NewFileFromFileName creates a new audio.File from the given filename
func NewFileFromReader ¶
NewFileFromReader creates a new audio.File from an io.Reader
func (*File) Pad ¶
Pad adds silence to both the beginning and end of the audio data. Silence is specified in seconds.
func (*File) TrimSilence ¶
func (f *File) TrimSilence()
TrimSilence trims silence from both ends of the audio data.
func (*File) WAVData ¶
WAVData returns the wav data (header + audio data) contained in the audio file
func (*File) WriteToFile ¶
WriteToFile writes the audio data to a file.
type WAV ¶
type WAV struct { // NumChannels is the number of channels the WAV file has. 1 = mono, // 2 = stereo, etc. This affects the block align and also number of // bytes per sample: (BitsPerSample / 8) * NumChannels. NumChannels uint16 // SampleRate is the number of samples taken per second. SampleRate uint32 // AudioFormat is the type of Audio that is encoded in the WAV file. // In most scenarios, this will be 1 (1 = raw, uncompressed PCM audio), // since WAV doesn't support compression. AudioFormat uint16 // BitsPerSample is the width of each sample. 16 bits means each sample // is two bytes. BitsPerSample uint16 // contains filtered or unexported fields }
WAV represents a PCM audio file in the WAV container format. It keeps a high-level description of the parameters of the file, along with the raw audio bytes, until it needs to be written to a file, stream, or array. It is based on the WAV formatting as specified: http://soundfile.sapp.org/doc/WaveFormat/
func NewWAVFromData ¶
NewWAVFromData creates a WAV format struct from the given data buffer The buffer is broken up into its respective information and that
func NewWAVFromParams ¶
NewWAVFromParams returns a new WAV file from the passed in parameters If any of the parameters are 0, it will be given the default value.
func NewWAVFromReader ¶
NewWAVFromReader takes in a reader and creates a new WAV file.
func (*WAV) AddAudioData ¶
AddAudioData adds the passed-in audio bytes to the WAV struct
func (*WAV) Data ¶
Data creates the header and data based on the WAV struct and returns a fully formatted WAV file
func (*WAV) TrimSilent ¶
TrimSilent is called on a WAV struct to trim the silent portions from the ends of the file while leaving a certain amount of padding. The padding input is specified in seconds. The threshold input is a decimal (between 0 and 1) and is relative to the maximum amplitude of the waveform