def test_can_transcribe_long_speech(self): manager = VideoManager( os.path.join(os.path.dirname(__file__), "input", "test1.mp4"), ) _, audio = tempfile.mkstemp(".wav") manager.extract_audio(audio) audio_manager = AudioManager(audio) transcriber = Transcriber(audio_manager) transcribe_result = list(transcriber.transcribe()) self.assertGreaterEqual(len(transcribe_result), 1)
def test_can_extract_audio(self): manager = VideoManager( os.path.join(os.path.dirname(__file__), "input", "test1.mp4"), ) _, audio = tempfile.mkstemp(".wav") extracted_audio = manager.extract_audio(audio) self.assertEqual(audio, extracted_audio) self.assertTrue(os.path.exists(extracted_audio)) os.remove(audio)
def main(): logger = logging.getLogger() logger.info("start processing %s", input_file) manager = VideoManager(input_file) audio = manager.extract_audio(settings.ROOT / "output/a.wav") thumbnail = manager.extract_thumbnail(settings.ROOT / "output/a.jpg") audio_manager = AudioManager(audio) transcriber = Transcriber(audio_manager) filter_sections = [] for transcribtion in transcriber.transcribe(): logger.debug("transcription: %s", transcribtion) word, start, end = transcribtion if detect_mature_word(word): logger.debug("mature word: %s, %s", word, detect_mature_word(word)) audio_manager.apply_beep(start, end) manager.apply_mask(start, end) filter_sections.append({ "start_time": start, "end_time": end, "word": word }) manager.apply_audio(audio_manager.save(settings.ROOT / "output/a_beep.wav")) manager.save(settings.ROOT / "output/a.mp4") print( json.dumps({ "thumbnail": str(thumbnail), "filter_sections": filter_sections, "filter_video": str(settings.ROOT / "output" / "a.mp4"), }))