0

I try to get a python code running with the pydub library that should split an audio file on silent parts. The code is pretty short but still I get errors that I can't understand. Thanks a lot for your help:

Complete error message:

Traceback (most recent call last):
  File "app.py", line 7, in <module>
    chunks = split_on_silence(sound, 
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pydub/silence.py", line 134, in split_on_silence
    chunks.append(audio_segment[max(start_min, start_ii - keep_silence):
UnboundLocalError: local variable 'start_ii' referenced before assignment

Code:

from os import path
from pydub import AudioSegment
from pydub.silence import split_on_silence


sound = AudioSegment.from_mp3("test5.mp3")
chunks = split_on_silence(sound, 
    # must be silent for at least half a second
    min_silence_len=500,

    # consider it silent if quieter than -16 dBFS
    silence_thresh=-16
)

for i, chunk in enumerate(chunks):
    chunk.export("chunk{0}.wav".format(i), format="wav")

studioDKR
  • 23
  • 3

1 Answers1

0

You need to adjust your silence_thresh argument. You can start by assigning it the value you get when you call sound.dBFS, then adjust the value till it works or you.

  • Apparently it's a known issue that can't be solved with a workaround. But they are working on it and have a pre-solution on github. https://github.com/jiaaro/pydub/issues/481 – studioDKR Jun 01 '20 at 08:37