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")