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

[dataset] add singal channel conf & processor #2439

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions wenet/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def Dataset(data_type,
cycle=cycle)
dataset = dataset.map_ignore_error(processor.decode_wav)

singal_channel_conf = conf.get('singal_channel_conf', {})
dataset = dataset.map(partial(processor.singal_channel, **singal_channel_conf))

speaker_conf = conf.get('speaker_conf', None)
if speaker_conf is not None:
assert 'speaker_table_path' in speaker_conf
Expand Down
20 changes: 20 additions & 0 deletions wenet/dataset/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ def decode_wav(sample):
sample['sample_rate'] = sample_rate
return sample

def singal_channel(sample, channel=0):
""" Choose a channel of sample.
Inplace operation.

Args:
sample: {key, wav, label, sample_rate}
channel: target channel index

Returns:
{key, wav, label, sample_rate}
"""
assert 'wav' in sample
waveform = sample['wav']
channel_nums = waveform.size(0)
assert channel < channel_nums
if channel_nums != 1:
waveform = waveform[channel, :].unsqueeze(0)
sample['wav'] = waveform
return sample


def resample(sample, resample_rate=16000):
""" Resample sample.
Expand Down
Loading