File size: 1,059 Bytes
ade4f6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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("/Users/moyoyo/code/tests/audios")
audios_5s = current/"5s"
audios_10s = current/"10s"
for f in current.glob("*.wav"):
    file_name = f.name
    print(file_name)
    for i in [0, 5, 10, 15]:
        new_name = f"{f.name.split('.')[0]}-{i}.wav"
        command=f"ffmpeg -i {f} -ss 00:00:{str(i).zfill(2)} -t 00:00:05 {audios_5s/new_name}"
        cmd(command)
    for i in [0, 10, 20, 30]:
        new_name = f"{f.name.split('.')[0]}-{i}.wav"
        command = f"ffmpeg -i {f} -ss 00:00:{str(i).zfill(2)} -t 00:00:10 {audios_10s/new_name}"
        cmd(command)