pvrecorder

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: Apache-2.0 Imports: 14 Imported by: 3

README

PvRecorder Binding for Go

PvRecorder

PvRecorder is an easy-to-use, cross-platform audio recorder designed for real-time speech audio processing. It allows developers access to an audio device's input stream, broken up into data frames of a given size.

Compatibility

  • Go 1.16+
  • Runs on Linux (x86_64), macOS (x86_64 and arm64), Windows (x86_64), Raspberry Pi (all variants), NVIDIA Jetson (Nano), and BeagleBone.

Installation

go get github.com/Picovoice/pvrecorder/binding/go

Usage

Initialize and begin recording:

import . "github.com/Picovoice/pvrecorder/binding/go"

recorder = NewPvRecorder(/*FrameLength*/512)
recorder.Init()
if err != nil {
    // handle init error
}
defer recorder.Delete()

err = recorder.Start()
if err != nil {
    // handle start error
}

(or)

Use GetAvailableDevices() to get a list of available devices and then initialize the instance based on the index of a device:

import . "github.com/Picovoice/pvrecorder/binding/go"

devices = GetAvailableDevices() // select index of device

recorder = NewPvRecorder(/*FrameLength*/512)
recorder.DeviceIndex = 0
recorder.Init()
if err != nil {
    // handle init error
}
defer recorder.Delete()

err = recorder.Start()
if err != nil {
    // handle start error
}

Get a frame of audio by calling the Read() function:

frame, err := recorder.Read()
if err != nil {
    // handle error
}

To stop recording, call Stop() on the instance:

recorder.Stop()

Once you are done, free the resources acquired by PvRecorder. You do not have to call stop() before delete():

recorder.Delete()
Demo

For more detailed information on how to use the PvRecorder Go binding, please that a look at demo/demo.go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SampleRate Audio sample rate used by PvRecorder.
	SampleRate int

	// Version PvRecorder version
	Version string
)

Functions

func GetAvailableDevices

func GetAvailableDevices() ([]string, error)

GetAvailableDevices function gets the currently available input audio devices.

Types

type PvRecorder

type PvRecorder struct {

	// Length of each frame returned from read command.
	FrameLength int

	// Index of audio device to start recording and capture audio.
	DeviceIndex int

	// BufferedFramesCount is the number of audio frames buffered internally for reading - i.e. internal circular buffer
	// will be of size `frame_length` * `buffered_frames_count`. If this value is too low, buffer overflows could occur.
	BufferedFramesCount int
	// contains filtered or unexported fields
}

PvRecorder struct

func NewPvRecorder

func NewPvRecorder(frameLength int) PvRecorder

NewPvRecorder returns a PvRecorder struct with default parameters

func (*PvRecorder) Delete

func (pvRecorder *PvRecorder) Delete()

Delete function releases resources acquired by PvRecorder

func (*PvRecorder) GetSelectedDevice

func (pvRecorder *PvRecorder) GetSelectedDevice() string

GetSelectedDevice gets the current selected audio input device name

func (*PvRecorder) Init

func (pvRecorder *PvRecorder) Init() error

Init function for PvRecorder

func (*PvRecorder) IsRecording

func (pvRecorder *PvRecorder) IsRecording() bool

IsRecording gets whether the given instance is currently recording audio or not.

func (*PvRecorder) Read

func (pvRecorder *PvRecorder) Read() ([]int16, error)

Read function reads audio frames.

func (*PvRecorder) SetDebugLogging

func (pvRecorder *PvRecorder) SetDebugLogging(isDebugLoggingEnabled bool)

SetDebugLogging enables or disables debug logging for PvRecorder. Debug logs will indicate when there are overflows in the internal frame buffer and when an audio source is generating frames of silence.

func (*PvRecorder) Start

func (pvRecorder *PvRecorder) Start() error

Start function starts recording audio.

func (*PvRecorder) Stop

func (pvRecorder *PvRecorder) Stop() error

Stop function stops recording audio.

type PvRecorderStatus

type PvRecorderStatus int

PvRecorderStatus type

const (
	SUCCESS                    PvRecorderStatus = 0
	OUT_OF_MEMORY              PvRecorderStatus = 1
	INVALID_ARGUMENT           PvRecorderStatus = 2
	INVALID_STATE              PvRecorderStatus = 3
	BACKEND_ERROR              PvRecorderStatus = 4
	DEVICE_ALREADY_INITIALIZED PvRecorderStatus = 5
	DEVICE_NOT_INITIALIZED     PvRecorderStatus = 6
	IO_ERROR                   PvRecorderStatus = 7
	RUNTIME_ERROR              PvRecorderStatus = 8
)

PvRecorder status return codes from C library

Jump to

Keyboard shortcuts

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