pvrecorder

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2022 License: Apache-2.0 Imports: 14 Imported by: 3

README

PV_Recorder

A cross platform audio recorder to read one channel and 16kHz samples.

Requirements

  • Go 1.16+

Compatibility

  • Windows (amd64)
  • macOS
    • x86_64
    • arm64
  • Linux (x86_64)
  • Raspberry Pi:
    • Zero
    • 2
    • 3 (32 and 64 bit)
    • 4 (32 and 64 bit)
  • NVIDIA Jetson Nano
  • BeagleBone

Installation

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

Usage

To get the list of available devices:

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

devices, err := GetAudioDevices()
if err != nil {
    // error
}

To start recording, initialize the instance and run start function:

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

recorder := PvRecorder{
    DeviceIndex: -1, // Using -1 for index uses default audio input device.
    FrameLength: 512,
    BufferSizeMSec: 1000,
    LogOverflow: 1,
}
if err := recorder.Init(); err != nil {
    // error
}
if err := recorder.Start(); err != nil {
    // error
}

To read the pcm frames, run:

pcm, err := recorder.Read()
if err != nil {
    // handle error
}
// do something with pcm

To stop recording just run stop on the instance:

recorder.Stop()

Once you are done, free the used resources. You do not have to call stop before delete:

recorder.Delete()
Demo

For more detailed information on how to use the pv_recorder go sdk, please that a look at demo/demo.go.

To run the demo:

go run demo/demo.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAudioDevices

func GetAudioDevices() ([]string, error)

GetAudioDevices function gets the currently available input audio devices.

func Version

func Version() string

Version function gets the current library version.

Types

type PvRecorder

type PvRecorder struct {

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

	// FrameLength to get for each read command.
	FrameLength int

	// BufferSizeMSec is the total amount of audio frames to store in milliseconds.
	BufferSizeMSec int

	// LogOverflow flag to enable logs when a buffer overflow occurs.
	LogOverflow int

	// LogSilence flag to enable logs when continuous audio buffers are detected as silent.
	LogSilence int
	// contains filtered or unexported fields
}

PvRecorder struct

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) Read

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

Read function reads audio frames.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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