目录
nvidia-ace 安装:
audio2face发消息:
nvidia-ace 安装:
pip install nvidia-ace报错:
File "D:\projcect\audio2face\Audio2Face-3D-Samples-main\a2f_3d\client\service.py", line 19, in <module>
from nvidia_ace.animation_data.v1_pb2 import AnimationData, AnimationDataStreamHeader
ModuleNotFoundError: No module named 'nvidia_ace.animation_data'
audio2face发消息:
import asyncio import json import a2f_3d.client.auth import a2f_3d.client.service from nvidia_ace.services.a2f_controller.v1_pb2_grpc import A2FControllerServiceStub # ===================== 配置 ===================== A2F_GRPC_ADDR = "127.0.0.1:52000" # gRPC 服务器地址 CONFIG_FILE = "config.yaml" # Audio2Face 部署配置文件 AUDIO_FILE = r"D:\data\audios\post_res1.wav" # 输入音频 OUTPUT_JSON = r"output.json" # 输出 JSON 文件 # ===================== 主程序 ===================== async def process_audio_to_json(): # 创建 gRPC channel channel = a2f_3d.client.auth.create_channel(uri=A2F_GRPC_ADDR, use_ssl=False) stub = A2FControllerServiceStub(channel) # 创建双向流 stream = stub.ProcessAudioStream() frames = [] # 异步读取输出流 async def read_stream(): async for msg in stream: anim = msg.animation_data skel = anim.skel_animation bs_names = msg.animation_data_stream_header.skel_animation_header.blend_shapes frame = { "timeCode": getattr(anim, "time_code", None), "blendShapes": dict(zip(bs_names, skel.blend_shape_weights)), "pose": { "translation": list(skel.translations), "rotation": list(skel.rotations) } } frames.append(frame) # 写入音频并关闭写入 await a2f_3d.client.service.write_to_stream(stream, CONFIG_FILE, AUDIO_FILE) # 等待读取完成 await read_stream() # 保存 JSON with open(OUTPUT_JSON, "w", encoding="utf-8") as f: json.dump(frames, f, indent=2, ensure_ascii=False) print(f"输出已保存到 {OUTPUT_JSON}, 总帧数: {len(frames)}") # ===================== 运行 ===================== if __name__ == "__main__": asyncio.run(process_audio_to_json())