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

54_Spring AI 干货笔记之 Azure OpenAI 语音转录

一、Azure OpenAI 语音转录

Spring AI 支持 Azure Whisper 模型。

二、前置条件

从 Azure 门户的 Azure OpenAI 服务部分获取您的 Azure OpenAI 端点和 API 密钥。Spring AI 定义了一个名为 spring.ai.azure.openai.api-key 的配置属性,您应将其设置为从 Azure 获取的 API 密钥值。同时还有一个名为 spring.ai.azure.openai.endpoint 的配置属性,应设置为在 Azure 中部署模型时获取的端点 URL。

三、自动配置

Spring AI 的自动配置及其 Starter 模块的构件名称发生了显著变化。更多信息请参阅升级说明。

Spring AI 为 Azure OpenAI 语音转录生成客户端提供了 Spring Boot 自动配置。要启用它,请将以下依赖项添加到项目的 Maven pom.xml 文件中:

<dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-model-azure-openai</artifactId></dependency>

或者添加到您的 Gradle build.gradle 构建文件中。

dependencies{implementation'org.springframework.ai:spring-ai-starter-model-azure-openai'}

请参考“依赖管理”部分,将 Spring AI BOM 添加到您的构建文件中。

转录属性

现在通过顶级属性 spring.ai.model.audio.transcription 来启用或禁用音频转录的自动配置。

  • 要启用:spring.ai.model.audio.transcription=azure-openai (默认已启用)

  • 要禁用:spring.ai.model.audio.transcription=none (或任何非 azure-openai 的值)

此项变更是为了支持配置多个模型。

前缀 spring.ai.openai.audio.transcription 用作属性前缀,用于配置 OpenAI 图像模型的重试机制。

四、运行时选项

AzureOpenAiAudioTranscriptionOptions 类提供了进行转录时使用的选项。在启动时,会使用 spring.ai.azure.openai.audio.transcription 指定的选项,但您可以在运行时覆盖这些选项。

例如:

AzureOpenAiAudioTranscriptionOptions.TranscriptResponseFormatresponseFormat=AzureOpenAiAudioTranscriptionOptions.TranscriptResponseFormat.VTT;AzureOpenAiAudioTranscriptionOptionstranscriptionOptions=AzureOpenAiAudioTranscriptionOptions.builder().language("en").prompt("Ask not this, but ask that").temperature(0f).responseFormat(this.responseFormat).build();AudioTranscriptionPrompttranscriptionRequest=newAudioTranscriptionPrompt(audioFile,this.transcriptionOptions);AudioTranscriptionResponseresponse=azureOpenAiTranscriptionModel.call(this.transcriptionRequest);

五、手动配置

将 spring-ai-openai 依赖项添加到项目的 Maven pom.xml 文件中:

<dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-azure-openai</artifactId></dependency>

或者添加到您的 Gradle build.gradle 构建文件中。

dependencies{implementation'org.springframework.ai:spring-ai-azure-openai'}

请参考“依赖管理”部分,将 Spring AI BOM 添加到您的构建文件中。

接下来,创建一个 AzureOpenAiAudioTranscriptionModel

varopenAIClient=newOpenAIClientBuilder().credential(newAzureKeyCredential(System.getenv("AZURE_OPENAI_API_KEY"))).endpoint(System.getenv("AZURE_OPENAI_ENDPOINT")).buildClient();varazureOpenAiAudioTranscriptionModel=newAzureOpenAiAudioTranscriptionModel(this.openAIClient,null);vartranscriptionOptions=AzureOpenAiAudioTranscriptionOptions.builder().responseFormat(TranscriptResponseFormat.TEXT).temperature(0f).build();varaudioFile=newFileSystemResource("/path/to/your/resource/speech/jfk.flac");AudioTranscriptionPrompttranscriptionRequest=newAudioTranscriptionPrompt(this.audioFile,this.transcriptionOptions);AudioTranscriptionResponseresponse=this.azureOpenAiAudioTranscriptionModel.call(this.transcriptionRequest);
http://www.jsqmd.com/news/155603/

相关文章:

  • 基于YOLO的智能安防系统搭建:从模型拉取到GPU部署全流程
  • YOLO训练数据自动清洗:用GPU加速异常样本剔除
  • YOLO模型训练资源抢占检测:识别异常占用行为
  • YOLO目标检测可视化工具推荐:Feature Map怎么看?
  • YOLO目标检测项目成本控制:如何合理分配GPU与Token?
  • YOLO目标检测模型训练时如何防止过拟合?Dropout与GPU正则化
  • YOLO推理服务部署HTTPS:保护GPU接口安全
  • YOLO目标检测结果不稳定?可能是GPU浮点精度问题
  • YOLO如何应对恶劣天气下的检测挑战?
  • Win10系统VS2019+Cmake+vtk_8.2.0环境配置
  • YOLO目标检测模型热更新机制设计:不停机升级
  • VTK源码编译时候选qt5路径
  • YOLO模型支持ONNX Runtime-GPU加速推理
  • YOLOv10相比YOLOv8有哪些核心改进?一文说清
  • 基于Vector工具链的AUTOSAR架构配置深度剖析
  • YOLO目标检测支持ZeroMQ高性能网络通信
  • YOLOv8-DFL分布焦点损失详解:提升边界框精度
  • Keil uVision5中低功耗模式在工控设备的应用:通俗解释
  • YOLO模型支持Heartbeat心跳检测机制
  • YOLO目标检测评估数据集推荐:COCO、Pascal VOC
  • YOLOv10新增无锚框设计,带来哪些算力结构变化?
  • YOLO训练Batch Size选择:过大导致GPU显存溢出
  • YOLO实时检测延迟优化:GPU核心频率调优实战
  • YOLO模型灰盒监控告警:设定阈值触发通知机制
  • 散文阅读之分析结构思路
  • YOLO训练样本不平衡?使用GPU加速过采样策略
  • 学长亲荐9个AI论文平台,MBA论文写作不再难!
  • YOLO部署上云后,如何监控GPU利用率和Token消耗?
  • YOLO如何优化Anchor设计?最新版本改进分析
  • YOLO模型微调指南:迁移学习让效果立竿见影