File size: 2,541 Bytes
2394f31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3744ef
2394f31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Scripts

## make_clips.py: cut the clips from source videos

The dataset contains no audio. `make_clips.py` cuts the clips of the dataset from
source videos that you have downloaded yourself, with the same processing that produced
the dataset:

1. decode the audio track to 16 kHz mono 16-bit PCM with ffmpeg
   (`ffmpeg -vn -ac 1 -ar 16000 -c:a pcm_s16le`);
2. take the samples from `int(start * 16000)` to `int(end * 16000)`;
3. write them as FLAC to `<out-dir>/<audio_input_path>`.

The script does not download videos. The source video of a row is
`https://www.youtube.com/watch?v=<video_id>`.

### Requirements

Python 3.9 or later with `pyarrow` and `soundfile`, and the `ffmpeg` program:

```bash
pip install pyarrow soundfile
```

### Usage

Get the dataset rows, for example the Dutch rows of the `asr` split (files `data/asr/nl/`):

```bash
huggingface-cli download meetween/mumospee_v3 --repo-type dataset \
    --include "data/asr/nl/*" --local-dir mumospee
```

Cut the clips of one video:

```bash
python make_clips.py --rows mumospee/data/asr/nl \
    --video downloads/-H9G_NHn4Xc.mp4 --out-dir clips
```

or of all videos in a folder:

```bash
python make_clips.py --rows mumospee/data/asr/nl --videos-dir downloads --out-dir clips
```

The video ID is read from the file name: `<video_id>.<ext>`, `<video_id>_<anything>.<ext>`
or `<anything>[<video_id>].<ext>`; otherwise pass `--video-id`. `--rows` also accepts a
CSV or JSON Lines file with the columns `video_id`, `clip_id`, `start`, `end` and
`audio_input_path`.

### Output

```text
clips/
├── audio/<lang>/<video_id>/<clip_id>.flac   one file per clip, at the row's audio_input_path
└── make_clips_report.csv                    video_id, clip_id, status (written / skipped / failed), note
```

The audio of a row is `clips/<audio_input_path>`. Clips that already exist are skipped,
so an interrupted run can be repeated; `--overwrite` rewrites them.

### Notes

- The clips match the clips the dataset was built from when the downloaded audio is the
  same as the original. In a test with the original source files, 142 of 144 clips were
  identical sample by sample, and the other 2 differed by at most one unit in single
  samples (a rounding difference between ffmpeg versions).
- A video downloaded at a different time or in another format can differ slightly from
  the original, and a video may no longer be available.
- If the downloaded audio is shorter than a clip's `end`, the clip is cut at the end of
  the audio, and the report notes this.