arduino-audio-tools
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
WakeWordDetector< T, N > Class Template Reference

Template-based wake word detector for microcontrollers using dominant frequency patterns. More...

#include <WakeWordDetector.h>

Inheritance diagram for WakeWordDetector< T, N >:
AudioOutput Print AudioInfoSupport AudioInfoSource

Classes

struct  Template
 

Public Types

using WakeWordCallback = void(*)(const char *name)
 

Public Member Functions

 WakeWordDetector (AudioFFTBase &fft)
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
void addTemplate (const Vector< FrequencyFrame< N > > &frames, float threshold_percent, const char *name)
 
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 
virtual int availableForWrite () override
 
virtual bool begin ()
 
virtual bool begin (AudioInfo info)
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
virtual void end ()
 
virtual void flush ()
 
virtual bool isDeletable ()
 If true we need to release the related memory in the destructor.
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
bool isRecording () const
 
virtual operator bool ()
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setWakeWordCallback (WakeWordCallback cb)
 
void startRecording ()
 
Vector< FrequencyFrame< N > > stopRecording ()
 
size_t write (const uint8_t *buf, size_t size) override
 
virtual size_t write (uint8_t ch) override
 
virtual void writeSilence (size_t len)
 

Static Public Member Functions

static void fftResult (AudioFFTBase &fft)
 

Protected Member Functions

float matchTemplate (Template &tmpl)
 
void notifyAudioChange (AudioInfo info)
 

Protected Attributes

Vector< T_buffer
 Buffer for incoming PCM samples.
 
WakeWordCallback _callback = nullptr
 
size_t _frame_pos
 Current position in frame buffer.
 
bool _is_recording = false
 True if currently recording a template.
 
size_t _max_template_len = 0
 Length of the longest template.
 
Vector< FrequencyFrame< N > > _recent_frames
 Recent frames for comparison.
 
Vector< Template_templates
 List of wake word templates.
 
int _timeout = 10
 
AudioInfo cfg
 
bool is_active = false
 
bool is_notify_active = true
 
Vector< AudioInfoSupport * > notify_vector
 
AudioFFTBasep_fft = nullptr
 
SingleBuffer< uint8_ttmp {MAX_SINGLE_CHARS}
 
int tmpPos = 0
 

Detailed Description

template<typename T = int16_t, size_t N = 3>
class audio_tools::WakeWordDetector< T, N >

Template-based wake word detector for microcontrollers using dominant frequency patterns.

This class detects wake words by comparing the sequence of the top N dominant frequencies in each audio frame to stored templates for each wake word. When the percentage of matching frames exceeds a configurable threshold, the corresponding wake word is considered detected.

Template Parameters
NNumber of dominant frequencies to track per frame (default: 3)

Usage:

Example:

detector.addTemplate(my_template_frames, 80.0f, "hello");
detector.setWakeWordCallback([](const char* name) { Serial.println(name); });
// ...
Template-based wake word detector for microcontrollers using dominant frequency patterns.
Definition WakeWordDetector.h:51
static HardwareSerial Serial
Definition NoArduino.h:186
size_t writeData(Print *p_out, T *data, int samples, int maxSamples=512)
Definition AudioTypes.h:512

Member Typedef Documentation

◆ WakeWordCallback

template<typename T = int16_t, size_t N = 3>
using WakeWordCallback = void (*)(const char* name)

Constructor & Destructor Documentation

◆ WakeWordDetector()

template<typename T = int16_t, size_t N = 3>
WakeWordDetector ( AudioFFTBase fft)
inline

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ addTemplate()

template<typename T = int16_t, size_t N = 3>
void addTemplate ( const Vector< FrequencyFrame< N > > &  frames,
float  threshold_percent,
const char name 
)
inline

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlineoverridevirtualinherited

provides the actual input AudioInfo

Implements AudioInfoSupport.

Reimplemented in AdapterPrintToAudioOutput, EncodedAudioOutput, and AdapterAudioStreamToAudioOutput.

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ availableForWrite()

virtual int availableForWrite ( )
inlineoverridevirtualinherited

◆ begin() [1/2]

virtual bool begin ( )
inlinevirtualinherited

◆ begin() [2/2]

virtual bool begin ( AudioInfo  info)
inlinevirtualinherited

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ end()

virtual void end ( )
inlinevirtualinherited

◆ fftResult()

template<typename T = int16_t, size_t N = 3>
static void fftResult ( AudioFFTBase fft)
inlinestatic

◆ flush()

virtual void flush ( )
inlinevirtualinherited

Reimplemented from Print.

Reimplemented in MultiOutput, and HexDumpOutput.

◆ isDeletable()

virtual bool isDeletable ( )
inlinevirtualinherited

If true we need to release the related memory in the destructor.

Reimplemented in AdapterPrintToAudioOutput, and AdapterAudioStreamToAudioOutput.

◆ isNotifyActive()

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isRecording()

template<typename T = int16_t, size_t N = 3>
bool isRecording ( ) const
inline

◆ matchTemplate()

template<typename T = int16_t, size_t N = 3>
float matchTemplate ( Template tmpl)
inlineprotected

◆ notifyAudioChange()

void notifyAudioChange ( AudioInfo  info)
inlineprotectedinherited

◆ operator bool()

virtual operator bool ( )
inlinevirtualinherited

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlineoverridevirtualinherited

◆ setNotifyActive()

void setNotifyActive ( bool  flag)
inlineinherited

Deactivate/Reactivate automatic AudioInfo updates: (default is active)

◆ setWakeWordCallback()

template<typename T = int16_t, size_t N = 3>
void setWakeWordCallback ( WakeWordCallback  cb)
inline

◆ startRecording()

template<typename T = int16_t, size_t N = 3>
void startRecording ( )
inline

◆ stopRecording()

template<typename T = int16_t, size_t N = 3>
Vector< FrequencyFrame< N > > stopRecording ( )
inline

◆ write() [1/2]

template<typename T = int16_t, size_t N = 3>
size_t write ( const uint8_t buf,
size_t  size 
)
inlineoverridevirtual

Implements AudioOutput.

◆ write() [2/2]

virtual size_t write ( uint8_t  ch)
inlineoverridevirtualinherited

Reimplemented in MetaDataOutput, and MultiOutput.

◆ writeSilence()

virtual void writeSilence ( size_t  len)
inlinevirtualinherited

Writes n 0 values (= silence)

Parameters
len

Member Data Documentation

◆ _buffer

template<typename T = int16_t, size_t N = 3>
Vector<T> _buffer
protected

Buffer for incoming PCM samples.

◆ _callback

template<typename T = int16_t, size_t N = 3>
WakeWordCallback _callback = nullptr
protected

◆ _frame_pos

template<typename T = int16_t, size_t N = 3>
size_t _frame_pos
protected

Current position in frame buffer.

◆ _is_recording

template<typename T = int16_t, size_t N = 3>
bool _is_recording = false
protected

True if currently recording a template.

◆ _max_template_len

template<typename T = int16_t, size_t N = 3>
size_t _max_template_len = 0
protected

Length of the longest template.

◆ _recent_frames

template<typename T = int16_t, size_t N = 3>
Vector<FrequencyFrame<N> > _recent_frames
protected

Recent frames for comparison.

◆ _templates

template<typename T = int16_t, size_t N = 3>
Vector<Template> _templates
protected

List of wake word templates.

◆ _timeout

int _timeout = 10
protectedinherited

◆ cfg

AudioInfo cfg
protectedinherited

◆ is_active

bool is_active = false
protectedinherited

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ notify_vector

Vector<AudioInfoSupport*> notify_vector
protectedinherited

◆ p_fft

template<typename T = int16_t, size_t N = 3>
AudioFFTBase* p_fft = nullptr
protected

◆ tmp

SingleBuffer<uint8_t> tmp {MAX_SINGLE_CHARS}
protectedinherited

◆ tmpPos

int tmpPos = 0
protectedinherited

The documentation for this class was generated from the following file: