grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026U iÛf»ã@s2dZddgZddlmZeddƒZdej_dej_d ej_d ej_d ej _d d„Z d d„Z gZ dd„Z e  e ¡dd„Ze  e¡dd„Ze  e¡dd„Ze  e¡dd„Ze  e¡dd„Ze  e¡dd„Ze  e¡dd„Ze  e¡dd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zed*k�r.eƒd+S),a¶Routines to help recognizing sound files. Function whathdr() recognizes various types of sound file headers. It understands almost all headers that SOX can decode. The return tuple contains the following items, in this order: - file type (as SOX understands it) - sampling rate (0 if unknown or hard to decode) - number of channels (0 if unknown or hard to decode) - number of frames in the file (-1 if unknown or hard to decode) - number of bits/sample, or 'U' for U-LAW, or 'A' for A-LAW If the file doesn't have a recognizable type, it returns None. If the file can't be opened, OSError is raised. To compute the total time, divide the number of frames by the sampling rate (a frame contains a sample for each channel). Function what() calls whathdr(). (It used to also use some heuristics for raw data, but this doesn't work very well.) Finally, the function test() is a simple main program that calls what() for all files mentioned on the argument list. For directory arguments it calls what() for all files in that directory. Default argument is "." (testing all files in the current directory). The option -r tells it to recurse down directories found inside explicitly given directories. ÚwhatÚwhathdré)Ú namedtupleÚ SndHeadersz.filetype framerate nchannels nframes sampwidthz¡The value for type indicates the data type and will be one of the strings 'aifc', 'aiff', 'au','hcom', 'sndr', 'sndt', 'voc', 'wav', '8svx', 'sb', 'ub', or 'ul'.zYThe sampling_rate will be either the actual value or 0 if unknown or difficult to decode.z^The number of channels or 0 if it cannot be determined or if the value is difficult to decode.z?The value for frames will be either the number of frames or -1.zAEither the sample size in bits or 'A' for A-LAW or 'U' for u-LAW.cCs t|ƒ}|S)zGuess the type of a sound file.)r)ÚfilenameÚres©rú+/opt/alt/python38/lib64/python3.8/sndhdr.pyr4sc Cs^t|dƒ�J}| d¡}tD]*}|||ƒ}|rt|ŽW5QR£SqW5QR£dSQRXdS)zRecognize sound headers.ÚrbiN)ÚopenÚreadÚtestsr)rÚfÚhZtfrrrr r:s   c Cs ddl}| d¡sdS|dd…dkr,d}n|dd…dkrBd}ndS| d¡z| |d ¡}Wnt|jfk r|YdSX|| ¡| ¡| ¡d|  ¡fS) NróFORMéé sAIFCÚaifcsAIFFZaiffÚr) rÚ startswithÚseekr ÚEOFErrorÚErrorÚ getframerateÚ getnchannelsÚ getnframesÚ getsampwidth)rrrZfmtÚarrr Ú test_aifcKs"   ÿrc CsÜ| d¡rt}n|dd…dkr&t}ndSd}||dd…ƒ}||dd…ƒ}||dd…ƒ}||dd…ƒ}||dd …ƒ}d } |d kr�d } n$|d kržd} n|d kr°d} d } nd} | |} | rÊ|| } nd} |||| | fS)Ns.sndé)sds.sdns.ZaurrééééÚUééú?éÿÿÿÿ)rÚ get_long_beÚ get_long_le) rrÚfuncÚfiletypeZhdr_sizeÚ data_sizeÚencodingÚrateÚ nchannelsZ sample_sizeZ sample_bitsZ frame_sizeZnframerrr Útest_au`s2  r1cCsT|dd…dks |dd…dkr$dSt|dd…ƒ}|rBd |}nd }d |d d dfS)NéAéEsFSSDé€é„sHCOMé�é”i"VrZhcomr#r(r)r))rrZdivisorr/rrr Ú test_hcom�s  r8cCst| d¡sdSt|dd…ƒ}d}d|kr6dkrfnn,||dkrfd||d}|rftd |ƒ}d |dd d fS) NsCreative Voice Filer!ériôr#érg€„.AZvocr(r)rÚ get_short_leÚint)rrZsbseekr/Zratecoderrr Útest_vocŽs $ r=c Cs�ddl}| d¡r2|dd…dks2|dd…dkr6dS| d¡z| |d¡}Wnt|jfk rlYdSXd | ¡| ¡| ¡d|  ¡fS) NrsRIFFrrsWAVEr sfmt rZwav) Úwaverrr rrrrrr)rrr>Úwrrr Útest_wavœs*  ÿr@cCs"| d¡r|dd…dkrdSdS)Nrrrs8SVX)Z8svxrr#rr)r)rrrrr Ú test_8svx¬srAcCs<| d¡r8t|dd…ƒ}t|dd…ƒ}d|d|dfSdS)NsSOUNDrrr!r9Zsndtr#)rr*r;)rrZnsamplesr/rrr Ú test_sndtµs rBcCsD| d¡r@t|dd…ƒ}d|kr.dkr@nnd|ddd fSdS) Nsr%ri i¨aZsndrr#r(r)rr;)rrr/rrr Ú test_sndr¾s rCcCs,|dd>|dd>B|dd>B|dBS)Nrr"r#r r%rr&r©Úbrrr r)Ësr)cCs,|dd>|dd>B|dd>B|dBS)Nr&r"r%r r#rrrrDrrr r*Îsr*cCs|dd>|dBS)Nrrr#rrDrrr Ú get_short_beÑsrFcCs|dd>|dBS)Nr#rrrrDrrr r;Ôsr;cCs ddl}d}|jdd…r8|jddkr8|jdd…=d}z8|jdd…r`t|jdd…|dƒntdg|dƒWn*tk rš|j d¡| d¡YnXdS)Nrr#z-rr%Ú.z [Interrupted] )ÚsysÚargvÚtestallÚKeyboardInterruptÚstderrÚwriteÚexit)rHÚ recursiverrr ÚtestÜs  rPc CsÌddl}ddl}|D]²}|j |¡r~t|ddd�|s<|rttdƒddl}| |j | |¡d¡¡}t||dƒqÆtdƒqt|ddd�|j   ¡ztt |ƒƒWqt k rÄtd ƒYqXqdS) Nrz/:ú )Úendzrecursing down:Ú*z*** directory (use -r) ***ú:z*** not found ***) rHÚosÚpathÚisdirÚprintÚglobÚjoinÚescaperJÚstdoutÚflushrÚOSError)ÚlistrOZtoplevelrHrUrrYÚnamesrrr rJës"   rJÚ__main__N)Ú__doc__Ú__all__Ú collectionsrrr,Z framerater0ZnframesZ sampwidthrrr rÚappendr1r8r=r@rArBrCr)r*rFr;rPrJÚ__name__rrrr ÚsJ  ÿ