init
This commit is contained in:
40
services/a2f_api/a2f_service.py
Normal file
40
services/a2f_api/a2f_service.py
Normal file
@ -0,0 +1,40 @@
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
import glob
|
||||
|
||||
class A2FService:
|
||||
def __init__(self, a2f_url="192.168.1.39:52000"):
|
||||
self.base_dir = Path(__file__).parent.parent.parent
|
||||
self.output_dir = self.base_dir / "data" / "output"
|
||||
self.a2f_script = self.base_dir / "external" / "Audio2Face-3D-Samples" / "scripts" / "audio2face_3d_microservices_interaction_app" / "a2f_3d.py"
|
||||
self.config_file = self.base_dir / "external" / "Audio2Face-3D-Samples" / "scripts" / "audio2face_3d_microservices_interaction_app" / "config" / "config_james.yml"
|
||||
self.a2f_url = a2f_url
|
||||
os.makedirs(self.output_dir, exist_ok=True)
|
||||
|
||||
def audio_to_csv(self, audio_path: str) -> str:
|
||||
cmd = [
|
||||
sys.executable,
|
||||
str(self.a2f_script),
|
||||
"run_inference",
|
||||
audio_path,
|
||||
str(self.config_file),
|
||||
"--url",
|
||||
self.a2f_url
|
||||
]
|
||||
|
||||
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, cwd=str(self.output_dir))
|
||||
|
||||
if result.returncode != 0:
|
||||
raise RuntimeError(f"A2F inference failed: {result.stdout}")
|
||||
|
||||
output_dirs = sorted(glob.glob(str(self.output_dir / "output_*")))
|
||||
if not output_dirs:
|
||||
raise RuntimeError("No output directory found")
|
||||
|
||||
csv_path = os.path.join(output_dirs[-1], "animation_frames.csv")
|
||||
if not os.path.exists(csv_path):
|
||||
raise RuntimeError(f"CSV file not found: {csv_path}")
|
||||
|
||||
return csv_path
|
||||
Reference in New Issue
Block a user