Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm trying to take an mp3 and simply remove silent blocks. I'm using
pydub.split_on_silence()
, but it returns an empty list. In my code below, the audio chunk seems to be silent for the first 4 seconds, has 12 seconds of audio, then is silent for the remainder.
from pydub import AudioSegment
from pydub.silence import split_on_silence
sound = AudioSegment.from_mp3("audio_files/xxxxxx.mp3")
clip = sound[21*1000:45*1000]
#"graph" the volume in 1 second increments
for x in range(0,int(len(clip)/1000)):
print(x,clip[x*1000:(x+1)*1000].max_dBFS)
chunks = split_on_silence(
clip,
min_silence_len=1000,
silence_thresh=-16,
keep_silence=100
print("number of chunks",len(chunks))
print (chunks)
Output :
0 -59.67942035834925
1 -59.67942035834925
2 -60.20599913279624
3 -59.18294868384861
4 -7.294483767470469
5 -9.54772815923718
6 -7.8863408992261785
7 -8.018780602216872
8 -8.086437972291877
9 -9.689721851628853
10 -12.146807891343315
11 -13.187719632532362
12 -14.065443216019279
13 -14.344275171835644
14 -14.668150366783275
15 -10.544064231686791
16 -59.67942035834925
17 -59.9387199016366
18 -58.94496421785445
19 -59.9387199016366
20 -59.42763781218885
21 -59.67942035834925
22 -60.20599913279624
23 -59.67942035834925
number of chunks 0
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.