Struct rustpotter::WakewordDetector
source · [−]pub struct WakewordDetector { /* private fields */ }Expand description
This struct manages the wakeword generation and the spotting functionality.
use rustpotter::{WakewordDetectorBuilder};
// assuming the audio input format match the detector defaults
let mut word_detector = WakewordDetectorBuilder::new().build();
// load and enable a wakeword
word_detector.add_wakeword_from_model_file("./tests/resources/oye_casa.rpw".to_owned(), true).unwrap();
let mut frame_buffer: Vec<i32> = vec![0; word_detector.get_samples_per_frame()];
// while true { Iterate forever
// fill the buffer with new samples...
let detection_option = word_detector.process(&frame_buffer);
if detection_option.is_some() {
let detection = detection_option.as_ref().unwrap();
println!(
"Detected '{}' with score {}!",
detection.wakeword,
detection.score,
);
}
// }Implementations
sourceimpl WakewordDetector
impl WakewordDetector
sourcepub fn new(
sample_rate: usize,
sample_format: SampleFormat,
bits_per_sample: u16,
channels: u16,
endianness: Endianness,
eager_mode: bool,
single_thread: bool,
training_mode: bool,
threshold: f32,
averaged_threshold: f32,
comparator_band_size: usize,
comparator_ref: f32,
noise_mode: Option<NoiseDetectionMode>,
noise_sensitivity: f32
) -> Self
pub fn new(
sample_rate: usize,
sample_format: SampleFormat,
bits_per_sample: u16,
channels: u16,
endianness: Endianness,
eager_mode: bool,
single_thread: bool,
training_mode: bool,
threshold: f32,
averaged_threshold: f32,
comparator_band_size: usize,
comparator_ref: f32,
noise_mode: Option<NoiseDetectionMode>,
noise_sensitivity: f32
) -> Self
Creates a new WakewordDetector.
It is recommended to use the WakewordDetectorBuilder struct instead.
sourcepub fn add_wakeword_from_model_bytes(
&mut self,
bytes: Vec<u8>,
enabled: bool
) -> Result<String, String>
pub fn add_wakeword_from_model_bytes(
&mut self,
bytes: Vec<u8>,
enabled: bool
) -> Result<String, String>
Loads a wakeword from its model bytes.
sourcepub fn add_wakeword_from_model_file(
&mut self,
path: String,
enabled: bool
) -> Result<String, String>
pub fn add_wakeword_from_model_file(
&mut self,
path: String,
enabled: bool
) -> Result<String, String>
Loads a wakeword from its model path.
sourcepub fn generate_trained_wakeword_model_bytes(
&self,
name: String
) -> Result<Vec<u8>, String>
pub fn generate_trained_wakeword_model_bytes(
&self,
name: String
) -> Result<Vec<u8>, String>
Generates the model file bytes from a trained a wakeword. Asserts training mode is enabled.
sourcepub fn generate_trained_wakeword_model_file(
&self,
name: String,
path: String
) -> Result<(), String>
pub fn generate_trained_wakeword_model_file(
&self,
name: String,
path: String
) -> Result<(), String>
Generates a model file from a trained a wakeword on the desired path. Asserts training mode is enabled.
sourcepub fn generate_wakeword_model_bytes(
&self,
name: String
) -> Result<Vec<u8>, String>
pub fn generate_wakeword_model_bytes(
&self,
name: String
) -> Result<Vec<u8>, String>
Generates the model file bytes from a loaded a wakeword.
sourcepub fn generate_wakeword_model_file(
&self,
name: String,
path: String
) -> Result<(), String>
pub fn generate_wakeword_model_file(
&self,
name: String,
path: String
) -> Result<(), String>
Generates a model file from a loaded a wakeword on the desired path.
sourcepub fn add_wakeword(
&mut self,
name: &str,
enabled: bool,
averaged_threshold: Option<f32>,
threshold: Option<f32>,
sample_paths: Vec<String>
)
pub fn add_wakeword(
&mut self,
name: &str,
enabled: bool,
averaged_threshold: Option<f32>,
threshold: Option<f32>,
sample_paths: Vec<String>
)
Adds a wakeword using wav samples.
use rustpotter::{WakewordDetectorBuilder};
let mut word_detector = WakewordDetectorBuilder::new().build();
word_detector.add_wakeword(
"model_name",
true,
Some(0.35),
Some(0.6),
vec![],
);
// Save as model file
// word_detector.generate_wakeword_model_file("model_name".to_owned(), "model_path".to_owned()).unwrap();sourcepub fn remove_wakeword(&mut self, name: &str)
pub fn remove_wakeword(&mut self, name: &str)
Removes a wakeword by name.
sourcepub fn set_threshold(&mut self, threshold: f32)
pub fn set_threshold(&mut self, threshold: f32)
Sets detector threshold.
sourcepub fn set_averaged_threshold(&mut self, averaged_threshold: f32)
pub fn set_averaged_threshold(&mut self, averaged_threshold: f32)
Sets detector averaged threshold.
sourcepub fn set_wakeword_threshold(&mut self, name: &str, threshold: f32)
pub fn set_wakeword_threshold(&mut self, name: &str, threshold: f32)
Sets wakeword threshold.
sourcepub fn set_wakeword_averaged_threshold(
&mut self,
name: &str,
averaged_threshold: f32
)
pub fn set_wakeword_averaged_threshold(
&mut self,
name: &str,
averaged_threshold: f32
)
Sets wakeword averaged threshold.
sourcepub fn process_buffer(
&mut self,
audio_buffer: &[u8]
) -> Option<DetectedWakeword>
pub fn process_buffer(
&mut self,
audio_buffer: &[u8]
) -> Option<DetectedWakeword>
Process bytes buffer.
Asserts that the buffer length should match the return of the get_bytes_per_frame method.
Assumes sample rate match the configured for the detector.
Assumes little endian order on the buffer.
Asserts that detector bits_per_sample is 8, 16, 24 or 32 (float format only allows 32).
sourcepub fn process(&mut self, audio_chunk: &[i32]) -> Option<DetectedWakeword>
pub fn process(&mut self, audio_chunk: &[i32]) -> Option<DetectedWakeword>
Process i32 audio chunks.
Asserts that the audio chunk length should match the return of the get_samples_per_frame method.
Assumes sample rate match the configured for the detector.
Asserts that detector bits_per_sample is one of: 8, 16, 24, 32.
Asserts that detector sample_format is ‘int’.
It’s an alias for the process_i32 method.
sourcepub fn process_i8(&mut self, audio_chunk: &[i8]) -> Option<DetectedWakeword>
pub fn process_i8(&mut self, audio_chunk: &[i8]) -> Option<DetectedWakeword>
Process i8 audio chunks.
Asserts that the audio chunk length should match the return of the get_samples_per_frame method.
Assumes sample rate match the configured for the detector.
Asserts that detector bits_per_sample is 8.
Asserts that detector sample_format is ‘int’.
sourcepub fn process_i16(&mut self, audio_chunk: &[i16]) -> Option<DetectedWakeword>
pub fn process_i16(&mut self, audio_chunk: &[i16]) -> Option<DetectedWakeword>
Process i16 audio chunks.
Asserts that the audio chunk length should match the return of the get_samples_per_frame method.
Assumes sample rate match the configured for the detector.
Asserts that detector bits_per_sample is one of: 8, 16.
Asserts that detector sample_format is ‘int’.
sourcepub fn process_i32(&mut self, audio_chunk: &[i32]) -> Option<DetectedWakeword>
pub fn process_i32(&mut self, audio_chunk: &[i32]) -> Option<DetectedWakeword>
Process i32 audio chunks.
Asserts that the audio chunk length should match the return of the get_samples_per_frame method.
Assumes sample rate match the configured for the detector.
Asserts that detector bits_per_sample is one of: 8, 16, 24, 32.
Asserts that detector sample_format is ‘int’.
sourcepub fn process_f32(&mut self, audio_chunk: &[f32]) -> Option<DetectedWakeword>
pub fn process_f32(&mut self, audio_chunk: &[f32]) -> Option<DetectedWakeword>
Process f32 audio chunks.
Asserts that the audio chunk length should match the return of the get_samples_per_frame method.
Assumes sample rate match the configured for the detector.
Asserts that detector bits_per_sample is 32.
Asserts that detector sample_format is ‘float’.
sourcepub fn get_samples_per_frame(&self) -> usize
pub fn get_samples_per_frame(&self) -> usize
Returns the desired chunk size.
sourcepub fn get_bytes_per_frame(&self) -> usize
pub fn get_bytes_per_frame(&self) -> usize
Returns size in bytes for the desired chunk
Auto Trait Implementations
impl !RefUnwindSafe for WakewordDetector
impl Send for WakewordDetector
impl Sync for WakewordDetector
impl Unpin for WakewordDetector
impl !UnwindSafe for WakewordDetector
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more