Voice-Note-Audio / preprocessing /move_to_dataset.py
danielrosehill's picture
Initial commit
6158f1c
raw
history blame
2.37 kB
#!/usr/bin/env python3
"""
Script to move preprocessed data to main dataset
"""
import os
import shutil
from pathlib import Path
import json
def move_preprocessed_data():
"""Move preprocessed data to main dataset"""
# Create directories if they don't exist
os.makedirs("audio", exist_ok=True)
os.makedirs("aitranscripts", exist_ok=True)
# Get the next available ID
existing_audio = list(Path("audio").glob("*"))
next_id = 1
if existing_audio:
# Extract numbers from existing files and find the max
ids = []
for f in existing_audio:
try:
ids.append(int(f.stem))
except ValueError:
pass
if ids:
next_id = max(ids) + 1
# Move files from preprocessing queue
queue_files = list(Path("preprocessing/queue").glob("*"))
if not queue_files:
print("No files in preprocessing queue")
return
moved_files = []
for queue_file in queue_files:
if queue_file.suffix in ['.mp3', '.wav']:
# Move audio file
new_name = f"{next_id}{queue_file.suffix}"
dest_path = Path("audio") / new_name
shutil.move(str(queue_file), str(dest_path))
# Look for corresponding transcript
transcript_file = Path("preprocessing/transcripts") / f"{queue_file.stem}.txt"
if transcript_file.exists():
dest_transcript = Path("aitranscripts") / f"{next_id}.txt"
shutil.move(str(transcript_file), str(dest_transcript))
else:
# Create empty transcript file
dest_transcript = Path("aitranscripts") / f"{next_id}.txt"
dest_transcript.write_text("")
moved_files.append((new_name, next_id))
next_id += 1
if moved_files:
print(f"Moved {len(moved_files)} files to main dataset:")
for filename, file_id in moved_files:
print(f" - {filename} (ID: {file_id})")
# Regenerate task list and dataset metadata
print("\nRegenerating task list and dataset metadata...")
os.system("python3 setup_annotation.py")
else:
print("No audio files found in preprocessing queue")
if __name__ == "__main__":
move_preprocessed_data()