-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15b5df4
commit 5ea1667
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
This is a sort of interesting name because | ||
I thought of making this while catching a | ||
season of Breaking Bad, which is about a | ||
meth manufacturer, and another name of the | ||
drug is speed. So ha. Also it adjusts vlc's | ||
playback speed so I can more efficiently | ||
waste my time. | ||
|
||
It's not very hard to use. | ||
|
||
python speed.py < path_to_srt | ||
|
||
Stealing from the videolan wiki: | ||
|
||
#to set up vlc to use this script, go to tools->preferences and | ||
#click on "show settings->all" at the bottom. from that menu, | ||
#select "Interface->Main Interfaces", and check the "Remote Control | ||
#Interface" box. Next, select "Interface->Main Interfaces->RC", | ||
#check the "Fake TTY' box, and enter 'home/YOURNAME/vlc.sock'in | ||
#the "UNIX socket command input" field. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
import os, sys, time | ||
t = 0 | ||
drift = 999 | ||
speaking = True | ||
|
||
buf = "" | ||
start = 0 | ||
end = 0 | ||
|
||
#based loosely off http://wiki.videolan.org/How_to_use_VLC_for_transcription_in_linux | ||
def vlc(s): | ||
#for some reason subprocess.Popen/communicate isn't working for me | ||
#from my limited google-fu skills, i can tell this | ||
return os.popen('echo "'+s+'" | nc -U ~/vlc.sock').readlines() | ||
|
||
#http://stackoverflow.com/a/8351793/205784 | ||
#takes an SRT time and turns it into an int for seconds | ||
def srt_time_to_seconds(time): | ||
major = time.replace(" ","").split(',')[0].split(':') | ||
#print major | ||
return int(major[0])*3600 + int(major[1])*60 + int(major[2]) | ||
|
||
#query vlc for number of seconds elapsed in playback | ||
def update_t(): | ||
global t | ||
try: | ||
et = int(vlc('get_time')[0].strip()) | ||
print "Time Delta", et - t | ||
t = et | ||
except Exception: | ||
print "Error parsing time delta" | ||
|
||
|
||
|
||
def has_t(s): | ||
#check if within transcript range | ||
global buf, start, end | ||
#print s, end | ||
while s > end: | ||
while '-->' not in buf: | ||
buf = sys.stdin.readline() | ||
start, end = buf.split('-->') | ||
start = srt_time_to_seconds(start) | ||
end = srt_time_to_seconds(end) | ||
#print buf, start, end | ||
buf = '' | ||
if start - 5 < s < end + 2: | ||
return True | ||
return False | ||
|
||
def set_speed(s): | ||
if s: | ||
vlc('normal') | ||
else: | ||
vlc('faster') | ||
vlc('faster') | ||
vlc('faster') | ||
|
||
|
||
while True: | ||
if drift > -1: | ||
update_t() | ||
drift = 0 | ||
inrange = has_t(t) | ||
print "is speaking", inrange, "at time",t | ||
if inrange != speaking: | ||
speaking = inrange | ||
set_speed(speaking) | ||
time.sleep(1) #maybe a better timing mechanism, but whatever | ||
t += 1 | ||
drift += 1 |