-2

I'm trying to index an audio file at a certain non-silent timestamp, say 20 seconds from the beginning (0:20:00), and find the closest timestamp from there that silence begins, say 21 seconds from the beginning (0:21:00).

I'm aware that pydub has detect_silence feature that may be useful but not sure how to index an audio file using timestamp. I'm open to using other libraries as well.

ytrewq
  • 3,670
  • 9
  • 42
  • 71
  • I don't understand what is the problem. You may use `detect_silence` to get all regions (as list with pairs `(start, end)`) and later search on list first pair which have start bigger than `0:20:00` – furas Aug 28 '22 at 10:10
  • diging in source code I found you can use slice `[start:end]` to get some region - `audio{20_000:]` gives audio at 20second. – furas Aug 28 '22 at 10:12

1 Answers1

1

I didn't test it but

detect_silence gives list with pairs (start, end) so you could run on original audio and later search this list to find first pair which have start bigger than 0:20:00 (or rather bigger than 20_000)

But it can use slice [start:end] to work only with some part of audio.

part = audio[20_000:]

It could look like this

from pydub import AudioSegment
from pydub.silence import detect_silence

audio = AudioSegment.from_mp3("your_audio.mp3")
part = audio[20_000:]

chunks = detect_silence(part, ... other options ...)

print('start in part :', chunks[0][0])
print('start in audio:', chunks[0][0] + 20_000)
furas
  • 134,197
  • 12
  • 106
  • 148