-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelevenlabs.py
31 lines (23 loc) · 1.01 KB
/
elevenlabs.py
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 pydub import AudioSegment
import os
def split_audio(file_path):
# Load the audio file
audio = AudioSegment.from_file(file_path)
# Define the duration of each smaller audio file in milliseconds (5 minutes)
segment_duration = 5 * 60 * 1000
# Calculate the total number of smaller segments
total_segments = len(audio) // segment_duration
# Create a directory to store the smaller audio files
output_dir = 'elevenlabs'
os.makedirs(output_dir, exist_ok=True)
# Split the audio file into smaller segments
for i in range(total_segments):
start_time = i * segment_duration
end_time = (i + 1) * segment_duration
segment = audio[start_time:end_time]
# Export the segment as a smaller audio file
segment.export(f"{output_dir}/segment_{i+1}.mp3", format="mp3")
print("Audio file has been successfully split into smaller segments.")
if __name__ == "__main__":
file_path = input("Enter the path of the audio file: ")
split_audio(file_path)