PocketSphinx  5.0.0rc5
A small speech recognizer
Macros | Typedefs | Enumerations | Functions
vad.h File Reference

Simple voice activity detection. More...

#include <pocketsphinx/prim_type.h>
#include <pocketsphinx/export.h>

Go to the source code of this file.

Macros

#define PS_VAD_DEFAULT_SAMPLE_RATE   16000
 
#define PS_VAD_DEFAULT_FRAME_LENGTH   0.03
 
#define ps_vad_frame_length(vad)   ((double)ps_vad_frame_size(vad) / ps_vad_sample_rate(vad))
 

Typedefs

typedef struct ps_vad_s ps_vad_t
 
typedef enum ps_vad_mode_e ps_vad_mode_t
 
typedef enum ps_vad_class_e ps_vad_class_t
 

Enumerations

enum  ps_vad_mode_e { PS_VAD_LOOSE = 0, PS_VAD_MEDIUM_LOOSE = 1, PS_VAD_MEDIUM_STRICT = 2, PS_VAD_STRICT = 3 }
 
enum  ps_vad_class_e { PS_VAD_ERROR = -1, PS_VAD_NOT_SPEECH = 0, PS_VAD_SPEECH = 1 }
 

Functions

POCKETSPHINX_EXPORT ps_vad_tps_vad_init (ps_vad_mode_t mode, int sample_rate, double frame_length)
 
POCKETSPHINX_EXPORT ps_vad_tps_vad_retain (ps_vad_t *vad)
 
POCKETSPHINX_EXPORT int ps_vad_free (ps_vad_t *vad)
 
POCKETSPHINX_EXPORT int ps_vad_set_input_params (ps_vad_t *vad, int sample_rate, double frame_length)
 
POCKETSPHINX_EXPORT int ps_vad_sample_rate (ps_vad_t *vad)
 
POCKETSPHINX_EXPORT size_t ps_vad_frame_size (ps_vad_t *vad)
 
POCKETSPHINX_EXPORT ps_vad_class_t ps_vad_classify (ps_vad_t *vad, const int16 *frame)
 

Detailed Description

Simple voice activity detection.

Macro Definition Documentation

◆ PS_VAD_DEFAULT_FRAME_LENGTH

#define PS_VAD_DEFAULT_FRAME_LENGTH   0.03

Default frame length for voice activity detector

◆ PS_VAD_DEFAULT_SAMPLE_RATE

#define PS_VAD_DEFAULT_SAMPLE_RATE   16000

Default sampling rate for voice activity detector

◆ ps_vad_frame_length

#define ps_vad_frame_length (   vad)    ((double)ps_vad_frame_size(vad) / ps_vad_sample_rate(vad))

Get the actual length of a frame in seconds.

This may differ from the value requested in ps_vad_set_input_params().

Typedef Documentation

◆ ps_vad_class_t

Classification of input frames returned by ps_vad_classify().

◆ ps_vad_mode_t

Voice activity detection "aggressiveness" levels.

◆ ps_vad_t

typedef struct ps_vad_s ps_vad_t

Voice activity detector.

Enumeration Type Documentation

◆ ps_vad_class_e

Classification of input frames returned by ps_vad_classify().

◆ ps_vad_mode_e

Voice activity detection "aggressiveness" levels.

Function Documentation

◆ ps_vad_classify()

POCKETSPHINX_EXPORT ps_vad_class_t ps_vad_classify ( ps_vad_t vad,
const int16 *  frame 
)

Classify a frame as speech or not speech.

Parameters
vadVoice activity detector.
frameFrame of input, must contain the number of samples returned by ps_vad_frame_size().
Returns
PS_VAD_SPEECH, PS_VAD_NOT_SPEECH, or PS_VAD_ERROR (see ps_vad_class_t).

◆ ps_vad_frame_size()

POCKETSPHINX_EXPORT size_t ps_vad_frame_size ( ps_vad_t vad)

Get the number of samples expected by voice activity detection.

You must always ensure that the buffers passed to ps_vad_classify() contain this number of samples (zero-pad them if necessary).

Parameters
vadVoice activity detector.
Returns
Size, in samples, of the frames passed to ps_vad_classify().

◆ ps_vad_free()

POCKETSPHINX_EXPORT int ps_vad_free ( ps_vad_t vad)

Release a pointer to voice activity detector.

Parameters
vadVoice activity detector.
Returns
New reference count (0 if freed).

◆ ps_vad_init()

POCKETSPHINX_EXPORT ps_vad_t* ps_vad_init ( ps_vad_mode_t  mode,
int  sample_rate,
double  frame_length 
)

Initialize voice activity detection.

Parameters
mode"Aggressiveness" of voice activity detection. Stricter values (see ps_vad_mode_t) are less likely to misclassify non-speech as speech.
sample_rateSampling rate of input, or 0 for default (which can be obtained with ps_vad_sample_rate()). Only 8000, 16000, 32000, 48000 are directly supported. See ps_vad_set_input_params() for more information.
frame_lengthFrame length in seconds, or 0.0 for the default. Only 0.01, 0.02, 0.03 currently supported. Actual value may differ, you must use ps_vad_frame_length() to obtain it.
Returns
VAD object or NULL on failure (invalid parameter for instance).

◆ ps_vad_retain()

POCKETSPHINX_EXPORT ps_vad_t* ps_vad_retain ( ps_vad_t vad)

Retain a pointer to voice activity detector.

Parameters
vadVoice activity detector.
Returns
Voice activity detector with incremented reference count.

◆ ps_vad_sample_rate()

POCKETSPHINX_EXPORT int ps_vad_sample_rate ( ps_vad_t vad)

Get the sampling rate expected by voice activity detection.

Parameters
vadVoice activity detector.
Returns
Expected sampling rate.

◆ ps_vad_set_input_params()

POCKETSPHINX_EXPORT int ps_vad_set_input_params ( ps_vad_t vad,
int  sample_rate,
double  frame_length 
)

Set the input parameters for voice activity detection.

Parameters
sample_rateSampling rate of input, or 0 for default (which can be obtained with ps_vad_sample_rate()). Only 8000, 16000, 32000, 48000 are directly supported, others will use the closest supported rate (within reason). Note that this means that the actual frame length may not be exactly the one requested, so you must always use the one returned by ps_vad_frame_size() (in samples) or ps_vad_frame_length() (in seconds).
frame_lengthRequested frame length in seconds, or 0.0 for the default. Only 0.01, 0.02, 0.03 currently supported. Actual frame length may be different, you must always use ps_vad_frame_length() to obtain it.
Returns
0 for success or -1 on error.