Picovoice Wordmark
Start Building
Introduction
Introduction
AndroidC.NETFlutterlink to GoiOSJavaNVIDIA JetsonLinuxmacOSNodejsPythonRaspberry PiReact NativeRustWebWindows
AndroidC.NETFlutterlink to GoiOSJavaNodejsPythonReact NativeRustWeb
SummaryPicovoice LeopardAmazon TranscribeAzure Speech-to-TextGoogle ASRGoogle ASR (Enhanced)IBM Watson Speech-to-Text
FAQ
Introduction
AndroidC.NETFlutterlink to GoiOSJavaNVIDIA JetsonLinuxmacOSNodejsPythonRaspberry PiReact NativeRustWebWindows
AndroidC.NETFlutterlink to GoiOSJavaNodejsPythonReact NativeRustWeb
FAQ
Introduction
AndroidCiOSLinuxmacOSPythonWebWindows
AndroidCiOSPythonWeb
SummaryOctopus Speech-to-IndexGoogle Speech-to-TextMozilla DeepSpeech
FAQ
Introduction
AndroidAngularArduinoBeagleBoneCChrome.NETEdgeFirefoxFlutterlink to GoiOSJavaNVIDIA JetsonLinuxmacOSMicrocontrollerNodejsPythonRaspberry PiReactReact NativeRustSafariUnityVueWebWindows
AndroidAngularC.NETFlutterlink to GoiOSJavaMicrocontrollerNodejsPythonReactReact NativeRustUnityVueWeb
SummaryPorcupineSnowboyPocketSphinx
Wake Word TipsFAQ
Introduction
AndroidAngularBeagleBoneCChrome.NETEdgeFirefoxFlutterlink to GoiOSJavaNVIDIA JetsonLinuxmacOSNodejsPythonRaspberry PiReactReact NativeRustSafariUnityVueWebWindows
AndroidAngularC.NETFlutterlink to GoiOSJavaNodejsPythonReactReact NativeRustUnityVueWeb
SummaryPicovoice RhinoGoogle DialogflowAmazon LexIBM WatsonMicrosoft LUIS
Expression SyntaxFAQ
Introduction
AndroidBeagleboneCiOSNVIDIA JetsonLinuxmacOSPythonRaspberry PiRustWebWindows
AndroidCiOSPythonRustWeb
SummaryPicovoice CobraWebRTC VAD
FAQ
Introduction
AndroidCiOSNVIDIA JetsonLinuxmacOSPythonRaspberry PiWebWindows
AndroidCiOSPythonWeb
SummaryPicovoice KoalaMozilla RNNoise
Introduction
AndroidCiOSNVIDIA JetsonLinuxmacOSPythonRaspberry PiWebWindows
AndroidCPythoniOSWeb
Introduction
AndroidAngularArduinoBeagleBoneC.NETFlutterlink to GoiOSJavaNVIDIA JetsonMicrocontrollerNodejsPythonRaspberry PiReactReact NativeRustUnityVueWeb
AndroidAngularCMicrocontroller.NETFlutterlink to GoiOSJavaNodejsPythonReactReact NativeRustUnityVueWeb
Picovoice SDK - FAQ
IntroductionSTM32F407G-DISC1 (Arm Cortex-M4)STM32F411E-DISCO (Arm Cortex-M4)STM32F769I-DISCO (Arm Cortex-M7)IMXRT1050-EVKB (Arm Cortex-M7)
Introduction
AndroidC.NETFlutterlink to GoiOSNodejsPythonReact NativeRustUnityWeb
AndroidC.NETFlutterlink to GoiOSNodejsPythonReact NativeRustUnityWeb
FAQGlossary

Audio Recording
C Quick Start

Platforms

  • Linux (x86_64)
  • macOS (x86_64, arm64)
  • Windows (x86_64)
  • BeagleBone
  • NVIDIA Jetson Nano
  • Raspberry Pi (Zero, 2, 3, 4)

Requirements

  • CMake 3.4+.
  • C99 compatible compiler.
  • Windows: MinGW.

Quick Start

Setup

Include the public header files (pv_recorder.h and pv_circular_buffer.h) .

Usage

  1. Create a PvRecorder object:
#include "pv_recorder.h"
const int32_t frame_length = 512;
const int32_t device_index = -1; // -1 == default device
const int32_t buffered_frame_count = 10;
pv_recorder_t *recorder = NULL;
pv_recorder_status_t status = pv_recorder_init(
frame_length,
device_index,
buffered_frame_count,
&recorder);
if (status != PV_RECORDER_STATUS_SUCCESS) {
// handle PvRecorder init error
}
  1. Start recording audio:
pv_recorder_status_t status = pv_recorder_start(recorder);
if (status != PV_RECORDER_STATUS_SUCCESS) {
// handle PvRecorder start error
}
  1. Read frames of audio from the recorder:
// must have length equal to `frame_length` that was given to `pv_recorder_init()`
int16_t *frame = malloc(frame_length * sizeof(int16_t));
while (true) {
pv_recorder_status_t status = pv_recorder_read(recorder, frame);
if (status != PV_RECORDER_STATUS_SUCCESS) {
// handle PvRecorder read error
}
// use frame of audio data
// ...
}
  1. Stop recording:
pv_recorder_status_t status = pv_recorder_stop(recorder);
if (status != PV_RECORDER_STATUS_SUCCESS) {
// handle PvRecorder stop error
}
  1. Release resources used by PvRecorder:
pv_recorder_delete(recorder);
free(frame);

Selecting an Audio Device

To print a list of available audio devices:

char **device_list = NULL;
int32_t device_list_length = 0;
pv_recorder_status_t status = pv_recorder_get_available_devices(
&device_list_length,
&device_list);
if (status != PV_RECORDER_STATUS_SUCCESS) {
// handle PvRecorder get audio devices error
}
fprintf(stdout, "Printing devices...\n");
for (int32_t i = 0; i < device_list_length; i++) {
fprintf(stdout, "index: %d, name: %s\n", i, device_list[i]);
}
pv_recorder_free_available_devices(device_list_length, device_list);

The index of the device in the returned list can be used in pv_recorder_init() to select that device for recording.

Demo

For the PvRecorder C SDK, we offer a demo application that demonstrates how use PvRecorder to record audio to an output audio file in WAV format.

Setup

  1. Clone the repository:
git clone --recurse-submodules https://github.com/Picovoice/pvrecorder.git
  1. Build the project:
cd demo/c
cmake -S . -B build -DPV_RECORDER_PLATFORM={PV_RECORDER_PLATFORM}
cmake --build build

The {PV_RECORDER_PLATFORM} variable will set the compilation flags for the given platform. Exclude this variable to get a list of possible values.

Usage

To see the usage options for the demo:

./pv_recorder_demo

Get a list of available audio recording devices:

./pv_recorder_demo --show_audio_devices

Record to a file with a given audio device index:

./pv_recorder_demo -o test.wav -d 2

Hit Ctrl+C to stop recording. If no audio device index (-d) is provided, the demo will use the system's default recording device.

For more information about our PvRecorder demo, head over to our GitHub repository .

Resources

API

  • PvRecorder C API Docs

GitHub

  • PvRecorder C SDK on GitHub
  • PvRecorder C Demos on GitHub

Was this doc helpful?

Issue with this doc?

Report a GitHub Issue
Audio Recording C Quick Start
  • Platforms
  • Requirements
  • Quick Start
  • Setup
  • Usage
  • Selecting an Audio Device
  • Demo
  • Setup
  • Usage
  • Resources
Platform
  • Leopard Speech-to-Text
  • Cheetah Streaming Speech-to-Text
  • Koala Noise Suppression
  • Eagle Speaker RecognitionBETA
  • Octopus Speech-to-Index
  • Porcupine Wake Word
  • Rhino Speech-to-Intent
  • Cobra Voice Activity Detection
  • Orca Text-to-SpeechWAITLIST
  • Falcon Speaker DiarizationWAITLIST
Resources
  • Docs
  • Console
  • Blog
  • Use Cases
Sales & Services
  • Consulting
  • Developer Plan
  • Enterprise Plan
  • Support Add-on
Company
  • About us
  • Careers
Follow Picovoice
  • LinkedIn
  • GitHub
  • Twitter
  • Medium
  • YouTube
  • AngelList
Subscribe to our newsletter
Terms of Use
Privacy Policy
© 2019-2022 Picovoice Inc.