snowboy package

Submodules

snowboy.snowboydecoder module

class snowboy.snowboydecoder.ActiveListener(decoder_model, resource='/Users/panweizhou/Documents/projects/wukong-robot/snowboy/resources/common.res')[源代码]

基类:object

Active Listening with VAD

listen(interrupt_check=<function ActiveListener.<lambda>>, sleep_time=0.03, silent_count_threshold=15, recording_timeout=100)[源代码]
参数:
  • interrupt_check – a function that returns True if the main loop needs to stop.
  • silent_count_threshold – indicates how long silence must be heard to mark the end of a phrase that is being recorded.
  • sleep_time (float) – how much time in second every loop waits.
  • recording_timeout – limits the maximum length of a recording.
返回:

recorded file path

saveMessage()[源代码]

Save the message stored in self.recordedData to a timestamped file.

class snowboy.snowboydecoder.HotwordDetector(decoder_model, resource='/Users/panweizhou/Documents/projects/wukong-robot/snowboy/resources/common.res', sensitivity=[], audio_gain=1, apply_frontend=False)[源代码]

基类:object

Snowboy decoder to detect whether a keyword specified by decoder_model exists in a microphone input stream.

参数:
  • decoder_model – decoder model file path, a string or a list of strings
  • resource – resource file path.
  • sensitivity – decoder sensitivity, a float of a list of floats. The bigger the value, the more senstive the decoder. If an empty list is provided, then the default sensitivity in the model will be used.
  • audio_gain – multiply input volume by this factor.
  • apply_frontend – applies the frontend processing algorithm if True.
saveMessage()[源代码]

Save the message stored in self.recordedData to a timestamped file.

start(detected_callback=<function play_audio_file>, interrupt_check=<function HotwordDetector.<lambda>>, sleep_time=0.03, audio_recorder_callback=None, silent_count_threshold=15, recording_timeout=100)[源代码]

Start the voice detector. For every sleep_time second it checks the audio buffer for triggering keywords. If detected, then call corresponding function in detected_callback, which can be a single function (single model) or a list of callback functions (multiple models). Every loop it also calls interrupt_check – if it returns True, then breaks from the loop and return.

参数:
  • detected_callback – a function or list of functions. The number of items must match the number of models in decoder_model.
  • interrupt_check – a function that returns True if the main loop needs to stop.
  • sleep_time (float) – how much time in second every loop waits.
  • audio_recorder_callback – if specified, this will be called after a keyword has been spoken and after the phrase immediately after the keyword has been recorded. The function will be passed the name of the file where the phrase was recorded.
  • silent_count_threshold – indicates how long silence must be heard to mark the end of a phrase that is being recorded.
  • recording_timeout – limits the maximum length of a recording.
返回:

None

terminate()[源代码]

Terminate audio stream. Users can call start() again to detect. :return: None

class snowboy.snowboydecoder.RingBuffer(size=4096)[源代码]

基类:object

Ring buffer to hold audio from PortAudio

extend(data)[源代码]

Adds data to the end of buffer

get()[源代码]

Retrieves data from the beginning of buffer and clears it

snowboy.snowboydecoder.no_alsa_error()[源代码]
snowboy.snowboydecoder.play_audio_file(fname='/Users/panweizhou/Documents/projects/wukong-robot/snowboy/resources/ding.wav')[源代码]

Simple callback function to play a wave file. By default it plays a Ding sound.

参数:fname (str) – wave file name
返回:None
snowboy.snowboydecoder.py_error_handler(filename, line, function, err, fmt)[源代码]

snowboy.snowboydetect module

class snowboy.snowboydetect.SnowboyDetect(resource_filename, model_str)[源代码]

基类:object

ApplyFrontend(apply_frontend)[源代码]
BitsPerSample()[源代码]
GetSensitivity()[源代码]
NumChannels()[源代码]
NumHotwords()[源代码]
Reset()[源代码]
RunDetection(*args)[源代码]
SampleRate()[源代码]
SetAudioGain(audio_gain)[源代码]
SetHighSensitivity(high_sensitivity_str)[源代码]
SetSensitivity(sensitivity_str)[源代码]
UpdateModel()[源代码]
class snowboy.snowboydetect.SnowboyVad(resource_filename)[源代码]

基类:object

ApplyFrontend(apply_frontend)[源代码]
BitsPerSample()[源代码]
NumChannels()[源代码]
Reset()[源代码]
RunVad(*args)[源代码]
SampleRate()[源代码]
SetAudioGain(audio_gain)[源代码]

Module contents