当前位置: 首页 > news >正文

【网页端数字人开发】基于模型SAiD实现嘴型同步

一、项目介绍

SAiD是一种基于扩散模型的语音嘴型同步方法,通过一段语音就可以生成包含32个blendshape参数的数据,通过制作对应的数字人面部blendshape进行映射,能够实现嘴型同步功能。
效果展示:

SAiD嘴型同步效果

模型框架图为:
在这里插入图片描述
输出的blendshape列表为:
在这里插入图片描述

二、项目部署

1.下载项目

项目链接:https://github.com/yunik1004/SAiD

2.创建环境及安装需要的库

(1)安装依赖的库

在这里插入图片描述

(2)成功安装

在这里插入图片描述

3.判断cuda是否安装成功

(1)没有成功安装cuda,大概率是版本不对,查询自己电脑所适配的cuda版本,重新安装

安装失败
在这里插入图片描述
卸载当前的cuda版本
在这里插入图片描述
查询自己电脑所适配的cuda版本,尽量越接近越好
在这里插入图片描述
到官网选择适合自己电脑的cuda版本,并复制下载网址,官网:https://pytorch.org/get-started/locally/
在这里插入图片描述
进行cuda安装
在这里插入图片描述
安装成功
在这里插入图片描述
能够正常调用cuda
在这里插入图片描述

4.下载好预训练的模型,并放在合适的位置

模型下载地址:https://huggingface.co/yunik1004/SAiD
在这里插入图片描述

5.进行blendshape数据生成

在这里插入图片描述
生成的数据最好不要低于60帧,低于60帧嘴型同步效果不好
在这里插入图片描述
开始运行,运行失败,出现问题
在这里插入图片描述

6.解决ImportError: cannot import name ‘cached_download’ from ‘huggingface_hub’ (D:\anaconda3\envs\said1\lib\site-packages\huggingface_hub_init_.py)

原因:在huggingface_hub 0.26 中移除了该函数
解决方法:将huggingface_hub版本回退到0.25.2
在这里插入图片描述

7.重新进行生成

仍存在问题
在这里插入图片描述

8.解决ImportError: cannot import name ‘metric’ from partially initialized module ‘said’ (most likely due to a circular import) (D:\anaconda3\envs\said1\lib\site-packages\said_init_.py)

问题:在模块导入过程中发生了循环依赖或者模块初始化过程中的某些问题
解决方法:将一整个said文件夹复制一份到script文件夹中
在这里插入图片描述

9.继续生成

成功生成
在这里插入图片描述
查看生成的数据
在这里插入图片描述

三、API调用

1.基于Flask实现api调用

封装方法,实现接口调用

import argparse
import os
from diffusers import DDIMScheduler
import torch
import numpy as np
from said.model.diffusion import SAID_UNet1D
from said.util.audio import fit_audio_unet, load_audio
from said.util.blendshape import (load_blendshape_coeffs,save_blendshape_coeffs,save_blendshape_coeffs_image,
)
from dataset.dataset_voca import BlendVOCADatasetdef infer_blendshape_from_audio(audio_path: str,weights_path: str = r"D:\G\AIAgentHub\文档\技术方案文档\网页端数字人\project\SAiD-main\script\ModelWeight\SAiD.pth",output_path: str = r"D:\G\AIAgentHub\文档\技术方案文档\网页端数字人\project\SAiD-main\script\Output\test_ch.csv",device: str = "cuda:0",fps: int = 60,num_steps: int = 1000,strength: float = 1.0,guidance_scale: float = 2.0,guidance_rescale: float = 0.0,eta: float = 0.0,prediction_type: str = "epsilon",divisor_unet: int = 1,unet_feature_dim: int = -1,init_sample_path: str = None,mask_path: str = None,save_intermediate: bool = False,intermediate_dir: str = "./interm",save_image: bool = False,output_image_path: str = "./out.png",
) -> np.ndarray:"""从音频中推理生成 blendshape 数据"""# 加载初始样本和 maskinit_samples = (load_blendshape_coeffs(init_sample_path).unsqueeze(0).to(device)if init_sample_path else None)mask = (load_blendshape_coeffs(mask_path).unsqueeze(0).to(device)if mask_path else None)# 加载模型said_model = SAID_UNet1D(noise_scheduler=DDIMScheduler,feature_dim=unet_feature_dim,prediction_type=prediction_type,)said_model.load_state_dict(torch.load(weights_path, map_location=device))said_model.to(device)said_model.eval()# 加载并预处理音频waveform = load_audio(audio_path, said_model.sampling_rate)fit_output = fit_audio_unet(waveform, said_model.sampling_rate, fps, divisor_unet)waveform = fit_output.waveformwindow_len = fit_output.window_sizewaveform_processed = said_model.process_audio(waveform).to(device)# 模型推理with torch.no_grad():output = said_model.inference(waveform_processed=waveform_processed,init_samples=init_samples,mask=mask,num_inference_steps=num_steps,strength=strength,guidance_scale=guidance_scale,guidance_rescale=guidance_rescale,eta=eta,save_intermediate=save_intermediate,show_process=True,)# 获取结果result = output.result[0, :window_len].cpu().numpy()save_blendshape_coeffs(coeffs=result,classes=BlendVOCADataset.default_blendshape_classes,output_path=output_path,)return resultfrom flask import Flask, request, jsonify
from flask_cors import CORS  # ✅ 添加这行
import tempfile
import os
import script.MyInference  # 你自己的推理模块app = Flask(__name__)
CORS(app)  # ✅ 允许所有来源跨域访问
# 或者更安全的写法:CORS(app, origins=["http://localhost:5173"])@app.route('/audio2bs', methods=['POST'])
def audio2bs():if 'audio' not in request.files:return jsonify({"error": "No audio file uploaded"}), 400audio_file = request.files['audio']print("收到请求:", audio_file.filename)# 临时保存上传的文件with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:audio_file.save(tmp)tmp_path = tmp.nametry:# 执行推理result = script.MyInference.infer_blendshape_from_audio(tmp_path)print(result)# 转为 list 以便 jsonifyblendshape_data = result.tolist()return jsonify({"blendshape": blendshape_data})except Exception as e:return jsonify({"error": str(e)}), 500finally:os.remove(tmp_path)if __name__ == '__main__':# 默认监听 5000 端口,可改为 host='0.0.0.0' 供局域网访问app.run(debug=True, port=5000)

存放路径
在这里插入图片描述

http://www.xdnf.cn/news/913753.html

相关文章:

  • 三模冗余设计
  • 书籍推荐 --- 《筚路维艰:中国经济社会主义路径的五次选择》
  • 瑞它鲁肽 Retatrutide
  • Delphi 实现远程连接 Access 数据库的指南
  • 为什么HDI叠孔比错孔设计难生产
  • 调试时两个can盒子互连实现在一台电脑上自发自收的接线
  • Pytorch安装后 如何快速查看经典的网络模型.py文件(例如Alexnet,VGG)(已解决)
  • WiFi通信应用开发【保姆级】+配置ESP8266芯片的WiFi station和soft-AP + station工作模式!!!
  • 算力时代的四大引擎:CPU、GPU、NPU、DPU 深度解析
  • Vue3 + threeJs 定义六种banner轮播图切换动画效果:百叶窗、手风琴、拼图、渐变、菱形波次、圆形扩展
  • 如何利用 Redis 实现跨多个无状态服务实例的会话共享?
  • 讲解:Java I/O 流体系,并举例每个类的使用
  • 【YOLOs-CPP-图像分类部署】05-OpenVino加速
  • URL 带有 /../ 导致可以访问其他目录--路径穿越问题
  • SON.stringify()和JSON.parse()之间的转换
  • 优化电脑的磁盘和驱动器提高电脑性能和延长硬盘寿命?
  • Unity3D仿星露谷物语开发60之定制角色其他部位
  • Jpackage
  • 信号电压高,传输稳定性变强,但是传输速率下降?
  • Window Server 2019--11 虚拟专用网络
  • 软件测试python学习
  • 第十届电子技术和信息科学国际学术会议(ICETIS 2025)
  • 如何选择正确的团队交互模式:协作、服务还是促进?
  • 【普及+/提高】洛谷P2114 ——[NOI2014] 起床困难综合症
  • 耦合和内聚
  • BECKHOFF(倍福)PLC --北尔HMI ADS Symbolc 通讯
  • 电动螺丝刀-多实体拆图建模案例
  • 全球数控金属切削机床市场:现状、趋势与应对策略
  • # 从底层架构到应用实践:为何部分大模型在越狱攻击下失守?
  • 2025/6/6—halcon知识点总结