From bf6b88d3a22e82b516d93ce455771e7f00ed5008 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Thu, 23 Dec 2021 19:35:39 -0500 Subject: [PATCH] [+] Function to manually label data --- requirements-mac.txt | 1 + requirements-win-cuda.txt | 1 + src/validate_cn_celeb.py | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/requirements-mac.txt b/requirements-mac.txt index 86b6585..66825af 100644 --- a/requirements-mac.txt +++ b/requirements-mac.txt @@ -4,3 +4,4 @@ plaidml-keras==0.7.0 inaSpeechSegmenter==0.6.8 python-telegram-bot +pygame diff --git a/requirements-win-cuda.txt b/requirements-win-cuda.txt index be722db..fb58527 100644 --- a/requirements-win-cuda.txt +++ b/requirements-win-cuda.txt @@ -3,3 +3,4 @@ tensorflow==2.7.0 inaSpeechSegmenter==0.6.8 python-telegram-bot +pygame diff --git a/src/validate_cn_celeb.py b/src/validate_cn_celeb.py index 16a64b7..b64c247 100644 --- a/src/validate_cn_celeb.py +++ b/src/validate_cn_celeb.py @@ -5,6 +5,7 @@ from pathlib import Path import matplotlib.pyplot as plt import numpy as np +import pygame from inaSpeechSegmenter import Segmenter from ina_main import process, get_result_percentages @@ -100,10 +101,41 @@ def graph_histogram(): print(closest_to_half_id) +def manually_label_data(): + """ + Since CN-Celeb isn't labelled with the speaker's gender, this script is used to manually label + them. + """ + pygame.mixer.init() + + # Loop through all speaker + id_labels = {} + for id_i, id in enumerate(ids): + id_dir = data_dir.joinpath(id) + + # Loop through all tracks until identified + tracks = [f for f in os.listdir(id_dir) if f.endswith('.flac')] + for track_i, audio in enumerate(tracks): + # Play track + sound = pygame.mixer.Sound(id_dir.joinpath(audio)) + sound.play() + i = input(f'Playing speaker {id_i}/{len(ids)} - track {track_i}/{len(tracks)}\n' + f'- Identify gender. Press f / m, or anything else to play next track: ')\ + .lower().strip() + sound.stop() + + # Labeled + if i == 'f' or i == 'm': + id_labels[id] = i + data_dir.joinpath('id_labels.json').write_text(json.dumps(id_labels)) + break + + if __name__ == '__main__': cn_celeb_root = Path('C:/Users/me/Workspace/Data/CN-Celeb_flac') data_dir = cn_celeb_root.joinpath('data') ids = [id for id in os.listdir(data_dir) if id.startswith('id')] # segment_all() - graph_histogram() + # graph_histogram() + manually_label_data()