sawadogosalif commited on
Commit
632d306
1 Parent(s): 624a77e

Create ideas/how_is_segmented_audios.py

Browse files
Files changed (1) hide show
  1. ideas/how_is_segmented_audios.py +17 -0
ideas/how_is_segmented_audios.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydub import AudioSegment, silence
2
+ # file download from here
3
+ #https://www.jw.org/mos/d-s%E1%BA%BDn-yiisi/biible/nwt/books/S%C9%A9ngre/1/
4
+ audio = AudioSegment.from_file("nwt_01_Ge_MM_01.mp3")
5
+
6
+ # Détecter les silences
7
+ silences = silence.detect_silence(audio, min_silence_len=500, silence_thresh=-40)
8
+
9
+ # Découper en fonction des silences détectés
10
+ start = 0
11
+ for i, (silence_start, silence_end) in enumerate(silences):
12
+ segment = audio[start:silence_start]
13
+ # en supposant le dossier segemtns exist deja
14
+ filename = f"segments/segment_{i+1}.mp3"
15
+ segment.export(filename, format="mp3")
16
+ print(f"Segment sauvegardé : {filename}")
17
+ start = silence_end