def _split_audio_from_video(video_path: Path, overwrite: bool) -> Path:
    # Init splitter
    splitter = FFmpegAudioSplitter()

    # Split audio
    audio_save_path = video_path.parent / "audio.wav"
    if not audio_save_path.exists() or overwrite:
        audio_save_path = splitter.split(video_path,
                                         video_path.parent / "audio.wav")

    return audio_save_path
def test_mocked_save_path(tmpdir, example_video, audio_save_path):
    # Append save name to tmpdir
    audio_save_path = Path(tmpdir) / audio_save_path

    # Initialize splitter
    splitter = FFmpegAudioSplitter()

    # Mock split
    with mock.patch("ffmpeg.run") as mocked_ffmpeg:
        mocked_ffmpeg.return_value = (b"OUTPUT", b"ERROR")
        splitter.split(video_read_path=example_video,
                       audio_save_path=audio_save_path)
Exemplo n.º 3
0
def test_event_pipeline_no_backfill(
    empty_creds_db,
    empty_creds_fs,
    mocked_sr_model,
    example_config,
    example_seattle_routes,
):
    # Configure all mocks
    with mock.patch("cdptools.dev_utils.load_custom_object.load_custom_object"
                    ) as mock_loader:
        mock_loader.side_effect = [
            SeattleEventScraper(),
            empty_creds_db,
            empty_creds_fs,
            FFmpegAudioSplitter(),
            mocked_sr_model,
        ]

        # Initialize pipeline
        pipeline = mock.Mock(EventGatherPipeline(example_config))

        with mock.patch("requests.get") as mock_requests:
            # No backfill means only routes will be gathered because example html file
            # only includes past events.
            mock_requests.side_effect = [RequestReturn(example_seattle_routes)]

            pipeline.run()

            # This should never be ran because example html files only include past
            # events.
            pipeline.process_event.assert_not_called()
Exemplo n.º 4
0
def test_event_pipeline_mixture_sr_model_initialization(
    empty_creds_db,
    empty_creds_fs,
    mocked_sr_model,
    mocked_caption_sr_model,
    example_config_with_mixture_sr_model,
):
    # Configure all mocks
    with mock.patch("cdptools.dev_utils.load_custom_object.load_custom_object"
                    ) as mock_loader:
        mock_loader.side_effect = [
            SeattleEventScraper(),
            empty_creds_db,
            empty_creds_fs,
            FFmpegAudioSplitter(),
            mocked_caption_sr_model,
            mocked_sr_model,
        ]

        # Initialize pipeline
        pipeline = mock.Mock(
            EventGatherPipeline(example_config_with_mixture_sr_model))

        # Test EventGatherPipeline's mixture sr_model initialization
        assert hasattr(pipeline, "sr_model")
        assert hasattr(pipeline, "caption_sr_model")
Exemplo n.º 5
0
def mocked_splitter(example_audio) -> FFmpegAudioSplitter:
    mocked_splitter = mock.Mock(FFmpegAudioSplitter())
    mocked_splitter.split.return_value = example_audio
    return mocked_splitter