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

【大模型文生图、文生音频实战Demo】基于Spring AI Alibaba和阿里百炼大模型实现文生图、文生视频

文章目录

  • 大模型实现文生图
  • 大模型实现文生音频

大模型实现文生图

使用阿里百炼大模型-wanx2.1-t2i-turbo,作为文生图调用的大模型

  • 代码
@RestController
public class ImageModelController {private final ImageModel imageModel;ImageModelController(@Qualifier("dashScopeImageModel") ImageModel imageModel) {this.imageModel = imageModel;}@RequestMapping("/image")public String image(String input) {ImageOptions options = ImageOptionsBuilder.builder().model("wanx2.1-t2i-turbo").height(1024).width(1024).build();ImagePrompt imagePrompt = new ImagePrompt(input, options);ImageResponse response = imageModel.call(imagePrompt);String imageUrl = response.getResult().getOutput().getUrl();return "redirect:" + imageUrl;}
}

model指定模型,再指定生成图片的宽高

  • postman调用接口
    在这里插入图片描述
    点击链接打开,下载图片可查看
    在这里插入图片描述

雨西湖,雷峰塔哈哈哈有品位

大模型实现文生音频

  • 代码
@RestController
@RequestMapping("/audio")
public class AudioModelController {private final SpeechSynthesisModel speechSynthesisModel;@Autowiredpublic AudioModelController(SpeechSynthesisModel speechSynthesisModel) {this.speechSynthesisModel = speechSynthesisModel;}@GetMapping("/synthesize")public ResponseEntity<byte[]> synthesizeSpeech(@RequestParam String text) throws IOException {// 构建语音合成请求SpeechSynthesisPrompt prompt = new SpeechSynthesisPrompt(text);// 调用模型生成语音SpeechSynthesisResponse response = speechSynthesisModel.call(prompt);ByteBuffer audioData = response.getResult().getOutput().getAudio();// 将 ByteBuffer 转换为字节数组byte[] audioBytes = new byte[audioData.remaining()];audioData.get(audioBytes);// 返回音频流(MP3格式)return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", "attachment; filename=output.mp3").body(audioBytes);}}
  • 网页访问调用

http://localhost:8080/audio/synthesize?text=你好

下载后可以得到对应文本的音频

以上,完成了用Spring AI Alibaba和调用各类大模型的方式,实现了文生图和文生音频!

http://www.dtcms.com/a/294615.html

相关文章:

  • LeetCode 407:接雨水 II
  • 网络编程初识(详细易懂)
  • [强网杯 2019]高明的黑客
  • iOS加固工具有哪些?企业级团队协作视角的实战分析
  • 【浏览器插件冲突】Edge浏览器加载不出来CSDN创作者中心
  • SpringBoot07-数据层的解决方案:SQL
  • 【科研绘图系列】R语言绘制黑白填充等显著性标记条形图
  • 华为仓颉编程语言实践体验
  • 基于Springboot的中药商城管理系统/基于javaweb的中药材销售系统
  • 海外短剧系统开发:技术架构与市场机遇深度解析
  • 华为7月23日机考真题
  • 华为高频算法题:最长连续递增子序列(Longest Continuous Increasing Subsequence)
  • 【JVM】从 JVM 整体说明 JVM 运行的完整流程
  • Redis MCP 安装与配置完整指南
  • 83、设置有人DTU设备USR-M100采集传感器数据,然后上传阿里云服务
  • 卷积神经网络:模型评估标准
  • Qt容器类:QList、QMap等的高效使用
  • 2025年7月份实时最新获取地图边界数据方法,省市区县街道多级联动【文末附实时geoJson数据下载】
  • 闲庭信步使用图像验证平台加速FPGA的开发:第三十一课——车牌识别的FPGA实现(3)车牌字符分割预处理
  • 从零开始学习Dify-Excel数据可视化(四)
  • PHP面向对象高级应用:依赖注入、服务容器与PSR标准实现
  • STL学习(四、队列和堆栈)
  • CSP-J系列【2023】P9751 [CSP-J 2023] 旅游巴士题解
  • 变频器实习DAY12
  • 接入海康设备mark全是false解决方案
  • Elasticsearch整合:Repository+RestClient双模式查询优化
  • 【杂谈】-代理协议:重塑AI协作新生态,开启智能互联新时代
  • 开闭原则在C++中的实现
  • InfluxDB HTTP API 接口调用详解(二)
  • [HarmonyOS] 鸿蒙LiteOS-A内核深度解析 —— 面向 IoT 与智能终端的“小而强大”内核