Skip to content

Instantly share code, notes, and snippets.

@dennisvink
Created July 11, 2023 10:18
Show Gist options
  • Save dennisvink/79834bb7fac50dce26c9fc3e6b50290b to your computer and use it in GitHub Desktop.
Save dennisvink/79834bb7fac50dce26c9fc3e6b50290b to your computer and use it in GitHub Desktop.
Python script to facilitate auditing MP3 audio recordings and transcribed text
import os
import shutil
from pygame import mixer
import time
mixer.init()
base_dir = './' # The directory where your files are located
yes_dir = os.path.join(base_dir, 'yes')
no_dir = os.path.join(base_dir, 'no')
maybe_dir = os.path.join(base_dir, 'maybe')
os.makedirs(yes_dir, exist_ok=True)
os.makedirs(no_dir, exist_ok=True)
os.makedirs(maybe_dir, exist_ok=True)
mp3_files = [f for f in os.listdir(base_dir) if f.endswith('.mp3')]
mp3_files.sort(key=lambda f: os.path.getsize(os.path.join(base_dir, f)), reverse=True)
for mp3 in mp3_files:
txt_file = mp3.replace('.mp3', '.txt')
while True:
# Try to display the contents of the .txt file
try:
with open(os.path.join(base_dir, txt_file), 'r') as f:
print(f.read())
except Exception as e:
print(f'Error reading file {txt_file}: {e}')
# Try to play the MP3 file
try:
mixer.music.load(os.path.join(base_dir, mp3))
mixer.music.play()
except Exception as e:
print(f'Error playing file {mp3}: {e}')
# Wait for the music to finish
while mixer.music.get_busy():
time.sleep(1)
# Offer options
action = input("(R) Replay, (Y) Yes, (N) No, (L) Later, (E) Edit: ").upper()
if action == 'R':
# Replay the MP3
try:
mixer.music.play()
except Exception as e:
print(f'Error replaying file {mp3}: {e}')
elif action in ['Y', 'N', 'L']:
target_dir = yes_dir if action == 'Y' else no_dir if action == 'N' else maybe_dir
try:
shutil.move(os.path.join(base_dir, mp3), target_dir)
shutil.move(os.path.join(base_dir, txt_file), target_dir)
except Exception as e:
print(f'Error moving files {mp3} and {txt_file}: {e}')
break
elif action == 'E':
try:
os.system(f'vim {os.path.join(base_dir, txt_file)}')
except Exception as e:
print(f'Error editing file {txt_file}: {e}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment