def test_censor(): try: file_path = __get_file('/../data/testing.wav') audio_segment = AudioSegment.from_file(file_path) # Duplicate the audio file and begin muting the new file file_path_dup = __get_file('/../data/testing-censored-0.wav') dup_file = audio_segment.export(file_path_dup, format='wav') audio_segment_dup = AudioSegment.from_file(file_path_dup) # Test that the explicits were successfully removed wrapper = ChunkWrapper(audio_segment_dup) location = str(Path(__file__).parents[2]) + '/clean_file.wav' audio_segment_dup = Censor(explicits, 'wav', location)._Censor__mute_explicits( file_path_dup, wrapper, timestamps).segment # Get the silence segments silent_ranges = silence.detect_silence(audio_segment_dup, min_silence_len=500, silence_thresh=-50) # Assert silence is only in the 'mute' timestamp assert len(silent_ranges) == 1 beginning_diff = silent_ranges[0][0] - timestamps[2]['start'] end_diff = silent_ranges[0][1] - timestamps[2]['end'] # Less than 5 (milliseconds) to account for small inaccuracies assert abs(beginning_diff) < 5 assert abs(end_diff) < 5 except: assert False finally: # Cleanup os.remove(file_path_dup)
def __init__(self, args): Config.interface = args.interface Config.auth_token = args.auth_token Config.summary = args.summary Config.censor = Censor(args.censor) if args.mac_vendors: Config.mac = Mac(args.mac_vendors)
def test_censor(self): c = Censor() target = ( "Jan 13 01:08:40 localhost postfix/smtp[123]: " "0A0000123B: to=<*****@*****.**>, " "relay=mail.example.com[192.0.2.222]:25, delay=0.42, " "delays=0.1/0/0.08/0.24, dsn=2.0.0, status=sent (250 ok)" ) got = c.censor(target) expected = ( "Jan 13 01:08:40 localhost postfix/smtp[123]: " "0A0000123B: to=<*****@*****.**>, " "relay=mail.example.com[192.0.2.222]:25, delay=0.42, " "delays=0.1/0/0.08/0.24, dsn=2.0.0, status=sent (250 ok)" ) self.assertEqual(got, expected)