added api for ai; got backend working
This commit is contained in:
47
backend/diarization.py
Normal file
47
backend/diarization.py
Normal file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Speaker diarization using pyannote.audio.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add backend to path
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
from services.diarization import diarize_and_label
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python diarization.py <command> [args...]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
command = sys.argv[1]
|
||||
|
||||
try:
|
||||
if command == "diarize_and_label":
|
||||
if len(sys.argv) < 4:
|
||||
print("Usage: python diarization.py diarize_and_label <transcription_result_json> <audio_path> [hf_token] [num_speakers] [use_gpu]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
transcription_result = json.loads(sys.argv[2])
|
||||
audio_path = sys.argv[3]
|
||||
hf_token = sys.argv[4] if len(sys.argv) > 4 else None
|
||||
num_speakers = int(sys.argv[5]) if len(sys.argv) > 5 and sys.argv[5] != "null" else None
|
||||
use_gpu = sys.argv[6].lower() == "true" if len(sys.argv) > 6 else True
|
||||
|
||||
result = diarize_and_label(transcription_result, audio_path, hf_token, num_speakers, use_gpu)
|
||||
print(json.dumps(result))
|
||||
|
||||
else:
|
||||
print(f"Unknown command: {command}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user