Files
Hotword-detection/__pycache__/snowboydecoder.cpython-38.pyc

79 lines
6.4 KiB
Plaintext
Raw Normal View History

2023-01-16 20:36:17 +01:00
U
<00>ƆW<C686><00>@s<>ddlZddlZddlZddlZddlZddlZddlZe<06><07>e<06>d<02>Z e <09>
ej <0B>ej <0C> ej <0C>e<0F><01>Zej <0C>ed<03>Zej <0C>ed<04>Zej <0C>ed<05>ZGdd<07>de<15>Zefdd <09>ZGd
d <0B>d e<15>ZdS) <0C>NZsnowboyzresources/common.reszresources/ding.wavzresources/dong.wavc@s*eZdZdZd
dd<04>Zdd<06>Zdd<08>Zd S) <0B>
RingBufferz(Ring buffer to hold audio from PortAudio<69>cCstj|d<01>|_dS)N)Zmaxlen)<03> collectionsZdeque<75>_buf)<02>self<6C>size<7A>r<00>0D:\Documents\Hotword Detection\snowboydecoder.py<70>__init__szRingBuffer.__init__cCs|j<00>|<01>dS)zAdds data to the end of bufferN)r<00>extend)r<00>datarrr r szRingBuffer.extendcCsd<01>|j<01>}|j<01><02>|S)z9Retrieves data from the beginning of buffer and clears it<69>)<03>joinr<00>clear)rZtmprrr <00>gets 
zRingBuffer.getN)r)<07>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__r
r rrrrr rs
rcCs<>t<00>|d<01>}|<01>|<01><03><00>}t<04><05>}|j|<03>|<01><07><00>|<01><08>|<01> <09>ddd<04>}|<04>
<EFBFBD>|<04> |<02>t <0C> d<05>|<04><0E>|<04><0F>|<03><10>dS)z<>Simple callback function to play a wave file. By default it plays
a Ding sound.
:param str fname: wave file name
:return: None
ZrbFT)<05>format<61>channels<6C>rate<74>input<75>outputg<74><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?N)<11>wave<76>openZ
readframesZ
getnframes<EFBFBD>pyaudio<69>PyAudio<69>get_format_from_widthZ getsampwidthZ getnchannelsZ getframerateZ start_stream<61>write<74>time<6D>sleep<65> stop_stream<61>close<73> terminate)ZfnameZding_wavZ ding_data<74>audioZ
stream_outrrr <00>play_audio_file%s   <02>

r&c@s<eZdZdZegdfdd<04>Zedd<06>dfdd <09>Zd
d <0B>Zd S) <0A>HotwordDetectorab
Snowboy decoder to detect whether a keyword specified by `decoder_model`
exists in a microphone input stream.
:param decoder_model: decoder model file path, a string or a list of strings
:param resource: resource file path.
:param 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.
:param audio_gain: multiply input volume by this factor.
<20>c
sN<00>fdd<02>}t|<01>}t|<03>}|tk r*|g}|tk r8|g}d<03>|<01>}tj||d<04><02>_<05>j<05>|<04><00>j<05><07><00>_t |<01>dkr<>t |<03>dkr<>|<03>j}t |<03>dkr<><72>jt |<03>ks<>t
d<07>jt |<03>f<00><01>d<03>dd <09>|D<00><01>} t |<03>dkr<><72>j<05> | <09>t <0C>j<05> <0A><00>j<05><0E>d
<00><01>_t<10><11><00>_<12>jjd d <0C>j<12><14>j<05><15>d <00><01>j<05> <0A><00>j<05><0E>d|d<0F><07>_dS)Ncs&<00>j<00>|<00>td<01>t|<00>}|tjfS)Nr)<06> ring_bufferr <00>chr<68>lenrZ
paContinue)Zin_dataZ frame_countZ time_infoZstatusZ play_data<74>rrr <00>audio_callbackMs z0HotwordDetector.__init__.<locals>.audio_callback<63>,)Zresource_filename<6D> model_strr(rzLnumber of hotwords in decoder_model (%d) and sensitivity (%d) does not matchcSsg|] }t|<01><01>qSr)<01>str)<02>.0<EFBFBD>trrr <00>
<listcomp>esz,HotwordDetector.__init__.<locals>.<listcomp><3E>TF<54>i)rrrrrZframes_per_bufferZstream_callback)<17>type<70>listr<00> snowboydetectZ SnowboyDetect<63>detectorZ SetAudioGainZ NumHotwords<64> num_hotwordsr+<00>AssertionErrorZSetSensitivityrZ NumChannelsZ
SampleRater)rrr%rrZ BitsPerSample<6C> stream_in)
rZ decoder_model<65>resource<63> sensitivityZ
audio_gainr-ZtmZtsr/Zsensitivity_strrr,r r
HsP 
<02>  
  <0C><02>  <16>
 <0C><02>zHotwordDetector.__init__cCsdS)NFrrrrr <00><lambda>w<00>zHotwordDetector.<lambda>g<><1E><>Q<EFBFBD><51>?c CsH|<02>rt<00>d<01>dSt|<01>}|tk r*|g}t|<01>dkrJ|jdkrJ||j9}|jt|<01>ksntd|jt|<01>f<00><01>t<00>d<05>|<02>r<>t<00>d<06><00>q:|j<07><08>}t|<05>dkr<>t <09>
|<03>qx|j <0B> |<05>}|dkr<>t<00> d <09>qx|d
kr<>t<00>d <0B>qx|dkrxd t|<06>d }|t <09>dt <09>t <09> <09><00><01>7}t<00>|<07>||d}|dk rx|<08>qxt<00>d<0F>dS)ab
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.
:param detected_callback: a function or list of functions. The number of
items must match the number of models in
`decoder_model`.
:param interrupt_check: a function that returns True if the main loop
needs to stop.
:param float sleep_time: how much time in second every loop waits.
:return: None
zdetect voice returnNr(zMError: hotwords in your models (%d) do not match the number of callbacks (%d)z detecting...zdetect voice breakr<00><><EFBFBD><EFBFBD><EFBFBD>z0Error initializing streams or reading audio data<74><61><EFBFBD><EFBFBD><EFBFBD>ZSilencezKeyword z detected at time: z%Y-%m-%d %H:%M:%Sz finished.)<12>logger<65>debugr6r7r+r:r;r)rr r!r9Z RunDetectionZwarningr0<00>strftime<6D> localtime<6D>info) r<00>detected_callback<63>interrupt_check<63>
sleep_timeZtcr Zans<6E>messageZcallbackrrr <00>startvsH

 <0C><02>


 
    <0C>
 zHotwordDetector.startcCs"|j<00><01>|j<00><02>|j<03><04>dS)zj
Terminate audio stream. Users cannot call start() again to detect.
:return: None
N)r<r"r#r%r$r,rrr r$<00>s

zHotwordDetector.terminateN) rrrr<00> RESOURCE_FILEr
r&rLr$rrrr r';s <02>
.<02>
<r')rrr8r r<00>osZloggingZ basicConfigZ getLoggerrCZsetLevelZINFO<46>path<74>dirname<6D>abspath<74>__file__ZTOP_DIRrrMZ DETECT_DINGZ DETECT_DONG<4E>objectrr&r'rrrr <00><module>s