
    9in                        S SK r S SKrS SKJr  S SKrS SK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  S S	KJr  \" 5       rS
/r\R6                  " \R8                  \R8                  S9 " S S
\5      5       rg)    N)Union)File)	Pipelines)
OutputKeys)
InputModelPipeline)	PIPELINES)Tasks)
get_loggerLanguageRecognitionPipeline)module_namec            
          ^  \ rS rSrSrS\4U 4S jjr SS\\\	\
R                  4   S\4S jjrS\	4S	 jr SS\	S
\	S\\\	\
R                  4   4S jjrS\\\	\
R                  4   4S jrSrU =r$ )r      a  Language Recognition Inference Pipeline
use `model` to create a Language Recognition pipeline.

Args:
    model (LanguageRecognitionPipeline): A model instance, or a model local dir, or a model id in the model hub.
    kwargs (dict, `optional`):
        Extra kwargs passed into the pipeline's constructor.
Example:
>>> from modelscope.pipelines import pipeline
>>> from modelscope.utils.constant import Tasks
>>> p = pipeline(
>>>    task=Tasks.speech_language_recognition, model='damo/speech_campplus_lre_en-cn_16k')
>>> print(p(audio_in))

modelc                    > [         TU ]  " SSU0UD6  U R                  R                  U l        U R                  S   U l        g)zvuse `model` to create a Language Recognition pipeline for prediction
Args:
    model (str): a valid official model id
r   	languagesN )super__init__r   model_configr   )selfr   kwargs	__class__s      x/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/pipelines/audio/language_recognition_pipeline.pyr   $LanguageRecognitionPipeline.__init__-   s>    
 	/u// JJ33**;7    	in_audiosout_filec                 r    U R                  U5      nU R                  U5      u  pEU R                  XTX5      nU$ N)
preprocessforwardpostprocess)r   r   r   wavsscoresresultsoutputss          r   __call__$LanguageRecognitionPipeline.__call__6   s9     y),,t,""7IHr   inputsc                     / n/ nU HT  nU R                  U5      u  pVUR                  UR                  5       5        UR                  UR                  5       5        MV     X#4$ r    )r   appendtolistitem)r   r*   r%   r&   xscoreresults          r   r"   #LanguageRecognitionPipeline.forward>   sS    A JJqMMEMM%,,.)NN6;;=)  r   r%   c                    [        U[        5      (       a4  [        R                  U R                  US      [        R
                  U0nU$ [        R                  U Vs/ s H  o`R                  U   PM     sn[        R
                  U0nUb  / n[        U5       Hw  u  ph[        U[        5      (       a3  [        R                  R                  U5      R                  SS5      S   n	OUn	UR                  U	< SU R                  X      < S35        My     [        US5       n
U H  nU
R                  U5        M     S S S 5        U$ U$ s  snf ! , (       d  f       U$ = f)Nr   .    
w)
isinstancestrr   TEXTr   SCORE	enumerateospathbasenamersplitr,   openwrite)r   r*   r%   r   r   outputi	out_linesaudioaudio_idfs              r   r#   'LanguageRecognitionPipeline.postprocessG   s7   
 i%%q	!:  &F*  V!DV.."3V!D  &F #	 )) 4HA!%--#%77#3#3E#:#A#A#q#I!#L#$$$&.vy0I&K L !5 (C(A&
 ' ) v "E )( s   E E
Ec           
      T   / n[        U[        5      (       Ga  [        R                  " U5      n[        R                  " [
        R                  " U5      SS9u  pE[        UR                  5      S:X  a	  US S 2S4   n[        R                  " U5      R                  S5      nXPR                  S   :w  a_  [        R                  SU R                  S   -  5        [        R                   R#                  UUS[        U R                  S   5      //S9u  pEUR%                  S5      nUR'                  U5        U$ [)        [        U5      5       GH  n[        X   [        5      (       Ga  [        R                  " X   5      n[        R                  " [
        R                  " U5      SS9u  pE[        UR                  5      S:X  a	  US S 2S4   n[        R                  " U5      R                  S5      nXPR                  S   :w  a_  [        R                  SU R                  S   -  5        [        R                   R#                  UUS[        U R                  S   5      //S9u  pEUR%                  S5      nO[        X   [*        R,                  5      (       as  [        X   R                  5      S	:X  d   S
5       eX   nUR.                  S;   a  US-  R1                  S5      nOUR1                  S5      n[        R                  " U5      nO[3        S5      eUR'                  U5        GM     U$ )Nfloat32)dtype   r   sample_ratez0The sample rate of audio is not %d, resample it.rate)effectsr5   z.modelscope error: Input array should be [N, T])int16int32int64i   zOmodelscope error: The input type is restricted to audio address and nump array.)r9   r:   r   readsfioBytesIOlenshapetorch
from_numpy	unsqueezer   loggerwarning
torchaudiosox_effectsapply_effects_tensorsqueezer,   rangenpndarrayrM   astype
ValueError)r   r*   rD   
file_bytesdatafsrE   s          r   r!   &LanguageRecognitionPipeline.preprocessd   s   fc""6*Jwwrzz*5YGHD4::!#AqDz##D)33A6D&&}55F''678 &11FF$!$"3"3M"BCE F G G
 <<?DMM$H E 3v;'fi--!%69!5J!wwrzz*'=YOHD4::!+#AqDz ++D1;;A>D..}==N"//>?@ $.#9#9#N#N  & #D$5$5m$D E& % $O $   <<?D	2::66	 MLM  "9Dzz%@@ $ 088C#{{95 ++D1D$i  d#C (D r   )r   r   r    )__name__
__module____qualname____firstlineno____doc__r   r   r   r:   listre   rf   r(   r"   r#   r!   __static_attributes____classcell__)r   s   @r   r   r      s     8j 8 "&!#tRZZ"78d  "	    %S$

%:;:6sD"**'<!= 6 6r   )rW   r>   typingr   numpyre   	soundfilerV   r[   r`   modelscope.fileior   modelscope.metainfor   modelscope.outputsr   modelscope.pipelines.baser   r   modelscope.pipelines.builderr	   modelscope.utils.constantr
   modelscope.utils.loggerr   r^   __all__register_modulespeech_language_recognitionr   r   r   r   <module>r      s{    
 	      " ) ) : 2 + .	(
) 	%%557~( ~7~r   