from inaSpeechSegmenter import Segmenter
from inaSpeechSegmenter.export_funcs import seg2csv, seg2textgrid
import vlc
import time
path = "stream.mp4"
print(f"segmenting audio from {path}...")
t0 = time.time()
segmentation = Segmenter()(path)
t1 = time.time()
print(f"took {t1 - t0:.01f} seconds")
print(f"found {len(segmentation)} segments")
music_total = sum(i[2]-i[1] for i in segmentation if i[0] == 'music')
total_total = sum(i[2]-i[1] for i in segmentation)
print(f"time preserved: {music_total / total_total * 100 :.01f}%")
print()
media_player = vlc.MediaPlayer()
media_player.set_media(vlc.Media(path))
media_player.play()
media_player.set_time(0)
media_player.pause()
t0 = 0
for kind, start, end in segmentation:
if kind == 'music' and end - start > 30:
print(f'setting time to {start}, duration {end - start} (skipped {start - t0:.02f} seconds)')
media_player.set_time(int(start*1000))
media_player.play()
time.sleep(end - start)
media_player.pause()
time.sleep(1)
t0 = end
Comments
0 B
|👍
/👎