Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
Handle the case where Essentia won't analyze silent sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
iver56 committed May 15, 2016
1 parent 62f0f5b commit e78e330
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def analyze_multiple(self, sound_files, standardize=True):
self.add_derivative_series(sound_files)

if standardize:
self.add_standardized_series(sound_files)
self.add_standardized_series([sf for sf in sound_files if not sf.is_silent])

def ensure_equal_lengths(self, sounds, series_key='series'):
# Check if series length is equal for all series, and if not, try to fix it with padding
Expand Down
9 changes: 9 additions & 0 deletions essentia_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ def analyze_multiple(self, sound_files):

for j in range(len(processes)):
processes[j].wait()
stdout = processes[j].communicate()[0]
if settings.VERBOSE:
print(stdout)
if 'completely silent file' in stdout:
if settings.VERBOSE:
print('Discarding completely silent file')
sound_files[i + j].is_silent = True
continue

self.parse_output(sound_files[i + j])
self.post_process(sound_files[i + j])
self.clean_up(sound_files[i + j])
Expand Down
6 changes: 5 additions & 1 deletion neuroevolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,12 @@ def evaluate_fitness(self, individuals):
]
self.analyzer.analyze_multiple(sound_files)

for ind in individuals:
if ind.output_sound.is_silent:
ind.set_fitness(0.0)

self.fitness_evaluator_class.evaluate_multiple(
individuals,
[ind for ind in individuals if not ind.output_sound.is_silent],
self.target_sound
)

Expand Down
1 change: 1 addition & 0 deletions sound_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, filename, is_input=True, check_if_file_exists=False):
'ksmps': settings.HOP_SIZE,
'series': {}
}
self.is_silent = False

def compute_duration(self):
with contextlib.closing(wave.open(self.file_path, 'r')) as f:
Expand Down

0 comments on commit e78e330

Please sign in to comment.