Skip to content

Instantly share code, notes, and snippets.

@tararoys
Last active April 4, 2021 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tararoys/accf5506bea2c5c17e5bb31c7beac6e4 to your computer and use it in GitHub Desktop.
Save tararoys/accf5506bea2c5c17e5bb31c7beac6e4 to your computer and use it in GitHub Desktop.

This is a script that, when you say 'let the movie begin,' it automatically turns on OBS studio via the command line.

Things necessary:

  1. obs studio

  2. the command line interface to obs studio. I'm not sure if you need to install this or not.

  3. You will have to put the obs studio icon out of the system tray and into the task bar. This will make the icon apear. That means the part of the script that searches for the icon to click on it can find it.

  4. You will have to take a screenshot of the OBS studio icon while it is running, and place that screenshot in the 'templates' directory in the user directory. The templates directory might not exist until you name it

  5. You will have to name the icon obs_recording_tray_icon.png, or you will have to change the filename on line 18.

  locate_hover('templates/obs_recording_tray_icon.png')
from talon import imgui, Module, speech_system, scope, actions, app, cron, ui
import sys, os, subprocess, time, math
# We keep command_history_size lines of history, but by default display only
# command_history_display of them.
mod = Module()
setting_command_history_size = mod.setting("command_history_size", int, default=50)
setting_command_history_display = mod.setting(
"command_history_display", int, default=10
)
hist_more = False
history = []
transcribing = 0
markdown_transcript = None
subtitles_transcript = None
subtitle_counter = 1
subtitle_start_time = 0
movie_begins_time = 0
movie_begins_time_milliseconds = 0
last_command_end_time = 0
last_command_end_time_milliseconds = 0
subtitles_transcript_name = ""
transcript_name = ""
##let me launch obs studio
class Pwd:
dir_stack = []
def __init__(self, dirname):
self.dirname = dirname
self.dirname = os.path.realpath(os.path.expanduser(self.dirname))
def __enter__(self):
Pwd.dir_stack.append(self.dirname)
return self
def __exit__(self, type, value, traceback):
Pwd.dir_stack.pop()
def run(self, cmdline, **kwargs):
return subprocess.Popen(cmdline, cwd=Pwd.dir_stack[-1], shell=True, **kwargs)
def create_markdown_transcript(name):
global markdown_transcript
this_dir = os.path.dirname(os.path.realpath(__file__))
file_path = os.path.join(this_dir, name + ".md")
markdown_transcript = open(file_path,"a+")
def close_markdown_transcript():
global markdown_transcript
markdown_transcript.close()
def parse_phrase(word_list):
return " ".join(word.split("\\")[0] for word in word_list)
def print_markdown_transcript(phrase):
print("-----------markdown transcript written:" + phrase + "----------")
global markdown_transcript
if "command" in scope.get("mode"):
markdown_transcript.write(">" + phrase + "\n")
elif "sleep" in scope.get("mode") :
if phrase == "talon wake":
markdown_transcript.write("\n\n\n>" + phrase + "\n")
else:
#markdown_transcript.write(phrase)
markdown_transcript.write(taras_formatter.format(phrase)+".")
if phrase=="talon sleep":
markdown_transcript.write("\n\n\n")
def convertMillis(millis):
miliseconds="{:03d}".format(math.floor(millis)%1000)
seconds="{:02d}".format((math.floor(millis/1000))%60)
minutes="{:02d}".format((math.floor(millis/(1000*60)))%60)
hours = "{:02d}".format((math.floor(millis/(1000*60*60)))%24)
return miliseconds, seconds, minutes, hours
def create_subtitles_transcript(name):
global subtitles_transcript
this_dir = os.path.dirname(os.path.realpath(__file__))
file_path = os.path.join(this_dir, name + ".md")
subtitles_transcript = open(file_path,"a+")
print("SUUUUUBTITLES OPENNNN!!!")
def close_subtitles_transcript():
global subtitles_transcript
subtitles_transcript.close()
def print_subtitles_transcript(phrase):
print("-----------subtitles transcript written:" + phrase + "----------")
global subtitles_transcript
global last_command_end_time
global last_command_end_time_milliseconds
global subtitle_counter
global movie_begins_time
current_time = time.time()
last_command_end_time = time.gmtime(current_time)
last_command_end_time_milliseconds = current_time
current_runtime_milliseconds = math.floor((last_command_end_time_milliseconds - movie_begins_time_milliseconds)*1000)
#subtitles_transcript.write("\nMILLIseconds: " + str(current_runtime_milliseconds) + "\n")
milliseconds, seconds, minutes, hours = convertMillis(current_runtime_milliseconds)
if phrase != "let the movie begin":
subtitles_transcript.write(f"{hours}:{minutes}:{seconds},{milliseconds}\n")
if phrase != "terminate the movie":
subtitles_transcript.write(phrase)
subtitles_transcript.write("\n\n" + str(subtitle_counter) + "\n")
subtitle_counter = subtitle_counter + 1
subtitles_transcript.write(f"{hours}:{minutes}:{seconds},{milliseconds} --> ")
#subtitles_transcript.write("movie_begins_time-----" + str(movie_begins_time) + "\n")
#subtitles_transcript.write("last_command_end_time-----" + str(last_command_end_time) + "\n")
#subtitles_transcript.write(last_command_end_time)
replacement_words = {
"i":"I",
"i'm":"I'm",
"i've":"I've",
"i'll":"I'll",
"i'd":"I'd"
}
def on_phrase(j):
global history
global transcribing
print("--!!!-----wtf kind of data structure am I" + str(j))
try:
val = parse_phrase(getattr(j["parsed"], "_unmapped", j["phrase"]))
except:
val = parse_phrase(j["phrase"])
if val != "":
history.append(val)
history = history[-setting_command_history_size.get() :]
print("--------------peek into onphrase -----")
print(dir(j))
print(j.__class__)
print(j)
if transcribing == 1:
create_markdown_transcript(transcript_name)
print_markdown_transcript(val)
close_markdown_transcript()
create_subtitles_transcript(subtitles_transcript_name)
print_subtitles_transcript(val)
close_subtitles_transcript()
print("----------you made a sound----------")
sentence_ends = {
".": ".",
"?": "?",
"!": "!",
# these are mapped with names since passing "\n" didn't work for reasons
"new-paragraph": "\n\n",
"new-line": "\n",
}
# dictionary of punctuation. no space before these.
punctuation = {
",": ",",
":": ":",
";": ";",
"-": "-",
"/": "/",
"-": "-",
")": ")",
}
no_space_after_these = set("-/(")
class TarasFormat:
def __init__(self):
self.reset()
self.paused = False
ui.register("app_deactivate", lambda app: self.reset())
ui.register("win_focus", lambda win: self.reset())
def reset(self):
self.caps = True
self.space = False
def pause(self, paused):
self.paused = paused
def format(self, text):
if self.paused:
return text
result = ""
first_word = True
for word in text.split():
if first_word == True:
word = word.capitalize()
first_word = False
is_sentence_end = False
is_punctuation = False
if word in replacement_words:
word = replacement_words[word]
#sentence ending words
if word in sentence_ends:
word = sentence_ends[word]
is_sentence_end = True
#punctuation words. Gonna igore this
elif word in punctuation:
word = punctuation[word]
# do nothing
is_punctuation = True
elif self.space:
result += " "
if self.caps:
word = word.capitalize()
result += word
self.space = "\n" not in word and word[-1] not in no_space_after_these
self.caps = is_sentence_end
return result
taras_formatter = TarasFormat()
# todo: dynamic rect?
@imgui.open(y=0)
def gui(gui: imgui.GUI):
global history
text = (
history[:] if hist_more else history[-setting_command_history_display.get() :]
)
for line in text:
gui.text(line)
speech_system.register("phrase", on_phrase)
@mod.action_class
class Actions:
def transcript():
"""create transcript of what is going on"""
global transcript_name
global movie_begins_time
transcript_name = str(movie_begins_time.tm_year) + " " + str(movie_begins_time.tm_mon) + " " + str(movie_begins_time.tm_mday) + " " + str(movie_begins_time.tm_hour) + " " + str(movie_begins_time.tm_min) + " transcript"
create_markdown_transcript(transcript_name)
def close_transcript():
"""create transcript of what is going on"""
close_markdown_transcript()
def subtitles_transcript():
"""create a subtitles file of what is going on"""
global movie_begins_time
global subtitles_transcript
global subtitle_counter
global movie_begins_time_milliseconds
global transcribing
global subtitles_transcript_name
transcribing = 1
current_time = time.time()
movie_begins_time = time.gmtime(current_time)
subtitles_transcript_name = str(movie_begins_time.tm_year) + " " + str(movie_begins_time.tm_mon) + " " + str(movie_begins_time.tm_mday) + " " + str(movie_begins_time.tm_hour) + " " + str(movie_begins_time.tm_min) + " subtitles"
movie_begins_time_milliseconds = time.time()
print("\nLET THE MOVIE BEGINN!!!\n\n")
#starts obs studio automagically
with Pwd(r"C:\\Program Files\\obs-studio\\bin\\64bit\\") as shell:
shell.run(r'obs64.exe --startrecording --minimize-to-tray')
create_subtitles_transcript(subtitles_transcript_name)
subtitle_counter = 1
subtitles_transcript.write(str(subtitle_counter) + "\n")
subtitle_counter = subtitle_counter + 1
subtitles_transcript.write("00:00:00,000 --> ")
close_subtitles_transcript()
def close_sub_transcript():
"""create transcript of what is going on"""
global transcribing
transcribing = 0
let the movie begin:
user.subtitles_transcript()
user.transcript()
terminate the movie:
user.close_sub_transcript()
user.transcript()
user.turn_of_obs_studio()
sleep(1000ms)
mouse_click(1)
sleep(1000ms)
key(up:3)
sleep(1000ms)
key(enter)
sleep(1000ms)
mouse_click(1)
sleep(1000ms)
key(up)
#sleep(1000ms)
#key(down)
sleep(1000ms)
key(enter)
sleep(1000ms)
key(enter)
user.switcher_launch("file manager")
sleep(1000ms)
user.file_manager_open_user_directory("C:\\Users\\TalonBeginner\\Documents\\Research And Writing Workflow")
<phrase>:skip()
from talon import Module
from talon.experimental.locate import locate_hover
mod = Module()
#@mod.action_class
#class Actions:
# def test_reposition():
# '''testing image search thing'''
# print('I exist')
@mod.action_class
class Actions:
def turn_of_obs_studio():
'''turning off obs studio '''
locate_hover('templates/obs_recording_tray_icon.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment