Commit bd10b37c authored by Anthony Larcher's avatar Anthony Larcher
Browse files

modif io

parent ee06b1e4
......@@ -431,7 +431,14 @@ def read_audio(input_file_name, framerate=None):
if ext.lower() == '.sph':
sig, read_framerate, sampwidth = read_sph(input_file_name, 'p')
elif ext.lower() == '.wav' or ext.lower() == '.wave':
sig, read_framerate, sampwidth = read_wav(input_file_name)
try:
sig, read_framerate, sampwidth = read_wav(input_file_name)
except:
import pydub
audio = pydub.AudioSegment.from_wav(input_file_name)
read_framerate = audio.frame_rate
sampwidth = audio.sample_width
sig = numpy.array(audio.split_to_mono()[0].get_array_of_samples())
elif ext.lower() == '.pcm' or ext.lower() == '.raw':
sig, read_framerate, sampwidth = read_pcm(input_file_name)
read_framerate = framerate
......@@ -444,7 +451,7 @@ def read_audio(input_file_name, framerate=None):
if framerate > read_framerate:
print("Warning in read_audio, up-sampling function is not implemented yet!")
elif read_framerate % float(framerate) == 0 and not framerate == read_framerate:
print("downsample")
print("downsample {}".format(input_file_name))
sig = scipy.signal.decimate(sig, int(read_framerate / float(framerate)), n=None, ftype='iir', axis=0)
return sig.astype(numpy.float32), framerate
......
......@@ -203,7 +203,9 @@ def write_dict_hdf5(data, output_filename):
with h5py.File(output_filename, "w") as f:
for key in data:
value = data[key]
if isinstance(value, numpy.ndarray) or isinstance(value, list):
if value is None:
pass
elif isinstance(value, numpy.ndarray) or isinstance(value, list):
f.create_dataset(key,
data=value,
compression="gzip",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment