audio

package
Version: v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 4 Imported by: 6

Documentation

Overview

Package audio provides the audio configuration, input/output streams, and related utilities for audio interactions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioConfig

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

AudioConfig represents specific audio configuration, such as microphone, file, or custom audio streams.

func NewAudioConfigFromDefaultMicrophoneInput

func NewAudioConfigFromDefaultMicrophoneInput() (*AudioConfig, error)

NewAudioConfigFromDefaultMicrophoneInput creates an AudioConfig object representing the default microphone on the system.

func NewAudioConfigFromDefaultSpeakerOutput

func NewAudioConfigFromDefaultSpeakerOutput() (*AudioConfig, error)

NewAudioConfigFromDefaultSpeakerOutput creates an AudioConfig object representing the default audio output device (speaker) on the system.

func NewAudioConfigFromMicrophoneInput

func NewAudioConfigFromMicrophoneInput(deviceName string) (*AudioConfig, error)

NewAudioConfigFromMicrophoneInput creates an AudioConfig object representing a specific microphone on the system.

func NewAudioConfigFromSpeakerOutput added in v1.17.0

func NewAudioConfigFromSpeakerOutput(deviceName string) (*AudioConfig, error)

NewAudioConfigFromSpeakerOutput creates an AudioConfig object representing the specific audio output device (speaker) on the system.

func NewAudioConfigFromStreamInput

func NewAudioConfigFromStreamInput(stream AudioInputStream) (*AudioConfig, error)

NewAudioConfigFromStreamInput creates an AudioConfig object representing the specified stream.

func NewAudioConfigFromStreamOutput

func NewAudioConfigFromStreamOutput(stream AudioOutputStream) (*AudioConfig, error)

NewAudioConfigFromStreamOutput creates an AudioConfig object representing the specified output stream.

func NewAudioConfigFromWavFileInput

func NewAudioConfigFromWavFileInput(filename string) (*AudioConfig, error)

NewAudioConfigFromWavFileInput creates an AudioConfig object representing the specified file.

func NewAudioConfigFromWavFileOutput

func NewAudioConfigFromWavFileOutput(filename string) (*AudioConfig, error)

NewAudioConfigFromWavFileOutput creates an AudioConfig object representing the specified file for audio output.

func (AudioConfig) Close

func (config AudioConfig) Close()

Close releases the underlying resources

func (AudioConfig) GetHandle

func (config AudioConfig) GetHandle() common.SPXHandle

GetHandle gets the handle to the resource (for internal use)

func (AudioConfig) GetProperty

func (config AudioConfig) GetProperty(id common.PropertyID) string

GetProperty gets a property value by ID.

func (AudioConfig) GetPropertyByString

func (config AudioConfig) GetPropertyByString(name string) string

GetPropertyByString gets a property value by name.

func (AudioConfig) SetProperty

func (config AudioConfig) SetProperty(id common.PropertyID, value string) error

SetProperty sets a property value by ID.

func (AudioConfig) SetPropertyByString

func (config AudioConfig) SetPropertyByString(name string, value string) error

SetPropertyByString sets a property value by name.

type AudioInputStream

type AudioInputStream interface {
	Close()
	// contains filtered or unexported methods
}

AudioInputStream represents audio input stream used for custom audio input configurations

type AudioOutputStream

type AudioOutputStream interface {
	Close()
	// contains filtered or unexported methods
}

AudioOutputStream represents audio output stream used for custom audio output configurations. Updated in version 1.7.0

type AudioStreamContainerFormat

type AudioStreamContainerFormat int

AudioStreamContainerFormat defines supported audio stream container format.

const (
	// OGGOPUS Stream ContainerFormat definition for OGG OPUS.
	OGGOPUS AudioStreamContainerFormat = 0x101

	// MP3 Stream ContainerFormat definition for MP3.
	MP3 AudioStreamContainerFormat = 0x102

	// FLAC Stream ContainerFormat definition for FLAC.
	FLAC AudioStreamContainerFormat = 0x103

	// ALAW Stream ContainerFormat definition for ALAW.
	ALAW AudioStreamContainerFormat = 0x104

	// MULAW Stream ContainerFormat definition for MULAW.
	MULAW AudioStreamContainerFormat = 0x105

	// AMRNB Stream ContainerFormat definition for AMRNB. Currently not supported.
	AMRNB AudioStreamContainerFormat = 0x106

	// AMRWB Stream ContainerFormat definition for AMRWB. Currently not supported.
	AMRWB AudioStreamContainerFormat = 0x107

	// ANY Stream ContainerFormat definition when the actual stream format is not known.
	ANY AudioStreamContainerFormat = 0x108
)

type AudioStreamFormat

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

AudioStreamFormat represents the audio stream format used for custom audio input configurations. Updated in version 1.5.0.

func GetCompressedFormat

func GetCompressedFormat(compressedFormat AudioStreamContainerFormat) (*AudioStreamFormat, error)

GetCompressedFormat creates an audio stream format object with the specified compressed audio container format, to be used as input format.

func GetDefaultInputFormat

func GetDefaultInputFormat() (*AudioStreamFormat, error)

GetDefaultInputFormat creates an audio stream format object representing the default audio stream format (16 kHz, 16 bit, mono PCM).

func GetDefaultOutputFormat

func GetDefaultOutputFormat() (*AudioStreamFormat, error)

GetDefaultOutputFormat creates an audio stream format object representing the default audio stream format (16 kHz, 16 bit, mono PCM).

func GetWaveFormatPCM

func GetWaveFormatPCM(samplesPerSecond uint32, bitsPerSample uint8, channels uint8) (*AudioStreamFormat, error)

GetWaveFormatPCM creates an audio stream format object with the specified PCM waveformat characteristics. Note: Currently, only WAV / PCM with 16-bit samples, 16 kHz sample rate, and a single channel (Mono) is supported. When used with Conversation Transcription, eight channels are supported.

func (*AudioStreamFormat) Close

func (format *AudioStreamFormat) Close()

Close disposes the associated resources.

type PullAudioInputStream

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

PullAudioInputStream represents audio input stream used for custom audio input configurations.

func CreatePullStream

func CreatePullStream(callback PullAudioInputStreamCallback) (*PullAudioInputStream, error)

CreatePullStream creates a PullAudioInputStream that delegates to the specified callback interface for Read() and CloseStream() methods using the default format (16 kHz, 16 bit, mono PCM).

func CreatePullStreamFromFormat

func CreatePullStreamFromFormat(callback PullAudioInputStreamCallback, format *AudioStreamFormat) (*PullAudioInputStream, error)

CreatePullStreamFromFormat creates a PullAudioInputStream that delegates to the specified callback interface for Read() and CloseStream() methods and the specified format. Currently, only WAV / PCM with 16-bit samples, 16 kHz sample rate, and a single channel (Mono) is supported. When used with Conversation Transcription, eight channels are supported.

func (PullAudioInputStream) Close

func (stream PullAudioInputStream) Close()

type PullAudioInputStreamCallback

type PullAudioInputStreamCallback interface {
	Read(maxSize uint32) ([]byte, int)
	GetProperty(id common.PropertyID) string
	CloseStream()
}

PullAudioInputStreamCallback interface that defines callback methods (Read(), GetProperty() and CloseStream()) for custom audio input streams).

type PullAudioOutputStream

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

PullAudioOutputStream represents memory backed pull audio output stream used for custom audio output configurations.

func CreatePullAudioOutputStream

func CreatePullAudioOutputStream() (*PullAudioOutputStream, error)

CreatePullAudioOutputStream creates a memory backed PullAudioOutputStream.

func NewPullAudioOutputStreamFromHandle

func NewPullAudioOutputStreamFromHandle(handle common.SPXHandle) *PullAudioOutputStream

NewPullAudioOutputStreamFromHandle creates a new PullAudioOutputStream from a handle (for internal use)

func (*PullAudioOutputStream) Close

func (stream *PullAudioOutputStream) Close()

func (PullAudioOutputStream) Read

func (stream PullAudioOutputStream) Read(size uint) ([]byte, error)

Read reads audio from the stream. The maximal number of bytes to be read is determined from the size parameter. If there is no data immediately available, read() blocks until the next data becomes available.

type PushAudioInputStream

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

PushAudioInputStream represents memory backed push audio input stream used for custom audio input configurations.

func CreatePushAudioInputStream

func CreatePushAudioInputStream() (*PushAudioInputStream, error)

CreatePushAudioInputStream creates a memory backed PushAudioInputStream using the default format (16 kHz, 16 bit, mono PCM).

func CreatePushAudioInputStreamFromFormat

func CreatePushAudioInputStreamFromFormat(format *AudioStreamFormat) (*PushAudioInputStream, error)

CreatePushAudioInputStreamFromFormat creates a memory backed PushAudioInputStream with the specified audio format. Currently, only WAV / PCM with 16-bit samples, 16 kHz sample rate, and a single channel (Mono) is supported. When used with Conversation Transcription, eight channels are supported.

func (PushAudioInputStream) Close

func (stream PushAudioInputStream) Close()

func (PushAudioInputStream) CloseStream

func (stream PushAudioInputStream) CloseStream()

CloseStream closes the stream.

func (PushAudioInputStream) SetProperty

func (stream PushAudioInputStream) SetProperty(id common.PropertyID, value string) error

SetProperty sets value of a property. The properties of the audio data should be set before writing the audio data.

func (PushAudioInputStream) SetPropertyByName

func (stream PushAudioInputStream) SetPropertyByName(name string, value string) error

SetPropertyByName sets value of a property. The properties of the audio data should be set before writing the audio data.

func (PushAudioInputStream) Write

func (stream PushAudioInputStream) Write(buffer []byte) error

Write writes the audio data specified by making an internal copy of the data. Note: The dataBuffer should not contain any audio header.

type PushAudioOutputStream

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

PushAudioOutputStream represents audio output stream used for custom audio output configurations.

func CreatePushAudioOutputStream

func CreatePushAudioOutputStream(callback PushAudioOutputStreamCallback) (*PushAudioOutputStream, error)

CreatePushAudioOutputStream creates a PushAudioOutputStream that delegates to the specified callback interface for Write() and CloseStream() methods.

func (*PushAudioOutputStream) Close

func (stream *PushAudioOutputStream) Close()

type PushAudioOutputStreamCallback

type PushAudioOutputStreamCallback interface {
	Write(buffer []byte) int
	CloseStream()
}

PushAudioOutputStreamCallback an interface that defines callback methods (Write() and CloseStream()) for custom audio output streams).

Jump to

Keyboard shortcuts

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