52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
import requests
|
|
import time
|
|
import argparse
|
|
import multiprocessing
|
|
import sys
|
|
|
|
INGEST_URL = "https://emiapi.reynafamily.com/live-captions/ingest"
|
|
|
|
def run_distribution(in_queue, args):
|
|
print("[Distribute] Starting distribution service...")
|
|
|
|
while True:
|
|
try:
|
|
payload = in_queue.get()
|
|
if payload is None: break
|
|
|
|
# Draft support
|
|
if "draft" in payload:
|
|
draft_text = payload["draft"]
|
|
sys.stdout.write(f"\r\033[K[DRAFT]: {draft_text}")
|
|
sys.stdout.flush()
|
|
if args.ingest:
|
|
requests.post(INGEST_URL, json={"draft": draft_text}, timeout=2)
|
|
continue
|
|
|
|
# Finalized segment
|
|
print(f"\n[Final]: {payload.get('original', '')}")
|
|
for lang in ["es", "fr", "ar", "en"]:
|
|
if payload.get(lang):
|
|
print(f"[{lang.upper()}]: {payload[lang]}")
|
|
|
|
if args.ingest:
|
|
delay, max_delay, success = 1, 15, False
|
|
while not success:
|
|
try:
|
|
response = requests.post(INGEST_URL, json=payload, timeout=5)
|
|
if response.status_code == 200: success = True
|
|
else: print(f"[Distribute Error] {response.status_code}. Retrying...")
|
|
except Exception as e:
|
|
print(f"[Distribute Error] {e}. Retrying...")
|
|
|
|
if not success:
|
|
time.sleep(delay)
|
|
delay = min(delay * 2, max_delay)
|
|
|
|
except Exception as e:
|
|
print(f"[Distribute] Error: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
import multiprocessing
|
|
run_distribution(multiprocessing.Queue(), argparse.Namespace())
|