18
18
* Adafruit CircuitPython firmware for the supported boards:
19
19
https://circuitpython.org/downloads
20
20
21
- Usage.
22
-
23
- Reading WAVE files:
24
- f = wave.open(file, 'r')
25
- where file is either the name of a file or an open file pointer.
26
- The open file pointer must have methods read(), seek(), and close().
27
- When the setpos() and rewind() methods are not used, the seek()
28
- method is not necessary.
29
-
30
- This returns an instance of a class with the following public methods:
31
- getnchannels() -- returns number of audio channels (1 for
32
- mono, 2 for stereo)
33
- getsampwidth() -- returns sample width in bytes
34
- getframerate() -- returns sampling frequency
35
- getnframes() -- returns number of audio frames
36
- getcomptype() -- returns compression type ('NONE' for linear samples)
37
- getcompname() -- returns human-readable version of
38
- compression type ('not compressed' linear samples)
39
- getparams() -- returns a namedtuple consisting of all of the
40
- above in the above order
41
- getmarkers() -- returns None (for compatibility with the
42
- aifc module)
43
- getmark(id) -- raises an error since the mark does not
44
- exist (for compatibility with the aifc module)
45
- readframes(n) -- returns at most n frames of audio
46
- rewind() -- rewind to the beginning of the audio stream
47
- setpos(pos) -- seek to the specified position
48
- tell() -- return the current position
49
- close() -- close the instance (make it unusable)
50
- The position returned by tell() and the position given to setpos()
51
- are compatible and have nothing to do with the actual position in the
52
- file.
53
- The close() method is called automatically when the class instance
54
- is destroyed.
55
-
56
- Writing WAVE files:
57
- f = wave.open(file, 'w')
58
- where file is either the name of a file or an open file pointer.
59
- The open file pointer must have methods write(), tell(), seek(), and
60
- close().
61
-
62
- This returns an instance of a class with the following public methods:
63
- setnchannels(n) -- set the number of channels
64
- setsampwidth(n) -- set the sample width
65
- setframerate(n) -- set the frame rate
66
- setnframes(n) -- set the number of frames
67
- setcomptype(type, name)
68
- -- set the compression type and the
69
- human-readable compression type
70
- setparams(tuple)
71
- -- set all parameters at once
72
- tell() -- return current position in output file
73
- writeframesraw(data)
74
- -- write audio frames without patching up the
75
- file header
76
- writeframes(data)
77
- -- write audio frames and patch up the file header
78
- close() -- patch up the file header and close the
79
- output file
80
- You should set the parameters before the first writeframesraw or
81
- writeframes. The total number of frames does not need to be set,
82
- but when it is set to the correct value, the header does not have to
83
- be patched up.
84
- It is best to first set all parameters, perhaps possibly the
85
- compression type, and then write audio frames using writeframesraw.
86
- When all frames have been written, either call writeframes(b'') or
87
- close() to patch up the sizes in the header.
88
- The close() method is called automatically when the class instance
89
- is destroyed.
90
-
91
21
"""
92
22
93
23
# pylint: disable=missing-class-docstring,redefined-outer-name,missing-function-docstring,invalid-name,import-outside-toplevel,too-many-instance-attributes,consider-using-with,no-self-use,redefined-builtin,not-callable,unused-variable,attribute-defined-outside-init,too-many-public-methods,no-else-return
@@ -176,6 +106,7 @@ def tell(self):
176
106
177
107
def read (self , size = - 1 ):
178
108
"""Read at most size bytes from the chunk.
109
+
179
110
If size is omitted or negative, read until the end
180
111
of the chunk.
181
112
"""
@@ -197,6 +128,7 @@ def read(self, size=-1):
197
128
198
129
def skip (self ):
199
130
"""Skip the rest of the chunk.
131
+
200
132
If you are not interested in the contents of the chunk,
201
133
this method should be called so that the file points to
202
134
the start of the next chunk.
@@ -236,36 +168,6 @@ class Error(Exception):
236
168
237
169
238
170
class Wave_read :
239
- """Variables used in this class:
240
-
241
- These variables are available to the user though appropriate
242
- methods of this class:
243
- _file -- the open file with methods read(), close(), and seek()
244
- set through the __init__() method
245
- _nchannels -- the number of audio channels
246
- available through the getnchannels() method
247
- _nframes -- the number of audio frames
248
- available through the getnframes() method
249
- _sampwidth -- the number of bytes per audio sample
250
- available through the getsampwidth() method
251
- _framerate -- the sampling frequency
252
- available through the getframerate() method
253
- _comptype -- the AIFF-C compression type ('NONE' if AIFF)
254
- available through the getcomptype() method
255
- _compname -- the human-readable AIFF-C compression type
256
- available through the getcomptype() method
257
- _soundpos -- the position in the audio stream
258
- available through the tell() method, set through the
259
- setpos() method
260
-
261
- These variables are used internally only:
262
- _fmt_chunk_read -- 1 iff the FMT chunk has been read
263
- _data_seek_needed -- 1 iff positioned correctly in audio
264
- file for readframes()
265
- _data_chunk -- instantiation of a chunk class for the DATA chunk
266
- _framesize -- size of one frame in the file
267
- """
268
-
269
171
def initfp (self , file ):
270
172
self ._convert = None
271
173
self ._soundpos = 0
@@ -429,31 +331,6 @@ def _read_fmt_chunk(self, chunk):
429
331
430
332
431
333
class Wave_write :
432
- """Variables used in this class:
433
-
434
- These variables are user settable through appropriate methods
435
- of this class:
436
- _file -- the open file with methods write(), close(), tell(), seek()
437
- set through the __init__() method
438
- _comptype -- the AIFF-C compression type ('NONE' in AIFF)
439
- set through the setcomptype() or setparams() method
440
- _compname -- the human-readable AIFF-C compression type
441
- set through the setcomptype() or setparams() method
442
- _nchannels -- the number of audio channels
443
- set through the setnchannels() or setparams() method
444
- _sampwidth -- the number of bytes per audio sample
445
- set through the setsampwidth() or setparams() method
446
- _framerate -- the sampling frequency
447
- set through the setframerate() or setparams() method
448
- _nframes -- the number of audio frames written to the header
449
- set through the setnframes() or setparams() method
450
-
451
- These variables are used internally only:
452
- _datalength -- the size of the audio samples written to the header
453
- _nframeswritten -- the number of frames actually written
454
- _datawritten -- the size of the audio samples actually written
455
- """
456
-
457
334
def __init__ (self , f ):
458
335
self ._i_opened_the_file = None
459
336
if isinstance (f , str ):
0 commit comments