changeset 44:b7b1672b3c3b

Reading and writing of files now is done by soundfile since there seems to be a bug with writing .wav files with librosa (mplayer would play them as rubbish). Added soundfile as a requirement.
author Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk>
date Mon, 09 Oct 2017 11:55:03 +0100
parents a8e3d63653b6
children 771dde08349a
files python/requirements.txt python/simscene.py
diffstat 2 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/python/requirements.txt	Sun Oct 08 15:23:50 2017 +0100
+++ b/python/requirements.txt	Mon Oct 09 11:55:03 2017 +0100
@@ -4,3 +4,4 @@
 librosa
 matplotlib
 tabulate
+soundfile
--- a/python/simscene.py	Sun Oct 08 15:23:50 2017 +0100
+++ b/python/simscene.py	Mon Oct 09 11:55:03 2017 +0100
@@ -22,7 +22,10 @@
 # Librosa
 import librosa
 import librosa.display
-import librosa.output
+
+# PySoundfile
+
+import soundfile as sf
 
 # Matplotlib
 import matplotlib.pyplot as plt
@@ -73,7 +76,7 @@
             candidates = glob.glob('{}/event/{}*wav'.format(input_path, sampleid))
             chosen_fname = random.sample(candidates, 1)[0]
             
-            wav, SR = librosa.load(chosen_fname, sr=sr)
+            wav, SR = sf.read(chosen_fname)
         else:
             chosen_fname = random.sample(candidates, 1)[0]
 
@@ -365,7 +368,7 @@
             # If no patterns are found, search for normal audio files
             candidates = glob.glob('{}/background/{}*.wav'.format(input_path, backgrounds_df['sampleid'].loc[n]))           
             chosen_fname = random.sample(candidates, 1)[0]
-            wav, sr = librosa.load(chosen_fname, sr=SR)
+            wav, sr = sf.read(chosen_fname)
         else:
             chosen_fname = random.sample(candidates, 1)[0]
             wav, sr, pattern_timedict = render_pattern(chosen_fname, input_path)
@@ -541,7 +544,7 @@
             # If no patterns are found, search for normal audio files
             candidates = glob.glob('{}/event/{}*.wav'.format(input_path, events_df['sampleid'].loc[n]))           
             chosen_fname = random.sample(candidates, 1)[0]
-            wav, sr = librosa.load(chosen_fname, sr=SR)
+            wav, sr = sf.read(chosen_fname)
         else:
             chosen_fname = random.sample(candidates, 1)[0]
             wav, sr, pattern_timedict = render_pattern(chosen_fname, input_path)
@@ -685,7 +688,7 @@
             logging.debug('{}:New track ebr: {}db'.format(label, 20*np.log10(new_ebr)))
 
         if channel_mode == 'separate':
-            librosa.output.write_wav('{}/{}_event_track.wav'.format(output_path, label),
+            sf.write('{}/{}_event_track.wav'.format(output_path, label),
                                      track_arr/np.max(track_arr),
                                      SR)
             
@@ -786,9 +789,9 @@
         
     if channel_mode == 'mono':
         if append_to_filename:
-            librosa.output.write_wav('{}/scene_{}.wav'.format(output_path, append_to_filename), scene_arr, SR)
+            sf.write('{}/scene_{}.wav'.format(output_path, append_to_filename), scene_arr, SR)
         else:
-            librosa.output.write_wav('{}/scene.wav'.format(output_path), scene_arr, SR)
+            sf.write('{}/scene.wav'.format(output_path), scene_arr, SR)
 
     # Print timesdict