| 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" |
| |
| 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) |
|
|