-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmp3Clipper.py
More file actions
31 lines (24 loc) · 1021 Bytes
/
mp3Clipper.py
File metadata and controls
31 lines (24 loc) · 1021 Bytes
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
import os
import subprocess
# import taipy as tp
def split_mp3(output_folder, segment_length=10):
input_folder = os.path.join('assets','mp3')
output_folder = os.path.abspath(output_folder)
# scenario_cfg = tp.config['scenario']
# tp.config['scenario']['data']['path'] = input_folder
# scenario = tp.create_scenario(scenario_cfg)
if not os.path.exists(output_folder):
os.makedirs(output_folder)
audio_files = [f for f in os.listdir(input_folder) if f.endswith('.mp3')]
for input_file in audio_files:
input_file_path = os.path.join(input_folder, input_file)
output_file_pattern = os.path.join(output_folder, f"segment_%03d.mp3")
# Run ffmpeg command to split the audio file
subprocess.run([
"ffmpeg",
"-i", input_file_path,
"-f", "segment",
"-segment_time", str(segment_length),
"-c", "copy",
output_file_pattern
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)