# HG changeset patch # User Amine Sehili # Date 1546890718 -3600 # Node ID da2330e5b9ce5f7590239541adf3deb567e7a52f # Parent ceebd8e331c4f1c23d0ebc8c6025d06f454bb7b3 Add function to save audio data as a wave file diff -r ceebd8e331c4 -r da2330e5b9ce auditok/io.py --- a/auditok/io.py Sun Jan 06 16:08:25 2019 +0100 +++ b/auditok/io.py Mon Jan 07 20:51:58 2019 +0100 @@ -468,6 +468,18 @@ start += chunk_size +def _save_wave(filename, data, sampling_rate, sample_width, channels): + """ + Save audio data to a wave file. + """ + # use standard python's wave module + with wave.open(filename, "w") as fp: + fp.setframerate(sampling_rate) + fp.setsampwidth(sample_width) + fp.setnchannels(channels) + fp.writeframes(data) + + def from_file(filename): """ Create an `AudioSource` object using the audio file specified by `filename`.