diff -r bab0cbf86835 Doc/library/aifc.rst --- a/Doc/library/aifc.rst Sun Nov 10 21:44:36 2013 +0200 +++ b/Doc/library/aifc.rst Sun Nov 10 21:49:16 2013 +0200 @@ -225,12 +225,18 @@ Write data to the output file. This method can only be called after the audio file parameters have been set. + .. versionchanged:: 3.4 + Any :term:`bytes-like object`\ s are now accepted. + .. method:: aifc.writeframesraw(data) Like :meth:`writeframes`, except that the header of the audio file is not updated. + .. versionchanged:: 3.4 + Any :term:`bytes-like object`\ s are now accepted. + .. method:: aifc.close() diff -r bab0cbf86835 Doc/library/sunau.rst --- a/Doc/library/sunau.rst Sun Nov 10 21:44:36 2013 +0200 +++ b/Doc/library/sunau.rst Sun Nov 10 21:49:16 2013 +0200 @@ -250,11 +250,17 @@ Write audio frames, without correcting *nframes*. + .. versionchanged:: 3.4 + Any :term:`bytes-like object`\ s are now accepted. + .. method:: AU_write.writeframes(data) Write audio frames and make sure *nframes* is correct. + .. versionchanged:: 3.4 + Any :term:`bytes-like object`\ s are now accepted. + .. method:: AU_write.close() diff -r bab0cbf86835 Doc/library/wave.rst --- a/Doc/library/wave.rst Sun Nov 10 21:44:36 2013 +0200 +++ b/Doc/library/wave.rst Sun Nov 10 21:49:16 2013 +0200 @@ -205,11 +205,17 @@ Write audio frames, without correcting *nframes*. + .. versionchanged:: 3.4 + Any :term:`bytes-like object`\ s are now accepted. + .. method:: Wave_write.writeframes(data) Write audio frames and make sure *nframes* is correct. + .. versionchanged:: 3.4 + Any :term:`bytes-like object`\ s are now accepted. + Note that it is invalid to set any parameters after calling :meth:`writeframes` or :meth:`writeframesraw`, and any attempt to do so will raise diff -r bab0cbf86835 Lib/aifc.py --- a/Lib/aifc.py Sun Nov 10 21:44:36 2013 +0200 +++ b/Lib/aifc.py Sun Nov 10 21:49:16 2013 +0200 @@ -692,6 +692,8 @@ 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: diff -r bab0cbf86835 Lib/sunau.py --- a/Lib/sunau.py Sun Nov 10 21:44:36 2013 +0200 +++ b/Lib/sunau.py Sun Nov 10 21:49:16 2013 +0200 @@ -415,6 +415,8 @@ 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 diff -r bab0cbf86835 Lib/test/audiotests.py --- a/Lib/test/audiotests.py Sun Nov 10 21:44:36 2013 +0200 +++ b/Lib/test/audiotests.py Sun Nov 10 21:49:16 2013 +0200 @@ -139,6 +139,30 @@ 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_write_memoryview(self): + f = self.create_file(TESTFN) + f.setnframes(self.nframes) + f.writeframes(memoryview(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 bab0cbf86835 Lib/wave.py --- a/Lib/wave.py Sun Nov 10 21:44:36 2013 +0200 +++ b/Lib/wave.py Sun Nov 10 21:49:16 2013 +0200 @@ -435,6 +435,8 @@ 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: diff -r bab0cbf86835 Misc/NEWS --- a/Misc/NEWS Sun Nov 10 21:44:36 2013 +0200 +++ b/Misc/NEWS Sun Nov 10 21:49:16 2013 +0200 @@ -34,6 +34,9 @@ Library ------- +- Issue #16685: Added support for writing any bytes-like objects in the aifc, + sunau, and wave modules. + - Issue #16685: Added support for any bytes-like objects in the audioop module. Removed support for strings.