File size: 1,254 Bytes
e4406a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d1d87d
e4406a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from pathlib import Path
import subprocess
from subprocess import CompletedProcess


def cmd(command: str, check=True, capture_output=False) -> CompletedProcess:
    print(command)
    if capture_output:
        ret = subprocess.run(command, shell=True, check=check, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                             universal_newlines=True)
    else:
        ret = subprocess.run(command, shell=True, check=check)
    print(ret.stdout)
    return ret


current = Path("/test_data/audio_clips")
audios_5s = current/"5s"
audios_10s = current/"10s"
if not audios_5s.exists():
    audios_5s.mkdir(parents=True, exist_ok=True)
if not audios_10s.exists():
    audios_10s.mkdir(parents=True, exist_ok=True)
for f in sorted(current.glob("randomforest*.wav")):
    file_name = f.name
    print(file_name)
    for i in [0, 5, 10, 15]:
        new_name = f"{f.stem}-{i}.wav"
        # -ac 1 -ar 16000
        command=f"ffmpeg -i {f} -ss 00:00:{str(i).zfill(2)} -ac 1 -ar 16000 -t 00:00:05 {audios_5s/new_name}"
        cmd(command)
    for i in [0, 10, 20, 30]:
        new_name = f"{f.stem}-{i}.wav"
        command = f"ffmpeg -i {f} -ss 00:00:{str(i).zfill(2)} -ac 1 -ar 16000 -t 00:00:10 {audios_10s/new_name}"
        cmd(command)