tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
M\¬Qc@s*dZddgZd„Zd„ZgZd„Zejeƒd„Zejeƒd„Zejeƒd„Z    eje    ƒd    „Z
eje
ƒd
„Z eje ƒd „Z eje ƒd „Z eje ƒd „Zd„Zd„Zd„Zd„Zd„Zedkr&eƒndS(s¶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, IOError 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.
twhattwhathdrcCst|ƒ}|S(sGuess the type of a sound file(R(tfilenametres((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyR#s cCsLt|dƒ}|jdƒ}x'tD]}|||ƒ}|r%|Sq%WdS(sRecognize sound headerstrbiN(topentreadtteststNone(RtfthttfR((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyR)s cCsÌddl}|d dkr dS|dd!dkr<d}n |dd!dkrXd    }ndS|jd
ƒy|j|d ƒ}Wnt|jfk
rœdSX||jƒ|jƒ|jƒd|j    ƒfS( NiÿÿÿÿitFORMii tAIFCtaifctAIFFtaiffitr(
RRtseektopenfptEOFErrortErrort getframeratet getnchannelst
getnframest getsampwidth(R
R    Rtfmtta((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyt    test_aifc:s          c Cs |d dkrt}n|d dkr2t}ndSd}||dd!ƒ}||dd!ƒ}||dd!ƒ}||dd    !ƒ}||d    d
!ƒ}d }|d kr¶d }    n6|d krËd}    n!|dkræd}    d }nd}    ||}
|||||
|    fS(Nis.sndtds.sdns.tauii iiiitUiit?(Rsdns.(t get_long_bet get_long_leR( R
R    ttypethdr_sizet    data_sizetencodingtratet    nchannelst sample_sizet sample_bitst
frame_size((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyttest_auOs,                       
cCsT|dd!dks&|dd!dkr*dSt|dd!ƒ}d    d
|d d d fS(NiAiEtFSSDi€i„tHCOMiithcomi"Viiÿÿÿÿiii”(RR!(R
R    tdivisor((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyt    test_hcomls&cCs—|d dkrdSt|dd!ƒ}d}d|koDdknr„||dkr„t||dƒ}tdd    |ƒ}nd
|d d d fS(NisCreative Voice Fileiiiôsig€„.Aitvociiÿÿÿÿi(Rt get_short_letordtint(R
R    tsbseekR'tratecode((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyttest_vocus,cCs™|d dks6|dd!dks6|dd!dkr:dSt|dd    !ƒ}t|d    d
!ƒ}t|d
d !ƒ}t|d d !ƒ}d||d|fS(NitRIFFii tWAVEisfmt iiiii"i$twaviÿÿÿÿ(RR3R"(R
R    tstyleR(R'R*((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyttest_wav‚s6cCs+|d dks#|dd!dkr'dSd    S(
NiR ii t8SVXt8svxii(R?iiii(R(R
R    ((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyt    test_8svxs#cCsM|d dkrIt|dd!ƒ}t|dd!ƒ}d|d|dfSdS(    NitSOUNDii iitsndti(R"R3(R
R    tnsamplesR'((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyt    test_sndt˜scCsY|d dkrUt|dd!ƒ}d|ko:dknrUd|ddd    fSndS(
Nitii i¨atsndriiÿÿÿÿi(R3(R
R    R'((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyt    test_sndr¡scCsDt|dƒd>t|dƒd>Bt|dƒd>Bt|dƒBS(Niiiiiii(R4(ts((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyR!®scCsDt|dƒd>t|dƒd>Bt|dƒd>Bt|dƒBS(Niiiiiii(R4(RH((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyR"±scCs t|dƒd>t|dƒBS(Niii(R4(RH((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyt get_short_be´scCs t|dƒd>t|dƒBS(Niii(R4(RH((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyR3·scCs»ddl}d}|jdrH|jddkrH|jdd5d}ny>|jdrrt|jd|dƒntdg|dƒWn.tk
r¶|jjdƒ|jdƒnXdS(Niÿÿÿÿiis-rit.s
[Interrupted]
(tsystargvttestalltKeyboardInterrupttstderrtwritetexit(RKt    recursive((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyttest¿s         cCsÚddl}ddl}x»|D]³}|jj|ƒr•|dG|sK|rdGHddl}|j|jj|dƒƒ}t||dƒqÒdGHq|dG|jjƒyt    |ƒGHWqt
k
rÑdGHqXqWdS(    Niÿÿÿÿs/:srecursing down:t*is*** directory (use -r) ***t:s*** not found ***( RKtostpathtisdirtglobtjoinRMtstdouttflushRtIOError(tlistRRttoplevelRKRVRRYtnames((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyRMÎs"       t__main__N(t__doc__t__all__RRRRtappendR,R1R8R=R@RDRGR!R"RIR3RSRMt__name__(((sN/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/sndhdr.pyt<module>s8