diff -r 37c06d20dda5 Lib/aifc.py --- a/Lib/aifc.py Mon Oct 14 10:44:25 2013 +0300 +++ b/Lib/aifc.py Mon Oct 14 14:36:53 2013 +0300 @@ -692,9 +692,14 @@ 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: + if not (isinstance(data, bytes) or + isinstance(data, memoryview) and data.readonly): + data = bytes(data) data = self._convert(data) self._file.write(data) self._nframeswritten = self._nframeswritten + nframes diff -r 37c06d20dda5 Lib/sunau.py --- a/Lib/sunau.py Mon Oct 14 10:44:25 2013 +0300 +++ b/Lib/sunau.py Mon Oct 14 14:36:53 2013 +0300 @@ -415,9 +415,14 @@ return self._nframeswritten def writeframesraw(self, data): + if not isinstance(data, (bytes, bytearray)): + data = memoryview(data).cast('B') self._ensure_header_written() if self._comptype == 'ULAW': import audioop + if not (isinstance(data, bytes) or + isinstance(data, memoryview) and data.readonly): + data = bytes(data) data = audioop.lin2ulaw(data, self._sampwidth) nframes = len(data) // self._framesize self._file.write(data) diff -r 37c06d20dda5 Lib/test/audiotests.py --- a/Lib/test/audiotests.py Mon Oct 14 10:44:25 2013 +0300 +++ b/Lib/test/audiotests.py Mon Oct 14 14:36:53 2013 +0300 @@ -139,6 +139,22 @@ self.check_file(TESTFN, self.nframes, self.frames) + def test_write_bytearray(self): + f = self.create_file(TESTFN) + f.setnframes(self.nframes) + f.writeframes(bytearray(self.frames)) + f.close() + + self.check_file(TESTFN, self.nframes, self.frames) + + def test_write_array(self): + f = self.create_file(TESTFN) + f.setnframes(self.nframes) + f.writeframes(array.array('h', self.frames)) + f.close() + + self.check_file(TESTFN, self.nframes, self.frames) + def test_incompleted_write(self): with open(TESTFN, 'wb') as testfile: testfile.write(b'ababagalamaga') diff -r 37c06d20dda5 Lib/wave.py --- a/Lib/wave.py Mon Oct 14 10:44:25 2013 +0300 +++ b/Lib/wave.py Mon Oct 14 14:36:53 2013 +0300 @@ -426,9 +426,14 @@ 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: + if not (isinstance(data, bytes) or + isinstance(data, memoryview) and data.readonly): + data = bytes(data) data = self._convert(data) if self._sampwidth > 1 and sys.byteorder == 'big': import array