Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assamilator needs to correct the timestamps in the transcripts to use real time based off the file creation date and the telative timestamps in the vtt file. #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion tools/assamilator/audio_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,18 @@ def transcribe_audio(self, file_path, dir_name):
print("Found .vtt files: ", vtt_files)
if not vtt_files:
return json.dumps({"error": "No .vtt files found"}), 500
import re
from datetime import timedelta
creation_time = os.path.getctime(abs_file_path)
with open(vtt_files[0], "r") as f:
lines = f.readlines()[2:]
for i, line in enumerate(lines):
match = re.search(r'(\d+):(\d+):(\d+)\.(\d+)', line)
if match:
hours, minutes, seconds, milliseconds = map(int, match.groups())
timestamp = timedelta(hours=hours, minutes=minutes, seconds=seconds, milliseconds=milliseconds)
adjusted_timestamp = timestamp + timedelta(seconds=creation_time)
lines[i] = line.replace(match.group(), str(adjusted_timestamp))
transcription = ''.join(lines)

shutil.rmtree(dir_name)
Expand All @@ -88,7 +98,7 @@ def save_to_obsidian_vault(self, transcription, file_name):
#add filename.opus to the metadata
metadata = f"---\ndataview\ntimestamp: {timestamp}\n---\n![[{file_name}.opus]]\n\n"
with open(os.path.join(self.vault_dir, file_name + ' Transcript.md'), 'w') as f:
f.write(f"# Transcription of {file_name}\n\n{metadata}{transcription}")
f.write(f"# Transcription of {file_name}\n\n{metadata}{transcription}\n\nAdjusted Timestamps:\n{adjusted_timestamps}")

def process_folders(self, text_box, folder_listbox):
for folder in self.config_handler.config.get('folder_list', []):
Expand Down