
    9i                         S SK r S SKrS SKJrJr  S SKrS SKrS SKJ	r	  S SK
Jr  S SKJr  S SKJrJr  S SKJr  S SKJr  \R*                  " \R,                  \R.                  S	9 " S
 S\5      5       rg)    N)AnyDict)File)	Pipelines)
OutputKeys)InputPipeline)	PIPELINES)Tasks)module_namec                      ^  \ rS rSrSrSrSrSrSrU 4S jr	S r
S\S	\\\4   4S
 jrS\\\4   S	\\\4   4S jr SS\R$                  S\R(                  4S jjrS\\\4   S	\\\4   4S jrSrU =r$ )KWSFarfieldPipeline   zA Keyword Spotting Inference Pipeline .

When invoke the class with pipeline.__call__(), it accept only one parameter:
    inputs(str): the path of wav file
i>        c                 P  > [         TU ]  " SSU0UD6  U R                  R                  U R                  5      U l        U R                  R                  5         U R                  U R                  -  nU R                  R                  U-  U l	        SU;   a  US   U l
        g0 U l
        g)zl
use `model` to create a kws far field pipeline for prediction
Args:
    model: model id on modelscope hub.
modelkeyword_mapN )super__init__r   todeviceevalINPUT_CHANNELSSAMPLE_WIDTHsize_in_nframe_keyword_map)selfr   kwargs
frame_size	__class__s       p/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/pipelines/audio/kws_farfield_pipeline.pyr   KWSFarfieldPipeline.__init__    s     	/u//ZZ]]4;;/


((4+<+<<
zz))Z7F" &} 5D "D    c                 
    XU4$ Nr   )r    pipeline_parameterss     r$   _sanitize_parameters(KWSFarfieldPipeline._sanitize_parameters0   s    "9LLLr&   inputsreturnc                     [        U[        5      (       a	  [        US9$ [        U[        5      (       a	  [        US9$ [        U[        5      (       a  U$ [        S[        U5       35      e)N)
input_filezNot supported input type: )
isinstancebytesdictstrr   
ValueErrortype)r    r,   preprocess_paramss      r$   
preprocessKWSFarfieldPipeline.preprocess3   s[    fe$$6**$$6**%%M9$v,HIIr&   c                    US   n[        U[        5      (       a  [        R                  " U5      n[        R                  " [
        R                  " U5      SS9u  pE[        UR                  5      S:X  a-  [        R                  " XD[        R                  " U5      4S5      n/ nSU;   a  [        R                  " US   S5       nUR                  U R                  5        UR!                  U R"                  5        UR%                  U R&                  5        U R)                  XFU5        S S S 5        OU R)                  XF5        [*        R,                  U0$ ! , (       d  f       N = f)Nr/   int16)dtype   output_filewb)r0   r3   r   readsfioBytesIOlenshapenumpystack
zeros_likewaveopensetframerateSAMPLE_RATEsetnchannelsOUTPUT_CHANNELSsetsampwidthr   _processr   KWS_LIST)r    r,   forward_paramsr/   frames
sampleratekws_listfouts           r$   forwardKWSFarfieldPipeline.forward=   s   L)
j#&&:.JWWRZZ
%;7Kv||![[&%2B2B62J!KQOFN*>-8$?4!!$"2"23!!$"6"67!!$"3"34f5	 @? MM&+##X.. @?s   A$E
E"rR   rU   c                 ,   [        SUR                  S   U R                  5       H  nX@R                  -   nXQR                  S   :  a  UR                  S   nXU2S S 24   R                  5       nU R                  R                  U5      nU(       a  UR                  US   5        SU;   d  M  US   S==   X@R                  -  -  ss'   SUS   S'   US   S   nXR                  ;   a  U R                  U   US   S'   UR                  US   5        M     g )Nr   pcmkwsoffsetwakeupr5   keyword)
rangerD   r   tobytesr   forward_decodewriteframesrK   r   append)	r    rR   rT   rU   start_index	end_indexdataresultr]   s	            r$   rO   KWSFarfieldPipeline._processQ   s    !FLLOT\\BK#ll2I<<?*"LLO	i/23;;=DZZ..t4F  /uh';9I9I+II'(0uf% -	2////3/@/@/IF5M),u. Cr&   c                     U$ r(   r   )r    r,   r!   s      r$   postprocessKWSFarfieldPipeline.postprocesse   s    r&   )r   r   r   r(   )__name__
__module____qualname____firstlineno____doc__rK   r   r   rM   r   r*   r   r   r3   r   r7   rV   rE   ndarrayrH   
Wave_writerO   ri   __static_attributes____classcell__)r#   s   @r$   r   r      s    
 KLNO# MJ JS#X J/d38n /%)#s(^/. *.// /($sCx. tCH~  r&   r   )rA   rH   typingr   r   rE   	soundfiler@   modelscope.fileior   modelscope.metainfor   modelscope.outputsr   modelscope.pipelines.baser   r	   modelscope.pipelines.builderr
   modelscope.utils.constantr   register_modulekeyword_spottingspeech_dfsmn_kws_char_farfieldr   r   r&   r$   <module>r      sc    
     " ) ) 5 2 + 	88:Q( Q:Qr&   