Advertisement
JoelSjogren

music seeker

May 5th, 2022
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. from inaSpeechSegmenter import Segmenter
  2. from inaSpeechSegmenter.export_funcs import seg2csv, seg2textgrid
  3.  
  4. import vlc
  5. import time
  6.  
  7. path = "stream.mp4"
  8.  
  9. print(f"segmenting audio from {path}...")
  10. t0 = time.time()
  11. segmentation = Segmenter()(path)
  12. t1 = time.time()
  13. print(f"took {t1 - t0:.01f} seconds")
  14. print(f"found {len(segmentation)} segments")
  15. music_total = sum(i[2]-i[1] for i in segmentation if i[0] == 'music')
  16. total_total = sum(i[2]-i[1] for i in segmentation)
  17. print(f"time preserved: {music_total / total_total * 100 :.01f}%")
  18. print()
  19.  
  20. media_player = vlc.MediaPlayer()
  21. media_player.set_media(vlc.Media(path))
  22.  
  23. media_player.play()
  24. media_player.set_time(0)
  25. media_player.pause()
  26.  
  27. t0 = 0
  28.  
  29. for kind, start, end in segmentation:
  30.     if kind == 'music' and end - start > 30:
  31.         print(f'setting time to {start}, duration {end - start} (skipped {start - t0:.02f} seconds)')
  32.         media_player.set_time(int(start*1000))
  33.         media_player.play()
  34.         time.sleep(end - start)
  35.         media_player.pause()
  36.         time.sleep(1)
  37.         t0 = end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement