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