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

express做静态网站关于建网站做淘宝联盟

express做静态网站,关于建网站做淘宝联盟,海口网站建设服务,网站备案 国外域名通义万相-文生视频实践 简介 本文主要介绍关于阿里的文生视频的Api的注册和如何使用,详细简介在官网:https://help.aliyun.com/zh/model-studio/text-to-video-api-reference#ecd1180f3c026 注册APIkey 前往阿里的个人中心开通通义灵码服务,没…

通义万相-文生视频实践

简介

本文主要介绍关于阿里的文生视频的Api的注册和如何使用,详细简介在官网:https://help.aliyun.com/zh/model-studio/text-to-video-api-reference#ecd1180f3c026

注册APIkey

前往阿里的个人中心开通通义灵码服务,没有APi的同学可以创建相应key,并且保存好

image-20250716203922434

pom项目中添加依赖

环境说明:

<java.version>17</java.version>
<spring-boot.version>3.4.7</spring-boot.version>
<spring-cloud.version>2024.0.0</spring-cloud.version>

我这里由于本地有SLF4j的依赖冲突,所以移除了slf4j-simple的依赖,如果不冲突可以不移除。

<dependency><groupId>com.alibaba</groupId><artifactId>dashscope-sdk-java</artifactId><version>2.20.7</version><exclusions><!-- 排除 slf4j-simple --><exclusion><groupId>org.slf4j</groupId><artifactId>slf4j-simple</artifactId></exclusion></exclusions>
</dependency>

配置文件


/*** @Description:  阿里的apiKey配置中心* @author: zh* @Create : 2025/7/10* @Project_name : RuoYi-Cloud-Plus* @Version :**/
@Component
public class AiGeneralProperties {@Value("${dashscope.apiKey}")public String apiKey;@Value("${dashscope.model}")public String model;
}

配置资源

dashscope:apiKey: sk-xxxxx##对应模型的版本-这个版本可以支持首图和尾图model: wanx2.1-kf2v-plus

对应的Dto类


import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;import java.io.Serial;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;/*** @Description: 阿里图生视频请求dto* @author: zh* @Create : 2025/7/11* @Project_name : RuoYi-Cloud-Plus* @Version :**/
@Data
@Builder
public class VideoParamDto implements Serializable {@Serialprivate static final long serialVersionUID = 1L;/***  首图*/@NotBlank(message = "首图不能为空")private String firstFrameUrl;/*** 第二张图*/private String lastFrameUrl;/*** prompt提示词*/@NotBlank(message = "prompt不能为空")private String prompt;/*** 视频分辨率*/@Pattern(regexp = "\\d{3,4}\\*\\d{3,4}",message = "分辨率格式错误")private String size = "1280*720";/*** 视频时长*/@Min(1) @Max(10)private String duration = "5";/*** 随机数种子 --- 控制模型生成内容的随机性。取值范围为[0, 2147483647]*/@Min(0) @Max(2147483647)private Long seed;/*** 反向提示词,用来描述不希望在视频画面中看到的内容,可以对视频画面进行限制。*/private String negativePrompt;
}

实现类

/*** @Description: 图片转视频* @author: zh* @Create : 2025/7/10* @Project_name : RuoYi-Cloud-Plus* @Version :**/
@Component
public class PictureToVideoComponent {@Autowiredprivate AiGeneralProperties aiGeneralProperties;private static final VideoSynthesis videoSynthesis = new VideoSynthesis();private static final Map<String, Object> parameters = new HashMap<>();static {parameters.put("prompt_extend", true);}/*** 需要调用方自行实现异步调用图生视频ali大模型* @param dto*/public R<VideoSynthesisOutput> callSync(VideoParamDto dto) {try {if ("".equals(dto.getFirstFrameUrl()) && "".equals(dto.getPrompt())) {return R.fail();}VideoSynthesisParam.VideoSynthesisParamBuilder<?, ?> builder = VideoSynthesisParam.builder().apiKey(aiGeneralProperties.apiKey).model(aiGeneralProperties.model).prompt(dto.getPrompt()).size(dto.getSize()).parameters(parameters);if (dto.getLastFrameUrl() != null && !"".equals(dto.getLastFrameUrl())) {builder.firstFrameUrl(dto.getFirstFrameUrl()).lastFrameUrl(dto.getLastFrameUrl());}else{builder.imgUrl(dto.getFirstFrameUrl());}VideoSynthesisParam param = builder.build();VideoSynthesisResult result = null;result = videoSynthesis.call(param);return R.ok(result.getOutput());} catch (Exception e) {e.printStackTrace();}return R.fail();}
}

测试类

@SpringBootTest(classes = RuoyiAiApplication.class)
@DisplayName("阿里Ai功能测试")
public class test {@ResourcePictureToVideoComponent pictureToVideoComponent;@DisplayName("图片动态视频测试")@Testpublic void testPictureToVideo(){VideoParamDto dto = VideoParamDto.builder().firstFrameUrl("https://typo-img.oss-cn-chengdu.aliyuncs.com/img-localhost/202507162159709.png").lastFrameUrl("https://typo-img.oss-cn-chengdu.aliyuncs.com/img-localhost/202507162200488.jpg").prompt("让男孩跑向女孩").build();System.out.println(pictureToVideoComponent.callSync(dto));}}

测试结果

image-20250716215832948

对应的图片

首图:

尾图:

900684d4768d9ec687c5352feeb161aa_1

生成的视频链接放这里了:
https://dental-zh.oss-cn-chengdu.aliyuncs.com/dev/upload/2025-07-17/6878ef1653f666ad84863693


文章转载自:

http://EszT2jx8.zdzgf.cn
http://CLNC7RTM.zdzgf.cn
http://GCJyPYNh.zdzgf.cn
http://3VTaqguw.zdzgf.cn
http://GOdbyQro.zdzgf.cn
http://NN7QZ8Dj.zdzgf.cn
http://sSMFN6Im.zdzgf.cn
http://tnDLAF6H.zdzgf.cn
http://gyKUzyRQ.zdzgf.cn
http://OC3m27Hn.zdzgf.cn
http://Rbeuryi4.zdzgf.cn
http://3tNyLvIi.zdzgf.cn
http://jDbFhPsZ.zdzgf.cn
http://dvaDd6Yf.zdzgf.cn
http://TsFYvgkn.zdzgf.cn
http://WzRJhZ3n.zdzgf.cn
http://92wIVvW6.zdzgf.cn
http://NxxAg003.zdzgf.cn
http://PoMmPj4k.zdzgf.cn
http://5fYZuiKI.zdzgf.cn
http://Wja7AXAo.zdzgf.cn
http://bQ4OjAsr.zdzgf.cn
http://IvYxyEci.zdzgf.cn
http://Xscvm8nV.zdzgf.cn
http://plCGrswW.zdzgf.cn
http://xn9hjwTJ.zdzgf.cn
http://Wo1Z5JPo.zdzgf.cn
http://C7JJp0T3.zdzgf.cn
http://k2b0TQjn.zdzgf.cn
http://LOCnWlKg.zdzgf.cn
http://www.dtcms.com/wzjs/762488.html

相关文章:

  • wordpress 筛选 文章网站优化怎么做分录
  • 珠海网站建设王道下拉強服装设计公司属于什么行业类型
  • 初期网站开发费会计分录宁波seo教学
  • 个人网站名称 备案建设网站是什么科目
  • 秦皇岛网站制作源码php淘宝商城网站源码
  • wordpress公司展示网站杭州网站如何制作
  • 东莞做网站dgjcwl搜索引擎大全
  • 巩义网站公司广州科 外贸网站建设
  • 车陂网站建设网红营销概念
  • 西峡网站开发24手表网站
  • 做电商网站需要做什么准备新乡网站建设开发
  • 公司网站主页打不开购买一个小程序多少钱
  • 我的网站搜索不到了奢侈品网站建设方案
  • 网站seo查询建设系统网站
  • 网站建设系统 招标网站开发流程表
  • 做静态网站的开题报告企业查天眼查官网
  • 哪里有网站制作多用户商城数据库设计
  • 如何用电脑做网站服务器创意设计网站推荐
  • 滕州网站建设推广帝国cms这么做网站
  • 沧州英文模板建站鲁班设计工作平台
  • 网站推广公司 wordpress网络电话免费版
  • 深圳网站建设 龙华信科黑蜘蛛网站
  • 浏览wap网站制作免费个人网页
  • 网站如何做线上和线下推广南昌做seo的公司有哪些
  • 自适应网站系统吗巩义网站优化公司
  • 东莞市官网网站建设哪家好网站网业设计
  • 如何做网站链接分享朋友圈赣州seo优化
  • 商城类网站建设数据库mp3链接地址制作网站
  • 房产网站模板程序wordpress head文件夹
  • 没有备案的网站使用微信泊头网站优化