Current Path: > > lib64 > > > python3.8
Operation : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64 Software : Apache Server IP : 162.0.232.56 | Your IP: 216.73.216.111 Domains : 1034 Domain(s) Permission : [ 0755 ]
Name | Type | Size | Last Modified | Actions |
---|---|---|---|---|
__pycache__ | Directory | - | - | |
asyncio | Directory | - | - | |
collections | Directory | - | - | |
concurrent | Directory | - | - | |
config-3.8-x86_64-linux-gnu | Directory | - | - | |
ctypes | Directory | - | - | |
curses | Directory | - | - | |
dbm | Directory | - | - | |
distutils | Directory | - | - | |
Directory | - | - | ||
encodings | Directory | - | - | |
ensurepip | Directory | - | - | |
html | Directory | - | - | |
http | Directory | - | - | |
importlib | Directory | - | - | |
json | Directory | - | - | |
lib-dynload | Directory | - | - | |
lib2to3 | Directory | - | - | |
logging | Directory | - | - | |
multiprocessing | Directory | - | - | |
pydoc_data | Directory | - | - | |
site-packages | Directory | - | - | |
sqlite3 | Directory | - | - | |
tkinter | Directory | - | - | |
turtledemo | Directory | - | - | |
unittest | Directory | - | - | |
urllib | Directory | - | - | |
venv | Directory | - | - | |
wsgiref | Directory | - | - | |
xml | Directory | - | - | |
xmlrpc | Directory | - | - | |
LICENSE.txt | File | 13937 bytes | June 06 2023 13:32:21. | |
__future__.py | File | 5147 bytes | June 06 2023 13:32:21. | |
__phello__.foo.py | File | 64 bytes | June 06 2023 13:32:21. | |
_bootlocale.py | File | 1801 bytes | June 06 2023 13:32:21. | |
_collections_abc.py | File | 26100 bytes | June 06 2023 13:32:21. | |
_compat_pickle.py | File | 8749 bytes | June 06 2023 13:32:21. | |
_compression.py | File | 5340 bytes | June 06 2023 13:32:21. | |
_dummy_thread.py | File | 6027 bytes | June 06 2023 13:32:21. | |
_markupbase.py | File | 14598 bytes | June 06 2023 13:32:21. | |
_osx_support.py | File | 21774 bytes | June 06 2023 13:32:21. | |
_py_abc.py | File | 6189 bytes | June 06 2023 13:32:21. | |
_pydecimal.py | File | 228666 bytes | June 06 2023 13:32:21. | |
_pyio.py | File | 93177 bytes | June 06 2023 13:32:21. | |
_sitebuiltins.py | File | 3115 bytes | June 06 2023 13:32:21. | |
_strptime.py | File | 25268 bytes | June 06 2023 13:32:21. | |
_sysconfigdata__linux_x86_64-linux-gnu.py | File | 38510 bytes | October 17 2023 18:12:19. | |
_sysconfigdata_d_linux_x86_64-linux-gnu.py | File | 38237 bytes | October 17 2023 18:03:44. | |
_threading_local.py | File | 7220 bytes | June 06 2023 13:32:21. | |
_weakrefset.py | File | 5735 bytes | June 06 2023 13:32:21. | |
abc.py | File | 4489 bytes | June 06 2023 13:32:21. | |
aifc.py | File | 32814 bytes | June 06 2023 13:32:21. | |
antigravity.py | File | 477 bytes | June 06 2023 13:32:21. | |
argparse.py | File | 96015 bytes | June 06 2023 13:32:21. | |
ast.py | File | 19234 bytes | June 06 2023 13:32:21. | |
asynchat.py | File | 11328 bytes | June 06 2023 13:32:21. | |
asyncore.py | File | 20094 bytes | June 06 2023 13:32:21. | |
base64.py | File | 20382 bytes | June 06 2023 13:32:21. | |
bdb.py | File | 32056 bytes | June 06 2023 13:32:21. | |
binhex.py | File | 13954 bytes | June 06 2023 13:32:21. | |
bisect.py | File | 2214 bytes | June 06 2023 13:32:21. | |
bz2.py | File | 12558 bytes | June 06 2023 13:32:21. | |
cProfile.py | File | 7010 bytes | June 06 2023 13:32:21. | |
calendar.py | File | 24832 bytes | June 06 2023 13:32:21. | |
cgi.py | File | 33934 bytes | October 17 2023 18:02:14. | |
cgitb.py | File | 12096 bytes | June 06 2023 13:32:21. | |
chunk.py | File | 5435 bytes | June 06 2023 13:32:21. | |
cmd.py | File | 14860 bytes | June 06 2023 13:32:21. | |
code.py | File | 10622 bytes | June 06 2023 13:32:21. | |
codecs.py | File | 36667 bytes | June 06 2023 13:32:21. | |
codeop.py | File | 6330 bytes | June 06 2023 13:32:21. | |
colorsys.py | File | 4064 bytes | June 06 2023 13:32:21. | |
compileall.py | File | 13678 bytes | June 06 2023 13:32:21. | |
configparser.py | File | 54374 bytes | June 06 2023 13:32:21. | |
contextlib.py | File | 24995 bytes | June 06 2023 13:32:21. | |
contextvars.py | File | 129 bytes | June 06 2023 13:32:21. | |
copy.py | File | 8661 bytes | June 06 2023 13:32:21. | |
copyreg.py | File | 7135 bytes | June 06 2023 13:32:21. | |
crypt.py | File | 3610 bytes | June 06 2023 13:32:21. | |
csv.py | File | 16144 bytes | June 06 2023 13:32:21. | |
dataclasses.py | File | 49973 bytes | June 06 2023 13:32:21. | |
datetime.py | File | 88287 bytes | June 06 2023 13:32:21. | |
decimal.py | File | 320 bytes | June 06 2023 13:32:21. | |
difflib.py | File | 84058 bytes | June 06 2023 13:32:21. | |
dis.py | File | 20570 bytes | June 06 2023 13:32:21. | |
doctest.py | File | 104543 bytes | June 06 2023 13:32:21. | |
dummy_threading.py | File | 2815 bytes | June 06 2023 13:32:21. | |
enum.py | File | 38136 bytes | June 06 2023 13:32:21. | |
filecmp.py | File | 9830 bytes | June 06 2023 13:32:21. | |
fileinput.py | File | 14709 bytes | June 06 2023 13:32:21. | |
fnmatch.py | File | 4079 bytes | June 06 2023 13:32:21. | |
formatter.py | File | 15143 bytes | June 06 2023 13:32:21. | |
fractions.py | File | 24329 bytes | June 06 2023 13:32:21. | |
ftplib.py | File | 35129 bytes | June 06 2023 13:32:21. | |
functools.py | File | 37406 bytes | June 06 2023 13:32:21. | |
genericpath.py | File | 4975 bytes | June 06 2023 13:32:21. | |
getopt.py | File | 7489 bytes | June 06 2023 13:32:21. | |
getpass.py | File | 5994 bytes | June 06 2023 13:32:21. | |
gettext.py | File | 27138 bytes | June 06 2023 13:32:21. | |
glob.py | File | 5697 bytes | June 06 2023 13:32:21. | |
gzip.py | File | 21413 bytes | June 06 2023 13:32:21. | |
hashlib.py | File | 8333 bytes | October 17 2023 18:02:14. | |
heapq.py | File | 22877 bytes | June 06 2023 13:32:21. | |
hmac.py | File | 7850 bytes | October 17 2023 18:02:14. | |
imaplib.py | File | 53606 bytes | June 06 2023 13:32:21. | |
imghdr.py | File | 3808 bytes | June 06 2023 13:32:21. | |
imp.py | File | 10536 bytes | June 06 2023 13:32:21. | |
inspect.py | File | 118550 bytes | June 06 2023 13:32:21. | |
io.py | File | 3541 bytes | June 06 2023 13:32:21. | |
ipaddress.py | File | 71644 bytes | June 06 2023 13:32:21. | |
keyword.py | File | 945 bytes | June 06 2023 13:32:21. | |
linecache.py | File | 5330 bytes | June 06 2023 13:32:21. | |
locale.py | File | 78191 bytes | June 06 2023 13:32:21. | |
lzma.py | File | 12983 bytes | June 06 2023 13:32:21. | |
mailbox.py | File | 78661 bytes | June 06 2023 13:32:21. | |
mailcap.py | File | 9067 bytes | June 06 2023 13:32:21. | |
mimetypes.py | File | 21664 bytes | June 06 2023 13:32:21. | |
modulefinder.py | File | 24430 bytes | June 06 2023 13:32:21. | |
netrc.py | File | 5566 bytes | June 06 2023 13:32:21. | |
nntplib.py | File | 43261 bytes | June 06 2023 13:32:21. | |
ntpath.py | File | 27734 bytes | June 06 2023 13:32:21. | |
nturl2path.py | File | 2887 bytes | June 06 2023 13:32:21. | |
numbers.py | File | 10244 bytes | June 06 2023 13:32:21. | |
opcode.py | File | 5808 bytes | June 06 2023 13:32:21. | |
operator.py | File | 10711 bytes | June 06 2023 13:32:21. | |
optparse.py | File | 60369 bytes | June 06 2023 13:32:21. | |
os.py | File | 38995 bytes | June 06 2023 13:32:21. | |
pathlib.py | File | 52610 bytes | June 06 2023 13:32:21. | |
pdb.py | File | 62738 bytes | June 06 2023 13:32:21. | |
pickle.py | File | 64467 bytes | June 06 2023 13:32:21. | |
pickletools.py | File | 93486 bytes | June 06 2023 13:32:21. | |
pipes.py | File | 8916 bytes | June 06 2023 13:32:21. | |
pkgutil.py | File | 21500 bytes | June 06 2023 13:32:21. | |
platform.py | File | 40425 bytes | June 06 2023 13:32:21. | |
plistlib.py | File | 32220 bytes | June 06 2023 13:32:21. | |
poplib.py | File | 15077 bytes | June 06 2023 13:32:21. | |
posixpath.py | File | 15627 bytes | June 06 2023 13:32:21. | |
pprint.py | File | 21484 bytes | June 06 2023 13:32:21. | |
profile.py | File | 23546 bytes | June 06 2023 13:32:21. | |
pstats.py | File | 27345 bytes | June 06 2023 13:32:21. | |
pty.py | File | 4807 bytes | June 06 2023 13:32:21. | |
py_compile.py | File | 8203 bytes | October 17 2023 18:02:14. | |
pyclbr.py | File | 15255 bytes | June 06 2023 13:32:21. | |
pydoc.py | File | 106700 bytes | October 17 2023 18:12:57. | |
queue.py | File | 11356 bytes | June 06 2023 13:32:21. | |
quopri.py | File | 7252 bytes | June 06 2023 13:32:21. | |
random.py | File | 28802 bytes | June 06 2023 13:32:21. | |
re.py | File | 15861 bytes | June 06 2023 13:32:21. | |
reprlib.py | File | 5267 bytes | June 06 2023 13:32:21. | |
rlcompleter.py | File | 7097 bytes | June 06 2023 13:32:21. | |
runpy.py | File | 12052 bytes | June 06 2023 13:32:21. | |
sched.py | File | 6442 bytes | June 06 2023 13:32:21. | |
secrets.py | File | 2038 bytes | June 06 2023 13:32:21. | |
selectors.py | File | 18561 bytes | June 06 2023 13:32:21. | |
shelve.py | File | 8527 bytes | June 06 2023 13:32:21. | |
shlex.py | File | 13325 bytes | June 06 2023 13:32:21. | |
shutil.py | File | 51761 bytes | June 06 2023 13:32:21. | |
signal.py | File | 2273 bytes | June 06 2023 13:32:21. | |
site.py | File | 21838 bytes | October 17 2023 18:02:14. | |
smtpd.py | File | 34709 bytes | June 06 2023 13:32:21. | |
smtplib.py | File | 45001 bytes | June 06 2023 13:32:21. | |
sndhdr.py | File | 7099 bytes | June 06 2023 13:32:21. | |
socket.py | File | 35243 bytes | June 06 2023 13:32:21. | |
socketserver.py | File | 27296 bytes | June 06 2023 13:32:21. | |
sre_compile.py | File | 26695 bytes | June 06 2023 13:32:21. | |
sre_constants.py | File | 7154 bytes | June 06 2023 13:32:21. | |
sre_parse.py | File | 40230 bytes | June 06 2023 13:32:21. | |
ssl.py | File | 50760 bytes | June 06 2023 13:32:21. | |
stat.py | File | 5485 bytes | June 06 2023 13:32:21. | |
statistics.py | File | 39690 bytes | June 06 2023 13:32:21. | |
string.py | File | 10535 bytes | June 06 2023 13:32:21. | |
stringprep.py | File | 12917 bytes | June 06 2023 13:32:21. | |
struct.py | File | 257 bytes | June 06 2023 13:32:21. | |
subprocess.py | File | 78250 bytes | June 06 2023 13:32:21. | |
sunau.py | File | 18375 bytes | June 06 2023 13:32:21. | |
symbol.py | File | 2109 bytes | October 17 2023 18:04:15. | |
symtable.py | File | 8021 bytes | June 06 2023 13:32:21. | |
sysconfig.py | File | 24896 bytes | October 17 2023 18:12:55. | |
tabnanny.py | File | 11406 bytes | June 06 2023 13:32:21. | |
tarfile.py | File | 106473 bytes | October 17 2023 18:02:14. | |
telnetlib.py | File | 23254 bytes | June 06 2023 13:32:21. | |
tempfile.py | File | 27537 bytes | June 06 2023 13:32:21. | |
textwrap.py | File | 19407 bytes | June 06 2023 13:32:21. | |
this.py | File | 1003 bytes | June 06 2023 13:32:21. | |
threading.py | File | 50820 bytes | June 06 2023 13:32:21. | |
timeit.py | File | 13480 bytes | June 06 2023 13:32:21. | |
token.py | File | 2368 bytes | June 06 2023 13:32:21. | |
tokenize.py | File | 25841 bytes | June 06 2023 13:32:21. | |
trace.py | File | 29870 bytes | June 06 2023 13:32:21. | |
traceback.py | File | 23611 bytes | June 06 2023 13:32:21. | |
tracemalloc.py | File | 17076 bytes | June 06 2023 13:32:21. | |
tty.py | File | 879 bytes | June 06 2023 13:32:21. | |
turtle.py | File | 143716 bytes | June 06 2023 13:32:21. | |
types.py | File | 9713 bytes | June 06 2023 13:32:21. | |
typing.py | File | 68962 bytes | June 06 2023 13:32:21. | |
uu.py | File | 7277 bytes | October 17 2023 18:12:57. | |
uuid.py | File | 30515 bytes | October 17 2023 18:02:14. | |
warnings.py | File | 19688 bytes | June 06 2023 13:32:21. | |
wave.py | File | 18230 bytes | June 06 2023 13:32:21. | |
weakref.py | File | 21387 bytes | June 06 2023 13:32:21. | |
webbrowser.py | File | 24083 bytes | June 06 2023 13:32:21. | |
xdrlib.py | File | 5913 bytes | June 06 2023 13:32:21. | |
zipapp.py | File | 7535 bytes | June 06 2023 13:32:21. | |
zipfile.py | File | 87728 bytes | June 06 2023 13:32:21. | |
zipimport.py | File | 30765 bytes | June 06 2023 13:32:21. |
"""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 aifc module) getmark(id) -- raises an error since the mark does not exist (for compatibility with the 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. """ import builtins __all__ = ["open", "openfp", "Error", "Wave_read", "Wave_write"] class Error(Exception): pass WAVE_FORMAT_PCM = 0x0001 _array_fmts = None, 'b', 'h', None, 'i' import audioop import struct import sys from chunk import Chunk from collections import namedtuple import warnings _wave_params = namedtuple('_wave_params', 'nchannels sampwidth framerate nframes comptype compname') class Wave_read: """Variables 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 """ def initfp(self, file): self._convert = None self._soundpos = 0 self._file = Chunk(file, bigendian = 0) if self._file.getname() != b'RIFF': raise Error('file does not start with RIFF id') if self._file.read(4) != b'WAVE': raise Error('not a WAVE file') self._fmt_chunk_read = 0 self._data_chunk = None while 1: self._data_seek_needed = 1 try: chunk = Chunk(self._file, bigendian = 0) except EOFError: break chunkname = chunk.getname() if chunkname == b'fmt ': self._read_fmt_chunk(chunk) self._fmt_chunk_read = 1 elif chunkname == b'data': if not self._fmt_chunk_read: raise Error('data chunk before fmt chunk') self._data_chunk = chunk self._nframes = chunk.chunksize // self._framesize self._data_seek_needed = 0 break chunk.skip() if not self._fmt_chunk_read or not self._data_chunk: raise Error('fmt chunk and/or data chunk missing') def __init__(self, f): self._i_opened_the_file = None if isinstance(f, str): f = builtins.open(f, 'rb') self._i_opened_the_file = f # else, assume it is an open file object already try: self.initfp(f) except: if self._i_opened_the_file: f.close() raise def __del__(self): self.close() def __enter__(self): return self def __exit__(self, *args): self.close() # # User visible methods. # def getfp(self): return self._file def rewind(self): self._data_seek_needed = 1 self._soundpos = 0 def close(self): self._file = None file = self._i_opened_the_file if file: self._i_opened_the_file = None file.close() def tell(self): return self._soundpos def getnchannels(self): return self._nchannels def getnframes(self): return self._nframes def getsampwidth(self): return self._sampwidth def getframerate(self): return self._framerate def getcomptype(self): return self._comptype def getcompname(self): return self._compname def getparams(self): return _wave_params(self.getnchannels(), self.getsampwidth(), self.getframerate(), self.getnframes(), self.getcomptype(), self.getcompname()) def getmarkers(self): return None def getmark(self, id): raise Error('no marks') def setpos(self, pos): if pos < 0 or pos > self._nframes: raise Error('position not in range') self._soundpos = pos self._data_seek_needed = 1 def readframes(self, nframes): if self._data_seek_needed: self._data_chunk.seek(0, 0) pos = self._soundpos * self._framesize if pos: self._data_chunk.seek(pos, 0) self._data_seek_needed = 0 if nframes == 0: return b'' data = self._data_chunk.read(nframes * self._framesize) if self._sampwidth != 1 and sys.byteorder == 'big': data = audioop.byteswap(data, self._sampwidth) if self._convert and data: data = self._convert(data) self._soundpos = self._soundpos + len(data) // (self._nchannels * self._sampwidth) return data # # Internal methods. # def _read_fmt_chunk(self, chunk): try: wFormatTag, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack_from('<HHLLH', chunk.read(14)) except struct.error: raise EOFError from None if wFormatTag == WAVE_FORMAT_PCM: try: sampwidth = struct.unpack_from('<H', chunk.read(2))[0] except struct.error: raise EOFError from None self._sampwidth = (sampwidth + 7) // 8 if not self._sampwidth: raise Error('bad sample width') else: raise Error('unknown format: %r' % (wFormatTag,)) if not self._nchannels: raise Error('bad # of channels') self._framesize = self._nchannels * self._sampwidth self._comptype = 'NONE' self._compname = 'not compressed' class Wave_write: """Variables 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 """ def __init__(self, f): self._i_opened_the_file = None if isinstance(f, str): f = builtins.open(f, 'wb') self._i_opened_the_file = f try: self.initfp(f) except: if self._i_opened_the_file: f.close() raise def initfp(self, file): self._file = file self._convert = None self._nchannels = 0 self._sampwidth = 0 self._framerate = 0 self._nframes = 0 self._nframeswritten = 0 self._datawritten = 0 self._datalength = 0 self._headerwritten = False def __del__(self): self.close() def __enter__(self): return self def __exit__(self, *args): self.close() # # User visible methods. # def setnchannels(self, nchannels): if self._datawritten: raise Error('cannot change parameters after starting to write') if nchannels < 1: raise Error('bad # of channels') self._nchannels = nchannels def getnchannels(self): if not self._nchannels: raise Error('number of channels not set') return self._nchannels def setsampwidth(self, sampwidth): if self._datawritten: raise Error('cannot change parameters after starting to write') if sampwidth < 1 or sampwidth > 4: raise Error('bad sample width') self._sampwidth = sampwidth def getsampwidth(self): if not self._sampwidth: raise Error('sample width not set') return self._sampwidth def setframerate(self, framerate): if self._datawritten: raise Error('cannot change parameters after starting to write') if framerate <= 0: raise Error('bad frame rate') self._framerate = int(round(framerate)) def getframerate(self): if not self._framerate: raise Error('frame rate not set') return self._framerate def setnframes(self, nframes): if self._datawritten: raise Error('cannot change parameters after starting to write') self._nframes = nframes def getnframes(self): return self._nframeswritten def setcomptype(self, comptype, compname): if self._datawritten: raise Error('cannot change parameters after starting to write') if comptype not in ('NONE',): raise Error('unsupported compression type') self._comptype = comptype self._compname = compname def getcomptype(self): return self._comptype def getcompname(self): return self._compname def setparams(self, params): nchannels, sampwidth, framerate, nframes, comptype, compname = params if self._datawritten: raise Error('cannot change parameters after starting to write') self.setnchannels(nchannels) self.setsampwidth(sampwidth) self.setframerate(framerate) self.setnframes(nframes) self.setcomptype(comptype, compname) def getparams(self): if not self._nchannels or not self._sampwidth or not self._framerate: raise Error('not all parameters set') return _wave_params(self._nchannels, self._sampwidth, self._framerate, self._nframes, self._comptype, self._compname) def setmark(self, id, pos, name): raise Error('setmark() not supported') def getmark(self, id): raise Error('no marks') def getmarkers(self): return None def tell(self): return self._nframeswritten def writeframesraw(self, data): if not isinstance(data, (bytes, bytearray)): data = memoryview(data).cast('B') self._ensure_header_written(len(data)) nframes = len(data) // (self._sampwidth * self._nchannels) if self._convert: data = self._convert(data) if self._sampwidth != 1 and sys.byteorder == 'big': data = audioop.byteswap(data, self._sampwidth) self._file.write(data) self._datawritten += len(data) self._nframeswritten = self._nframeswritten + nframes def writeframes(self, data): self.writeframesraw(data) if self._datalength != self._datawritten: self._patchheader() def close(self): try: if self._file: self._ensure_header_written(0) if self._datalength != self._datawritten: self._patchheader() self._file.flush() finally: self._file = None file = self._i_opened_the_file if file: self._i_opened_the_file = None file.close() # # Internal methods. # def _ensure_header_written(self, datasize): if not self._headerwritten: if not self._nchannels: raise Error('# channels not specified') if not self._sampwidth: raise Error('sample width not specified') if not self._framerate: raise Error('sampling rate not specified') self._write_header(datasize) def _write_header(self, initlength): assert not self._headerwritten self._file.write(b'RIFF') if not self._nframes: self._nframes = initlength // (self._nchannels * self._sampwidth) self._datalength = self._nframes * self._nchannels * self._sampwidth try: self._form_length_pos = self._file.tell() except (AttributeError, OSError): self._form_length_pos = None self._file.write(struct.pack('<L4s4sLHHLLHH4s', 36 + self._datalength, b'WAVE', b'fmt ', 16, WAVE_FORMAT_PCM, self._nchannels, self._framerate, self._nchannels * self._framerate * self._sampwidth, self._nchannels * self._sampwidth, self._sampwidth * 8, b'data')) if self._form_length_pos is not None: self._data_length_pos = self._file.tell() self._file.write(struct.pack('<L', self._datalength)) self._headerwritten = True def _patchheader(self): assert self._headerwritten if self._datawritten == self._datalength: return curpos = self._file.tell() self._file.seek(self._form_length_pos, 0) self._file.write(struct.pack('<L', 36 + self._datawritten)) self._file.seek(self._data_length_pos, 0) self._file.write(struct.pack('<L', self._datawritten)) self._file.seek(curpos, 0) self._datalength = self._datawritten def open(f, mode=None): if mode is None: if hasattr(f, 'mode'): mode = f.mode else: mode = 'rb' if mode in ('r', 'rb'): return Wave_read(f) elif mode in ('w', 'wb'): return Wave_write(f) else: raise Error("mode must be 'r', 'rb', 'w', or 'wb'") def openfp(f, mode=None): warnings.warn("wave.openfp is deprecated since Python 3.7. " "Use wave.open instead.", DeprecationWarning, stacklevel=2) return open(f, mode=mode)
SILENT KILLER Tool