Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added uniform speaker sampling to RandomAssignSpeakersFromCorpus #254

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions users/rossenbach/corpus/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,32 @@ def run(self):
c.dump(self.out_corpus.get())



class RandomAssignSpeakersFromCorpus(Job):
"""
Takes another bliss corpus as speaker reference and randomly distributes speaker tags

Used e.g. for synthetic TTS data
"""

def __init__(self, bliss_corpus: tk.Path, speaker_reference_bliss_corpus: tk.Path, seed: int = 42):

__sis_hash_exclude__ = {"randomize_speaker": True}

def __init__(self, bliss_corpus: tk.Path, speaker_reference_bliss_corpus: tk.Path, seed: int = 42,
randomize_speaker: bool = True):
"""

:param bliss_corpus: bliss corpus to assign speakers to
:param speaker_reference_bliss_corpus: bliss corpus to take speakers from
:param seed: random seed for deterministic behavior
:param randomize_speaker:
True: samples speakers at random
False: every speaker appears at least once if bliss_size > num_speakers
"""
self.bliss_corpus = bliss_corpus
self.speaker_reference_bliss_corpus = speaker_reference_bliss_corpus
self.seed = seed

self.randomize_speaker = randomize_speaker
self.out_corpus = self.output_path("corpus.xml.gz")

def tasks(self) -> Iterator[Task]:
Expand All @@ -141,14 +149,26 @@ def run(self):
speaker_corpus.load(self.speaker_reference_bliss_corpus.get_path())

out_corpus.speakers = speaker_corpus.speakers

# shuffle speaker list for randomization of sequence to speaker mapping
speaker_name_list = list(out_corpus.speakers.keys())
random.shuffle(speaker_name_list)
num_speakers = len(speaker_name_list)

for recording in out_corpus.all_recordings():
recording.speaker_name = None
recording.default_speaker = None
for segment in recording.segments:
segment.speaker_name = speaker_name_list[np.random.randint(num_speakers)]
if self.randomize_speaker:
segment.speaker_name = speaker_name_list[np.random.randint(num_speakers)]
else:
if len(speaker_name_list)>0:
segment.speaker_name = speaker_name_list.pop()
else:
# re-initialize random speaker list
speaker_name_list = list(out_corpus.speakers.keys())
random.shuffle(speaker_name_list)
segment.speaker_name = speaker_name_list.pop()

out_corpus.dump(self.out_corpus.get_path())

Expand Down
Loading