当前位置: 首页 > 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.lryc.cn/news/597195.html

相关文章:

  • Android MediaCodec 的使用和源码实现分析
  • 2.1 为什么定义tensor数据结构?
  • 【有趣的跳跃一维数组问题】2022-7-27
  • 彻底掌握双列集合——Map接口以及实现类和常用API及其底层原理
  • 题解:P9468 [EGOI 2023] Candy / 糖果
  • 亚马逊云科技 上海AI研究院 突然解散 | AI早报
  • Taint Bug (污点漏洞):
  • GitHub 趋势日报 (2025年07月22日)
  • Docker 基础概念
  • 解决Node 17+版本与Metro、Webpack等兼容性问题(500)
  • 数据结构自学Day13 -- 快速排序--“分而治之”
  • ITIL 4:云计算与微服务对组织架构的影响
  • kotlin基础【1】
  • android studio(NewsApiDemo)100%kotlin
  • 【前端】当前主流的 CSS 预处理器语言Sass / SCSS、Less、Stylus
  • kotlin基础【2】
  • BaaS平台(Supabase)
  • 数据结构自学Day13 -- 快速排序--“前后指针法”
  • 《计算机网络》实验报告六 电子邮件
  • 数据结构(2)顺序表算法题
  • 【数据结构】二叉树的链式结构--用C语言实现
  • 数据结构系列之AVL树
  • Java冒泡排序的不同实现
  • Excel自动分列开票工具推荐
  • 耐达讯自动化EtherCAT转RS232:示波器连接的“开挂秘籍”
  • IDEA如何管理多个Java版本。
  • 图机器学习(16)——图数据与自然语言处理
  • 使用idea 将一个git分支的部分记录合并到git另一个分支
  • idea部署新项目时,用自定义的maven出现的问题解决
  • 【网络编程】二、socket编程