Mercurial > hg > auditok
changeset 98:da2330e5b9ce
Add function to save audio data as a wave file
author | Amine Sehili <amine.sehili@gmail.com> |
---|---|
date | Mon, 07 Jan 2019 20:51:58 +0100 |
parents | ceebd8e331c4 |
children | ccab869cdbcb |
files | auditok/io.py |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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`.