def _smoke_test(self, format, compression, check_num_frames): """ The purpose of this test suite is to verify that apply_codec functionalities do not exhibit abnormal behaviors. """ torch.random.manual_seed(42) sample_rate = 8000 num_frames = 3 * sample_rate num_channels = 2 waveform = torch.rand(num_channels, num_frames) augmented = F.apply_codec(waveform, sample_rate, format, True, compression) assert augmented.dtype == waveform.dtype assert augmented.shape[0] == num_channels if check_num_frames: assert augmented.shape[1] == num_frames
"bits_per_sample": 8 }, "8 bit mu-law"), ({ "format": "gsm" }, "GSM-FR"), ({ "format": "mp3", "compression": -9 }, "MP3"), ({ "format": "vorbis", "compression": -1 }, "Vorbis"), ] for param, title in configs: augmented = F.apply_codec(waveform, sample_rate, **param) plot_specgram(augmented, sample_rate, title=title) play_audio(augmented, sample_rate) ###################################################################### # Simulating a phone recoding # --------------------------- # # Combining the previous techniques, we can simulate audio that sounds # like a person talking over a phone in a echoey room with people talking # in the background. # sample_rate = 16000 speech, _ = get_speech_sample(resample=sample_rate)