
    -cJji                     t   d dl Z 	 d dlZd dlmZ d dlmZ  ej                         d        Z	e	j                  d	       ej                  d
 ej
                  dd             ej                  d ej
                                ej                  dedd       ej                  d ej                  g dd      dd       ej                  ded       ej                  ded      d
edededededefd                                                  Zy# e$ r  ed        ed        ed        w xY w)!    Nz
Please runz  pip install clickzbefore you continue)Path)
text2tokenc                  N    t        j                  dt         j                         y)z/
    The shell entry point to sherpa-onnx.
    z?%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s)formatlevelN)loggingbasicConfigINFO     Y/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/sherpa_onnx/cli.pyclir      s    
 Pllr   r   )nameinputTF)existsdir_okay)typeoutputz--tokenszThe path to tokens.txt.)r   requiredhelpz--tokens-type)cjkcharbpezcjkchar+bpefpinyinppinyinzphone+ppinyin)case_sensitivea3  The type of modeling units, should be cjkchar, bpe, cjkchar+bpe, fpinyin, ppinyin or phone+ppinyin.
    fpinyin means full pinyin, each cjkchar has a pinyin(with tone).
    ppinyin means partial pinyin, it splits pinyin into initial and final,
    phone means English phonemes in CMU dictionary format.
    z--bpe-modelzLThe path to bpe.model. Only required when tokens-type is bpe or cjkchar+bpe.)r   r   z	--lexiconzIThe path to lexicon.txt. Only required when tokens-type is phone+ppinyin.tokenstokens_type	bpe_modellexiconc                 p   g }g }t        | dd      5 }|D ]  }	g }
g }|	j                         j                         }|D ]=  }|d   dk(  s|d   dk(  s|d   dk(  r|
j                  |       -|j                  |       ? |j                  dj	                  |             |j                  |
        	 d	d	d	       t        |||||
      }t        |dd      5 }t        |      D ]0  \  }}|||   z  }|j                  dj	                  |      dz          2 	 d	d	d	       y	# 1 sw Y   pxY w# 1 sw Y   y	xY w)u  
    Encode the texts given by the INPUT to tokens and write the results to the OUTPUT.
    Each line in the texts contains the original phrase, it might also contain some
    extra items, for example, the boosting score (starting with :), the triggering
    threshold (starting with #, only used in keyword spotting task) and the original
    phrase (starting with @). Note: the extra items will be kept same in the output.

    example input 1 (tokens_type = ppinyin):

    小爱同学 :2.0 #0.6 @小爱同学
    你好问问 :3.5 @你好问问
    小艺小艺 #0.6 @小艺小艺

    example output 1:

    x iǎo ài t óng x ué :2.0 #0.6 @小爱同学
    n ǐ h ǎo w èn w èn :3.5 @你好问问
    x iǎo y ì x iǎo y ì #0.6 @小艺小艺

    example input 2 (tokens_type = bpe):

    HELLO WORLD :1.5 #0.4
    HI GOOGLE :2.0 #0.8
    HEY SIRI #0.35

    example output 2:

    ▁HE LL O ▁WORLD :1.5 #0.4
    ▁HI ▁GO O G LE :2.0 #0.8
    ▁HE Y ▁S I RI #0.35
    rutf8)encodingr   :#@ N)r   r   r   r   w
)openstripsplitappendjoinr   	enumeratewrite)r   r   r   r   r   r   texts
extra_infoflineextratexttokstokencoded_textsitxts                    r   encode_textr<      s0   \ E J	eS6	*aDED::<%%'Dq6S=CFcMSVs]LL%KK$	 
 LL$(e$  
+ M 
fcF	+q.FAs:a= CGGCHHSMD() / 
,	+) 
+	*( 
,	+s   BD ?D, D),D5)r   clickImportErrorprintpathlibr   sherpa_onnxr   groupr   commandargumentoptionstrChoicer<   r   r   r   <module>rH      s   
  "   ,jejjuEFzuzz|,		"	 		
 

 
( 		W
 		T
B*B*B* B* 	B*
 B* B*) - G  NB*y  
	,	
 	
 		
s   D D7