eZSrSSKJr SSKrSSKrSSKr/SQr"SS\5rSr Sr S r S r \"S S 5r S r"SS5r"SS5r"SS5rSSjrg)a- Stuff to parse WAVE files. Usage. Reading WAVE files: f = wave.open(file, 'r') where file is either the name of a file or an open file pointer. The open file pointer must have methods read(), seek(), and close(). When the setpos() and rewind() methods are not used, the seek() method is not necessary. This returns an instance of a class with the following public methods: getnchannels() -- returns number of audio channels (1 for mono, 2 for stereo) getsampwidth() -- returns sample width in bytes getframerate() -- returns sampling frequency getnframes() -- returns number of audio frames getcomptype() -- returns compression type ('NONE' for linear samples) getcompname() -- returns human-readable version of compression type ('not compressed' linear samples) getparams() -- returns a namedtuple consisting of all of the above in the above order getmarkers() -- returns None (for compatibility with the old aifc module) getmark(id) -- raises an error since the mark does not exist (for compatibility with the old aifc module) readframes(n) -- returns at most n frames of audio rewind() -- rewind to the beginning of the audio stream setpos(pos) -- seek to the specified position tell() -- return the current position close() -- close the instance (make it unusable) The position returned by tell() and the position given to setpos() are compatible and have nothing to do with the actual position in the file. The close() method is called automatically when the class instance is destroyed. Writing WAVE files: f = wave.open(file, 'w') where file is either the name of a file or an open file pointer. The open file pointer must have methods write(), tell(), seek(), and close(). This returns an instance of a class with the following public methods: setnchannels(n) -- set the number of channels setsampwidth(n) -- set the sample width setframerate(n) -- set the frame rate setnframes(n) -- set the number of frames setcomptype(type, name) -- set the compression type and the human-readable compression type setparams(tuple) -- set all parameters at once tell() -- return current position in output file writeframesraw(data) -- write audio frames without patching up the file header writeframes(data) -- write audio frames and patch up the file header close() -- patch up the file header and close the output file You should set the parameters before the first writeframesraw or writeframes. The total number of frames does not need to be set, but when it is set to the correct value, the header does not have to be patched up. It is best to first set all parameters, perhaps possibly the compression type, and then write audio frames using writeframesraw. When all frames have been written, either call writeframes(b'') or close() to patch up the sizes in the header. The close() method is called automatically when the class instance is destroyed. ) namedtupleN)openError Wave_read Wave_writec\rSrSrSrg)rRN)__name__ __module__ __qualname____firstlineno____static_attributes__r */opt/imh/python3.13/lib/python3.13/wave.pyrrRsrris8q)NbhNi _wave_paramsz7nchannels sampwidth framerate nframes comptype compnamec[[U55n[S[U5U5H'n[U5HnXU-X#U-S- U- 'M M) [U5$)Nrr) bytearraylenrangebytes)datawidth swapped_datarjs r _byteswapr `s]SY'L 1c$i 'uA.2q5kLUQ* +(  rcJ\rSrSrS SjrSrSrS SjrSrS Sjr Sr S r g )_ChunkjcSUlX lU(aSnOSnXlURS5Ul[ UR5S:a[ e[R"US-URS55SUl U(aURS- Ul SUl URR5Ul SUlg![Ra [ Sef=f![[ 4a SUlgf=f) NF><LrT)closedalignfileread chunknamerEOFErrorstruct unpack_from chunksizeerror size_readtelloffsetseekableAttributeErrorOSError)selfr,r+ bigendian inclheaderstrflags r__init___Chunk.__init__ks  GG 1 t~~  "N %#// TYYq\J1MDN !^^a/DN !))..*DK!DM|| % $ %( "!DM "s1C*C0C-0D  D cUR$)z*Return the name (ID) of the current chunk.)r.r:s rgetname_Chunk.getnames ~~rcpUR(dUR5 SUlgg!SUlf=f)NT)r*skiprAs rclose _Chunk.closes.{{ # " # s, 5cZUR(a [S5eUR(d [S5eUS:XaXR-nOUS:XaXR -nUS:dXR :a[ eURRURU-S5 Xlg)zSeek to specified position into the chunk. Default position is 0 (start of chunk). If the file is not seekable, this will result in an error. I/O operation on closed filez cannot seekrrN) r* ValueErrorr7r9r4r2 RuntimeErrorr,seekr6)r:poswhences rrM _Chunk.seeks ;;;< <}}-( ( Q;&C q[&C 7cNN*  t{{S(!,rcRUR(a [S5eUR$)NrI)r*rKr4rAs rr5 _Chunk.tells ;;;< <~~rczUR(a [S5eURUR:agUS:aURUR- nXRUR- :aURUR- nURR U5nUR[ U5-UlURUR:Xa]UR(aLURS-(a8URR S5nUR[ U5-UlU$)ziRead at most size bytes from the chunk. If size is omitted or negative, read until the end of the chunk. rIrrr)r*rKr4r2r,r-rr+)r:sizerdummys rr- _Chunk.reads ;;;< < >>T^^ + !8>>DNN2D ..4>>1 1>>DNN2Dyy~~d##d)3 >>T^^ + :: NNQ IINN1%E!^^c%j8DN rcXUR(a [S5eUR(auURUR- nUR (aURS-(aUS-nUR RUS5 URU-UlgURUR:a^[SURUR- 5nURU5nU(d[eURUR:aM]gg![a Nf=f)zSkip the rest of the chunk. If you are not interested in the contents of the chunk, this method should be called so that the file points to the start of the next chunk. rIrNi ) r*rKr7r2r4r+r,rMr9minr-r/)r:nrUs rrE _Chunk.skips ;;;< < == NNT^^3::4>>A#5AA q!$!%!!3nnt~~-D$..4>>9:AIIaLE nnt~~-  sA3D D)(D))r+r.r2r*r,r6r7r4N)TTF)r)) r r r rr>rBrFrMr5r-rErr rrr"r"js%!2#& .rr"c\rSrSrSrSrSrSrSrSr Sr S r S r S r S rS rSrSrSrSrSrSrSrSrSrSrSrg)raVariables used in this class: These variables are available to the user though appropriate methods of this class: _file -- the open file with methods read(), close(), and seek() set through the __init__() method _nchannels -- the number of audio channels available through the getnchannels() method _nframes -- the number of audio frames available through the getnframes() method _sampwidth -- the number of bytes per audio sample available through the getsampwidth() method _framerate -- the sampling frequency available through the getframerate() method _comptype -- the AIFF-C compression type ('NONE' if AIFF) available through the getcomptype() method _compname -- the human-readable AIFF-C compression type available through the getcomptype() method _soundpos -- the position in the audio stream available through the tell() method, set through the setpos() method These variables are used internally only: _fmt_chunk_read -- 1 iff the FMT chunk has been read _data_seek_needed -- 1 iff positioned correctly in audio file for readframes() _data_chunk -- instantiation of a chunk class for the DATA chunk _framesize -- size of one frame in the file cSUlSUl[USS9UlURR 5S:wa [ S5eURR S5S:wa [ S5eSUlSUlSUl [URSS9nUR 5nUS :XaURU5 SUlONUS :XaHUR(d [ S 5eX lURUR-UlSUl OUR5 MUR(aUR(d [ S 5eg![a M;f=f) Nr)r;RIFFz file does not start with RIFF idr'WAVEznot a WAVE filerfmt datazdata chunk before fmt chunkz#fmt chunk and/or data chunk missing)_convert _soundposr"_filerBrr-_fmt_chunk_read _data_chunk_data_seek_neededr/_read_fmt_chunkr2 _framesize_nframesrE)r:r,chunkr.s rinitfpWave_read.initfpsC Da0 ::   7 *:; ; ::??1  ()* * %&D " tzzq9 IG#$$U+'($g%++ =>>#( %4?? B )*& JJL#$##4+;+;=> >,<  sE E'&E'cSUl[U[5(a[R"US5nXlUR U5 g! UR(aUR 5 e=f)Nrb_i_opened_the_file isinstancestrbuiltinsrrmrFr:fs rr>Wave_read.__init__sY"& a   a&A&' #  KKN &&  A $A1c$UR5 gNrFrAs r__del__Wave_read.__del__$  rcU$r{r rAs r __enter__Wave_read.__enter__' rc$UR5 gr{r|r:argss r__exit__Wave_read.__exit__*rrcUR$r{)rerAs rgetfpWave_read.getfp0s zzrc SUlSUlg)Nrr)rhrdrAs rrewindWave_read.rewind3s!"rchSUlURnU(aSUlUR5 ggr{)rerrrFr:r,s rrFWave_read.close7s- && &*D # JJL rcUR$r{)rdrAs rr5Wave_read.tell> ~~rcUR$r{) _nchannelsrAs r getnchannelsWave_read.getnchannelsA rcUR$r{)rkrAs r getnframesWave_read.getnframesDs }}rcUR$r{) _sampwidthrAs r getsampwidthWave_read.getsampwidthGrrcUR$r{) _frameraterAs r getframerateWave_read.getframerateJrrcUR$r{ _comptyperAs r getcomptypeWave_read.getcomptypeMrrcUR$r{ _compnamerAs r getcompnameWave_read.getcompnamePrrc [UR5UR5UR5UR 5UR 5UR 55$r{)rrrrrrrrAs r getparamsWave_read.getparamsSsQD--/1B1B1D((*DOO,='')4+;+;+=? ?rc,SSKnURSSS9 g)NrzWave_read.getmarkersremovewarnings _deprecatedr:rs r getmarkersWave_read.getmarkersXs3GDrc@SSKnURSSS9 [S5e)NrzWave_read.getmarkrrno marksrrrr:idrs rgetmarkWave_read.getmark]s$0AJrc^US:dXR:a [S5eXlSUlg)Nrzposition not in ranger)rkrrdrh)r:rNs rsetposWave_read.setposbs+ 7cMM)/0 0!"rctUR(a_URRSS5 URUR-nU(aURRUS5 SUlUS:XagURR XR-5nUR S:wa)[RS:Xa[X0R 5nUR(aU(aURU5nUR[U5URUR ---UlU$)Nrrrbig) rhrgrMrdrjr-rsys byteorderr rcrr)r:nframesrNrs r readframesWave_read.readframeshs  ! !    ! !!Q '..4??2C  %%c1-%&D " a<$$W%>? ??a CMMU$:T??3D ==T==&D#d)$//8Y*ZZ rc[R"SURS55uo lUlp4U[:waU[:wa[SU<35e[R"SURS55SnU[:Xa}[R"SURS55upgnURS 5n [U 5S :a[ eU [:wa"SSK n S U RU S 93n [U 5eUS -S-UlUR(d [S5eUR(d [S5eURUR-UlSUlSUlg![R a [ Sef=f![R a [ Sef=f![R a [ Sef=f![a S n Nf=f)NzB&"N'44>&? S\ @]?^$_MM**$q=Q.*+ ++, ,//DOO;)?|| % $ % || % $ %<< )D( ) !>$=M>s64E<)FAF:)G<FF7:G G('G()rrrcrgrhrerfrrjrrrrkrrdN)r r r r__doc__rmr>r}rrrrrFr5rrrrrrrrrrrrirr rrrrsp<?>  ?   # *"*rrc\rSrSrSrSrSrSrSrSr Sr S r S r S r S rS rSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSr Sr!g )!riakVariables used in this class: These variables are user settable through appropriate methods of this class: _file -- the open file with methods write(), close(), tell(), seek() set through the __init__() method _comptype -- the AIFF-C compression type ('NONE' in AIFF) set through the setcomptype() or setparams() method _compname -- the human-readable AIFF-C compression type set through the setcomptype() or setparams() method _nchannels -- the number of audio channels set through the setnchannels() or setparams() method _sampwidth -- the number of bytes per audio sample set through the setsampwidth() or setparams() method _framerate -- the sampling frequency set through the setframerate() or setparams() method _nframes -- the number of audio frames written to the header set through the setnframes() or setparams() method These variables are used internally only: _datalength -- the size of the audio samples written to the header _nframeswritten -- the number of frames actually written _datawritten -- the size of the audio samples actually written cSUl[U[5(a[R"US5nXlUR U5 g! UR(aUR 5 e=f)Nwbrqrvs rr>Wave_write.__init__sY"& a   a&A&' #  KKN && rycXlSUlSUlSUlSUlSUlSUlSUlSUlSUl g)NrF) rercrrrrk_nframeswritten _datawritten _datalength_headerwrittenrs rrmWave_write.initfpsJ    #rc$UR5 gr{r|rAs rr}Wave_write.__del__rrcU$r{r rAs rrWave_write.__enter__rrc$UR5 gr{r|rs rrWave_write.__exit__rrcjUR(a [S5eUS:a [S5eXlg)N0cannot change parameters after starting to writerr)rrr)r: nchannelss r setnchannelsWave_write.setnchannelss/   JK K q=+, ,#rcRUR(d [S5eUR$)Nznumber of channels not set)rrrAs rrWave_write.getnchannelss45 5rcvUR(a [S5eUS:dUS:a [S5eXlg)Nrrr'r)rrr)r:rs r setsampwidthWave_write.setsampwidths5   JK K q=IM*+ +#rcRUR(d [S5eUR$)Nzsample width not set)rrrAs rrWave_write.getsampwidths./ /rcUR(a [S5eUS::a [S5e[[U55Ulg)Nrrzbad frame rate)rrintroundr)r: framerates r setframerateWave_write.setframerates;   JK K >() )eI./rcRUR(d [S5eUR$)Nzframe rate not set)rrrAs rrWave_write.getframerates,- -rcHUR(a [S5eXlgNr)rrrk)r:rs r setnframesWave_write.setnframess   JK K rcUR$r{rrAs rrWave_write.getnframes ###rcvUR(a [S5eUS;a [S5eXlX lg)Nr)rzunsupported compression type)rrrr)r:comptypecompnames r setcomptypeWave_write.setcomptype s5   JK K 9 $67 7!!rcUR$r{rrAs rrWave_write.getcomptyperrcUR$r{rrAs rrWave_write.getcompnamerrcUup#pEpgUR(a [S5eURU5 URU5 UR U5 UR U5 UR Xg5 gr )rrrrrrr)r:paramsrrrrrrs r setparamsWave_write.setparamssgGMD i(   JK K )$ )$ )$   ,rcUR(a"UR(aUR(d [S5e[ URURURUR UR UR5$)Nznot all parameters set)rrrrrrkrrrAs rrWave_write.getparams$sSdooT__01 1DOOT__doommT^^T^^= =rc@SSKnURSSS9 [S5e)NrzWave_write.setmarkrrzsetmark() not supportedr)r:rrNnamers rsetmarkWave_write.setmark*s%1'B-..rc@SSKnURSSS9 [S5e)NrzWave_write.getmarkrrrrrs rrWave_write.getmark/s$1'BJrc,SSKnURSSS9 g)NrzWave_write.getmarkersrrrrs rrWave_write.getmarkers4s4WErcUR$r{rrAs rr5Wave_write.tell9rrc<[U[[45(d[U5R S5nUR [ U55 [ U5URUR--nUR(aURU5nURS:wa)[RS:Xa[XR5nURRU5 U=R[ U5- slUR U-Ulg)NBrr)rsrr memoryviewcast_ensure_header_writtenrrrrcrrr rewriterr)r:rrs rwriteframesrawWave_write.writeframesraw<s$ 233d#((-D ##CI.d)$// AB ====&D ??a CMMU$:T??3D  SY&#33g=rc|URU5 URUR:waUR5 ggr{)r3rr _patchheader)r:rs r writeframesWave_write.writeframesIs5 D!   t00 0     1rcUR(aUURS5 URUR:waUR 5 URR 5 SUlUR nU(aSUlUR5 gg!SUlUR nU(aSUlUR5 ff=f)Nr)rer1rrr6flushrrrFrs rrFWave_write.closeNs zz++A.##t'8'88%%'   "DJ**D*.' DJ**D*.' s A&B4CcUR(dfUR(d [S5eUR(d [S5eUR(d [S5eUR U5 gg)Nz# channels not specifiedzsample width not specifiedzsampling rate not specified)rrrrr _write_header)r:datasizes rr1!Wave_write._ensure_header_written`sW""??677??899??9::   x (#rcUR(aeURRS5 UR(d XRUR --UlURUR-UR -UlURR5UlURR[R"SSUR -SSS[URURURUR-UR -URUR -UR S-S5 5 URbURR5UlURR[R"S UR 55 S Ulg![[4a SUlGN/f=f) Nr_z ",,r)rrrcrErrrerCrrrrrrkrrN)"r r r rrr>rmr}rrrrrrrrrrrrrrrr%rrr5r3r7rFr1r=r6rr rrrrs2  $ $ $ 0  $"-= /   $ > $)#* -rrcUc [US5(a URnOSnUS;a [U5$US;a [U5$[ S5e)Nmoderp)rrp)wrz$mode must be 'r', 'rb', 'w', or 'wb')hasattrrLrrr)rwrLs rrrsR | 1f  66DD {|  !}:;;rr{)r collectionsrrur0r__all__rrrrr _array_fmtsrr r"rrrr rrrSsGR#  7 I X' .NP ll^F*F*Rg-g-T