Delete diarize-dataset.py
Browse files- diarize-dataset.py +0 -75
diarize-dataset.py
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import json
|
| 3 |
-
from rich.console import Console
|
| 4 |
-
from rich.prompt import Prompt
|
| 5 |
-
|
| 6 |
-
# Initialize Rich Console
|
| 7 |
-
console = Console()
|
| 8 |
-
console.clear()
|
| 9 |
-
|
| 10 |
-
# Title Screen
|
| 11 |
-
console.print("""[bold cyan]
|
| 12 |
-
=====================================
|
| 13 |
-
SPEAKER DIARIZATION TOOL
|
| 14 |
-
=====================================
|
| 15 |
-
[/bold cyan]""")
|
| 16 |
-
console.print("This tool processes audio files and generates speaker diarization metadata.")
|
| 17 |
-
console.print("Input and output directories will be created in the same folder as this script.")
|
| 18 |
-
|
| 19 |
-
# Define Paths Relative to Script Location
|
| 20 |
-
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 21 |
-
INPUT_DIR = os.path.join(SCRIPT_DIR, "wavs")
|
| 22 |
-
OUTPUT_DIR = os.path.join(SCRIPT_DIR, "jsons")
|
| 23 |
-
|
| 24 |
-
# Ensure Directories Exist
|
| 25 |
-
os.makedirs(INPUT_DIR, exist_ok=True)
|
| 26 |
-
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 27 |
-
|
| 28 |
-
# Prompt User for Hugging Face Token
|
| 29 |
-
HF_TOKEN = Prompt.ask("[bold cyan]Enter your Hugging Face token[/bold cyan]", default="")
|
| 30 |
-
|
| 31 |
-
# Validate Token
|
| 32 |
-
if not HF_TOKEN or not HF_TOKEN.startswith("hf_"):
|
| 33 |
-
console.print("[bold red]Error:[/bold red] Invalid Hugging Face token.", style="red")
|
| 34 |
-
exit(1)
|
| 35 |
-
|
| 36 |
-
# Pause to allow user to populate audio directory
|
| 37 |
-
console.print(f"[bold yellow]Please add audio files (WAV format) to the directory: {INPUT_DIR}[/bold yellow]")
|
| 38 |
-
input("\nPress Enter to continue...")
|
| 39 |
-
|
| 40 |
-
# Validate Audio Files
|
| 41 |
-
audio_files = [f for f in os.listdir(INPUT_DIR) if f.endswith(".wav")]
|
| 42 |
-
if not audio_files:
|
| 43 |
-
console.print(f"[bold red]Error:[/bold red] No WAV files found in: {INPUT_DIR}", style="red")
|
| 44 |
-
exit(1)
|
| 45 |
-
|
| 46 |
-
# Mocked pipeline for diarization (Replace with actual pipeline initialization)
|
| 47 |
-
def mock_pipeline(file_path):
|
| 48 |
-
"""Mocked diarization function, replace with actual implementation."""
|
| 49 |
-
return [
|
| 50 |
-
{"speaker": "SPEAKER_1", "start": 0.0, "end": 10.0},
|
| 51 |
-
{"speaker": "SPEAKER_2", "start": 10.0, "end": 20.0}
|
| 52 |
-
]
|
| 53 |
-
|
| 54 |
-
# Process Audio Files
|
| 55 |
-
console.print(f"[bold green]Found {len(audio_files)} audio file(s). Starting processing...[/bold green]")
|
| 56 |
-
for index, file_name in enumerate(audio_files, start=1):
|
| 57 |
-
input_path = os.path.join(INPUT_DIR, file_name)
|
| 58 |
-
output_file = os.path.join(OUTPUT_DIR, f"{os.path.splitext(file_name)[0]}.json")
|
| 59 |
-
|
| 60 |
-
console.print(f"Processing: [bold blue]{file_name}[/bold blue] ({index}/{len(audio_files)})")
|
| 61 |
-
|
| 62 |
-
try:
|
| 63 |
-
# Perform diarization (Replace `mock_pipeline` with actual diarization pipeline call)
|
| 64 |
-
diarization_data = mock_pipeline(input_path)
|
| 65 |
-
|
| 66 |
-
# Save output to JSON
|
| 67 |
-
with open(output_file, "w") as f:
|
| 68 |
-
json.dump(diarization_data, f, indent=2)
|
| 69 |
-
|
| 70 |
-
console.print(f"[bold green]Success:[/bold green] Diarization output saved to: {output_file}", style="green")
|
| 71 |
-
except Exception as e:
|
| 72 |
-
console.print(f"[bold red]Error processing {file_name}:[/bold red] {e}", style="red")
|
| 73 |
-
|
| 74 |
-
console.print("[bold green]All files processed successfully.[/bold green]")
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|