Last active
June 9, 2018 19:02
-
-
Save LLCampos/ba8e9cee7e67e00b70c6f9b65db5d2f4 to your computer and use it in GitHub Desktop.
Records HipChat video calls
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
#!/usr/bin/env python3 | |
import os | |
import subprocess | |
from time import sleep, time | |
save_folder = "/home/lcampos/Dropbox/BetterConversationsRecordings" | |
speakers_monitor_stream = "alsa_output.pci-0000_00_1f.3.analog-stereo.monitor" | |
class Recording: | |
recording_microphone_filename = "recording_microphone.wav" | |
recording_speakers_filename = "recording_speakers.wav" | |
def __init__(self, save_folder, speakers_monitor_stream): | |
self.save_folder = save_folder | |
self.speakers_monitor_stream = speakers_monitor_stream | |
self.recording_microphone_file_path = "{}/{}".format(self.save_folder, self.recording_microphone_filename) | |
self.recording_speakers_file_path = "{}/{}".format(self.save_folder, self.recording_speakers_filename) | |
self.recording_final_file_path = "{}/{}-{}.wav".format(self.save_folder, "HipChat", int(time())) | |
def start(self): | |
self.recording_microphone_process = self.start_recording_microphone() | |
self.recording_speakers_process = self.start_recording_speakers() | |
def start_recording_microphone(self): | |
command = "arecord -fdat {}".format(self.recording_microphone_file_path) | |
return subprocess.Popen(command.split()) | |
def start_recording_speakers(self): | |
command = "parec --rate=48000 -d {} --file-format=wav {}".format(self.speakers_monitor_stream, self.recording_speakers_file_path) | |
return subprocess.Popen(command.split()) | |
def stop(self): | |
self.recording_microphone_process.terminate() | |
sleep(2) | |
self.recording_speakers_process.terminate() | |
sleep(2) | |
self.merge_recordings() | |
sleep(2) | |
self.clean() | |
def merge_recordings(self): | |
command = "sox -M {} {} {}".format(self.recording_microphone_file_path, self.recording_speakers_file_path, self.recording_final_file_path) | |
subprocess.Popen(command.split()) | |
def clean(self): | |
os.remove(self.recording_microphone_file_path) | |
os.remove(self.recording_speakers_file_path) | |
def is_hipchat_video_window_open(): | |
try: | |
windows = subprocess.check_output("wmctrl -l", shell=True) | |
except subprocess.CalledProcessError: | |
return False | |
if "HipChat Video" in str(windows): | |
return True | |
return False | |
recording = None | |
while True: | |
if is_hipchat_video_window_open(): | |
if not recording: | |
recording = Recording(save_folder, speakers_monitor_stream) | |
recording.start() | |
else: | |
if recording: | |
recording.stop() | |
recording = None | |
sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment