Picovoice WordmarkPicovoice Console
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 GoiOSJavaNodejsPythonReact NativeRustWeb
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
AndroidCiOSPythonWeb
AndroidCiOSPythonWeb
SummaryPicovoice KoalaMozilla RNNoise
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)
FAQGlossary

Cobra Voice Activity Detection
Rust API


API Reference for the Cobra Rust SDK (crates.io ).


cobra::Cobra

pub struct Cobra

Struct for the Cobra VAD engine.


cobra::Cobra.new()

pub fn new<S: Into<String>>(access_key: S) -> Result<Cobra, CobraError>

Creates a new Cobra from required arguments.

Parameters

  • access_key S : AccessKey obtained from Picovoice Console .

Returns

  • Result<Cobra, CobraError> : If Ok, returns a new Cobra object. If Err, a CobraError object describing the error that was encountered.

cobra::Cobra.new_with_library()

pub fn new_with_library<S: Into<String>, P: Into<PathBuf>>(access_key: S, library_path: P) -> Result<Cobra, CobraError>

Creates a new Cobra from required arguments.

Parameters

  • access_key S : AccessKey obtained from Picovoice Console .
  • library_path P : Path to the Cobra library file.

Returns

  • Result<Cobra, CobraError> : If Ok, returns a new Cobra object. If Err, a CobraError object describing the error that was encountered.

cobra::Cobra.process()

pub fn process(&self, pcm: &[i16]) -> Result<f32, CobraError>

Processes a frame of the incoming audio stream and emits the probability of voice activity.

The number of samples per frame can be attained by calling .frame_length. The incoming audio needs to have a sample rate equal to .sample_rate and be 16-bit linearly-encoded. Furthermore, Cobra operates on single-channel audio.

Parameters

  • pcm &[i16] : Audio data.

Returns

  • Result<f32, CobraError> : If Ok, returns the probability of voice activity. It is a floating-point number within [0, 1]. If Err, a CobraError object describing the error that was encountered.

cobra::Cobra.frame_length()

pub fn frame_length(&self) -> u32

Gets the frame length.

Returns

  • u32 : Audio frame length accepted by Cobra.

cobra::Cobra.sample_rate()

pub fn sample_rate(&self) -> u32

Gets the sample rate.

Returns

  • u32 : Audio sample rate accepted by Cobra.

cobra::Cobra.version()

pub fn version(&self) -> &str

Gets the Cobra version.

Returns

  • &str : Cobra version string.

cobra::CobraError

pub struct CobraError

An error type describing any errors encountered by the Cobra SDK.


cobra::CobraError.new()

pub fn new(status: CobraErrorStatus, message: impl Into<String>) -> Self

Creates a new instance of CobraError

Parameters

  • status CobraErrorStatus : Type of error encountered.
  • message impl Into<String> : Message detailing the cause of the error.

cobra::CobraErrorStatus

pub enum CobraErrorStatus {
LibraryError(PvStatus),
LibraryLoadError,
FrameLengthError,
ArgumentError,
}

Enum describing possible error types returned from the Cobra Rust SDK.


cobra::PvStatus

pub enum PvStatus {
SUCCESS = 0,
OUT_OF_MEMORY = 1,
IO_ERROR = 2,
INVALID_ARGUMENT = 3,
STOP_ITERATION = 4,
KEY_ERROR = 5,
INVALID_STATE = 6,
PV_STATUS_RUNTIME_ERROR = 7,
PV_STATUS_ACTIVATION_ERROR = 8,
PV_STATUS_ACTIVATION_LIMIT_REACHED = 9,
PV_STATUS_ACTIVATION_THROTTLED = 10,
PV_STATUS_ACTIVATION_REFUSED = 11,
}

Error codes returned from the Cobra library.

Was this doc helpful?

Issue with this doc?

Report a GitHub Issue
Cobra Voice Activity Detection Rust API
  • cobra::Cobra
  • new()
  • new_with_library()
  • process()
  • frame_length()
  • sample_rate()
  • version()
  • cobra::CobraError
  • new()
  • cobra::CobraErrorStatus
  • cobra::PvStatus
Platform
  • Leopard Speech-to-Text
  • Cheetah Streaming Speech-to-Text
  • Octopus Speech-to-Index
  • Porcupine Wake Word
  • Rhino Speech-to-Intent
  • Cobra Voice Activity Detection
Resources
  • Docs
  • Console
  • Blog
  • Demos
Sales
  • Pricing
  • Starter Tier
  • Enterprise
Company
  • Careers
Follow Picovoice
  • LinkedIn
  • GitHub
  • Twitter
  • Medium
  • YouTube
  • AngelList
Subscribe to our newsletter
Terms of Use
Privacy Policy
© 2019-2022 Picovoice Inc.