Resample data. Inplace operation. Args: data: Iterable[{key, wav, label, sample_rate}] resample_rate: target resample rate Returns: Iterable[{key, wav, label, sample_rate}]
(data, resample_rate=48000, min_sample_rate=16000, mode='train', n_codebook=4)
| 212 | |
| 213 | |
| 214 | def upsample(data, resample_rate=48000, min_sample_rate=16000, mode='train', |
| 215 | n_codebook=4): |
| 216 | """ Resample data. |
| 217 | Inplace operation. |
| 218 | |
| 219 | Args: |
| 220 | data: Iterable[{key, wav, label, sample_rate}] |
| 221 | resample_rate: target resample rate |
| 222 | |
| 223 | Returns: |
| 224 | Iterable[{key, wav, label, sample_rate}] |
| 225 | """ |
| 226 | for sample in data: |
| 227 | assert 'semantic_token' in sample |
| 228 | # TODO: unify data processing key names |
| 229 | if 'acoustic_token' not in sample: |
| 230 | continue |
| 231 | |
| 232 | if 'sample_rate' in sample.keys(): |
| 233 | sample_rate = sample['sample_rate'] |
| 234 | else: |
| 235 | sample_rate = 24000 |
| 236 | token = np.array(sample['semantic_token'][0][:-1]) |
| 237 | |
| 238 | # Calculate the repetition factor for resampling |
| 239 | repetition_factor = int(n_codebook * resample_rate / sample_rate) |
| 240 | if sample_rate != resample_rate: |
| 241 | if sample_rate < min_sample_rate: |
| 242 | continue |
| 243 | sample['sample_rate'] = resample_rate |
| 244 | sample['semantic_token'] = np.array( |
| 245 | [np.repeat(token, repetition_factor)]) |
| 246 | |
| 247 | yield sample |
| 248 | |
| 249 | def compute_fbank(data, |
| 250 | feat_extractor, |