|
最新快照版本请使用Spring AI 1.1.0! |
Azure OpenAI 转录
Spring AI 支持 Azure Whisper 模型。
前提条件
获取你的Azure OpenAI端点和API密钥来自Azure Portal的Azure OpenAI服务部分。
Spring AI 定义了一个名为Spring.ai.Azure.Openai.API-Key你应该设置为API 密钥摘自Azure。
还有一个配置属性,名为Spring.ai.azure.openai.endpoint你应该设置为在Azure中配置模型时获得的端点URL。
导出环境变量是设置该配置属性的一种方式:
自动配置
|
春季AI自动配置、起始模块的工件名称发生了重大变化。 更多信息请参阅升级说明。 |
Spring AI 为 Azure OpenAI 转录生成客户端提供 Spring Boot 自动配置。
要启用它,请在项目的 Maven 中添加以下依赖pom.xml文件:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-azure-openai</artifactId>
</dependency>
或者去你的Gradlebuild.gradle构建文件。
dependencies {
implementation 'org.springframework.ai:spring-ai-starter-model-azure-openai'
}
| 请参考依赖管理部分,将Spring AI的物料清单添加到你的构建文件中。 |
转录性质
|
现在,启用和禁用音频转录自动配置通过顶层属性配置,并以 启用时,spring.ai.model.audio.transcription=azure-openai(默认启用) 要禁用,可以选择 spring.ai.model.audio.transcription=none(或任何与 azure-openai 不匹配的值) 此改动旨在允许配置多个模型。 |
前缀spring.ai.openai.audio.transcription作为属性前缀,允许你配置OpenAI图像模型的重试机制。
| 属性 | 描述 | 默认值 |
|---|---|---|
spring.ai.azure.openai.audio.transcription.enabled(已移除且不再有效) |
Enable Azure OpenAI transcription model. |
true |
spring.ai.model.audio.transcription |
Enable Azure OpenAI transcription model. |
azure-openai |
Spring.ai.azure.openai.audio.transcription.options.model |
型号的识别码。目前只有 Whisper 可以购买。 |
耳语 |
Spring.ai.azure.openai.audio.transcription.options.deployment-name |
模型部署时的部署名称。 |
|
Spring.ai.azure.openai.audio.transcription.options.response-format |
转录输出格式,以下选项之一:json、文本、srt、verbose_json或vtt。 |
JSON |
Spring.ai.azure.openai.audio.transcription.options.prompt |
可选文本,用于指导模型风格或延续之前的音频片段。提示应与音频语言相匹配。 |
|
Spring.ai.azure.openai.audio.transcription.options.language |
输入音频的语言。以 ISO-639-1 格式提供输入语言将提升准确性和延迟。 |
|
Spring.ai.azure.openai.audio.transcription.options.temperature. |
采样温度在0到1之间。像0.8这样的高值会让输出更随机,而像0.2这样的低值则会让输出更聚焦和确定性强。如果设置为0,模型会利用对数概率自动升高温度,直到达到某些阈值。 |
0 |
Spring.ai.azure.openai.audio.transcription.options.timestamp-granularities |
本次转录的时间戳细粒度。response_format必须设置为verbose_json使用时间戳的粒度。支持以下选项之一或两种:单词或片段。注意:段时间戳不会有额外延迟,但生成字时间戳会产生额外的延迟。 |
段 |
运行时选项
这AzureOpenAiAudioTranscriptionOptions课程提供了转录时可用的选项。
启动时,指定选项如下spring.ai.azure.openai.audio.transcription但你可以在运行时覆盖这些设置。
例如:
AzureOpenAiAudioTranscriptionOptions.TranscriptResponseFormat responseFormat = AzureOpenAiAudioTranscriptionOptions.TranscriptResponseFormat.VTT;
AzureOpenAiAudioTranscriptionOptions transcriptionOptions = AzureOpenAiAudioTranscriptionOptions.builder()
.language("en")
.prompt("Ask not this, but ask that")
.temperature(0f)
.responseFormat(this.responseFormat)
.build();
AudioTranscriptionPrompt transcriptionRequest = new AudioTranscriptionPrompt(audioFile, this.transcriptionOptions);
AudioTranscriptionResponse response = azureOpenAiTranscriptionModel.call(this.transcriptionRequest);
手动配置
添加春艾开胃对你项目Maven的依赖pom.xml文件:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-azure-openai</artifactId>
</dependency>
或者去你的Gradlebuild.gradle构建文件。
dependencies {
implementation 'org.springframework.ai:spring-ai-azure-openai'
}
| 请参考依赖管理部分,将Spring AI的物料清单添加到你的构建文件中。 |
接下来,创建一个AzureOpenAiAudioTranscriptionModel
var openAIClient = new OpenAIClientBuilder()
.credential(new AzureKeyCredential(System.getenv("AZURE_OPENAI_API_KEY")))
.endpoint(System.getenv("AZURE_OPENAI_ENDPOINT"))
.buildClient();
var azureOpenAiAudioTranscriptionModel = new AzureOpenAiAudioTranscriptionModel(this.openAIClient, null);
var transcriptionOptions = AzureOpenAiAudioTranscriptionOptions.builder()
.responseFormat(TranscriptResponseFormat.TEXT)
.temperature(0f)
.build();
var audioFile = new FileSystemResource("/path/to/your/resource/speech/jfk.flac");
AudioTranscriptionPrompt transcriptionRequest = new AudioTranscriptionPrompt(this.audioFile, this.transcriptionOptions);
AudioTranscriptionResponse response = this.azureOpenAiAudioTranscriptionModel.call(this.transcriptionRequest);