grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026 ú“qcã@svdZddgZddlmZeddƒZdd„Zdd„ZgZd d „Zej eƒd d „Z ej e ƒd d„Z ej e ƒdd„Z ej e ƒdd„Z ej e ƒdd„Zej eƒdd„Zej eƒdd„Zej eƒdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zed%krreƒ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 sampwidthcCst|ƒ}|S)zGuess the type of a sound file.)r)ÚfilenameÚres©rú+/opt/alt/python35/lib64/python3.5/sndhdr.pyr(s c Cs`t|dƒ�J}|jdƒ}x-tD]%}|||ƒ}|r(t|ŒSq(WdSWdQRXdS)zRecognize sound headers.ÚrbiN)ÚopenÚreadÚtestsr)rÚfÚhZtfrrrr r.s cCsÕddl}|jdƒsdS|dd…dkr>d}n#|dd…dkr]d}ndS|jdƒy|j|d ƒ}Wnt|jfk r¥dSYnX||jƒ|jƒ|jƒd|j ƒfS) NrsFORMéé sAIFCÚaifcsAIFFZaiffÚr) rÚ startswithÚseekr ÚEOFErrorÚErrorÚ getframerateÚ getnchannelsÚ getnframesÚ getsampwidth)rrrZfmtÚarrr Ú test_aifc?s     rc Cs6|jdƒrt}n#|dd…dkr7t}ndSd}||dd…ƒ}||dd…ƒ}||dd…ƒ}||dd …ƒ}||d d …ƒ}d } |d krÊd } n6|d krßd} n!|dkrúd} d } nd} | |} | r|| } nd} |||| | fS)Ns.sndéóds.ódns.ZaurrééééÚUééú?)rr éÿÿÿÿ)rÚ get_long_beÚ get_long_le) rrÚfuncZfiletypeZhdr_sizeZ data_sizeÚencodingÚrateZ nchannelsZ sample_sizeZ sample_bitsZ frame_sizeZnframerrr Útest_auTs2          r/cCsr|dd…dks,|dd…dkr0dSt|dd…ƒ}|rYd |}nd }d |d dd fS)NéAéEsFSSDé€é„sHCOMé�é”i"VrZhcomr$rr))r*)rrZdivisorr.rrr Ú test_hcomus, r6cCs–|jdƒsdSt|dd…ƒ}d}d|koFdknrƒ||dkrƒd||d}|rƒtd |ƒ}d |dd d fS) NsCreative Voice Filer"ériôr$érg€„.AZvocrr))rÚ get_short_leÚint)rrZsbseekr.Zratecoderrr Útest_voc‚s,r;cCsÀddl}|jdƒ sH|dd…dksH|dd…dkrLdS|jdƒy|j|dƒ}Wnt|jfk r�dSYnXd |jƒ|jƒ|jƒd|j ƒfS) NrsRIFFrrsWAVEr!sfmt rZwav) ÚwaverrZopenfprrrrrr)rrr<Úwrrr Útest_wav�s <  r>cCs.|jdƒ s&|dd…dkr*dSdS) NsFORMrrs8SVXÚ8svxrr$)r?rr$rr)r)rrrrr Ú test_8svx s&r@cCsR|jdƒrNt|dd…ƒ}t|dd…ƒ}d|d|dfSdS)NsSOUNDrrr"r7Zsndtr$)rr+r9)rrZnsamplesr.rrr Ú test_sndt©srAcCsX|jdƒrTt|dd…ƒ}d|ko<dknrTd|dd dfSdS) Nsr&ri i¨aZsndrr$rr))rr9)rrr.rrr Ú test_sndr²srBcCs,|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$rrr)rCrrr r+Âsr+cCs|dd>|dBS)Nrrr$r)rCrrr Ú get_short_beÅsrDcCs|dd>|dBS)Nr$rrr)rCrrr r9Èsr9c CsÎddl}d}|jdd…rN|jddkrN|jdd…=d}yJ|jdd…r„t|jdd…|dƒntdg|dƒWn/tk rÉ|jjdƒ|jdƒYnXdS)Nrr$z-rr&Ú.z [Interrupted] )ÚsysÚargvÚtestallÚKeyboardInterruptÚstderrÚwriteÚexit)rFÚ recursiverrr ÚtestÐs &  rNc Csddl}ddl}xè|D]à}|jj|ƒr«t|dddƒ|sW|ržtdƒddl}|j|jj|dƒƒ}t||dƒqÿtdƒqt|dddƒ|jj ƒytt |ƒƒWqt k rþtd ƒYqXqWdS) Nrz/:Úendú zrecursing down:Ú*z*** directory (use -r) ***ú:z*** not found ***) rFÚosÚpathÚisdirÚprintÚglobÚjoinrHÚstdoutÚflushrÚOSError)ÚlistrMZtoplevelrFrSrrWÚnamesrrr rHßs"         rHÚ__main__N)Ú__doc__Ú__all__Ú collectionsrrrrr rÚappendr/r6r;r>r@rArBr*r+rDr9rNrHÚ__name__rrrr Ús>