def samples_to_file(samples, rate, file_out, fmt='', dtype='int16'): """Write data to file, using requested format or infer from file .ext. Only integer `rate` values are supported. See http://ajaxsoundstudio.com/pyodoc/api/functions/sndfile.html """ file_fmt, data_fmt = _get_pyo_codes(fmt, dtype, file_out) if type(samples) == np.ndarray: samples = samples.tolist() if type(samples) != list: raise TypeError('samples should be a list or np.array') try: pyo.savefile(samples, path=file_out, sr=int(rate), channels=1, fileformat=file_fmt, sampletype=data_fmt) except Exception: msg = 'could not save `{0}`; permissions or other issue?' raise IOError(msg.format(file_out))
def samples_to_file(samples, rate, file_out, fmt='', dtype='int16'): """Write data to file, using requested format or infer from file .ext. Only integer `rate`s are supported. See http://ajaxsoundstudio.com/pyodoc/api/functions/sndfile.html """ file_fmt, data_fmt = _get_pyo_codes(fmt, dtype, file_out) if type(samples) == np.ndarray: samples = samples.tolist() if type(samples) != list: raise TypeError('samples should be a list or np.array') try: pyo.savefile(samples, path=file_out, sr=int(rate), channels=1, fileformat=file_fmt, sampletype=data_fmt) except: msg = 'could not save `{0}`; permissions or other issue?' raise IOError(msg.format(file_out))