Skip to content

Commit

Permalink
Fix python 3 range compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
marciomazza committed Aug 21, 2017
1 parent 203a9e1 commit 2a48cba
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pydub/silence.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import itertools

from .utils import db_to_float


Expand All @@ -16,13 +18,13 @@ def detect_silence(audio_segment, min_silence_len=1000, silence_thresh=-16, seek

# check successive (1 sec by default) chunk of sound for silence
# try a chunk at every "seek step" (or every chunk for a seek step == 1)
#
# make sure the last portion of the audio is included in the seach
# even when seek step is greater than 1
last_slice_start = seg_len - min_silence_len
slice_starts = range(0, last_slice_start + 1, seek_step)
if slice_starts[-1] != last_slice_start:
slice_starts.append(last_slice_start)

# guarantee last_slice_start is included in the range
# to make sure the last portion of the audio is seached
if last_slice_start % seek_step:
slice_starts = itertools.chain(slice_starts, [last_slice_start])

for i in slice_starts:
audio_slice = audio_segment[i:i + min_silence_len]
Expand Down

0 comments on commit 2a48cba

Please sign in to comment.