文字转语音

This commit is contained in:
spllzh
2025-10-04 19:52:06 +08:00
parent 24c00c22ab
commit 06730b656e
51 changed files with 5157 additions and 8 deletions

View File

@@ -84,6 +84,10 @@ public class AliyunConfig {

View File

@@ -0,0 +1,73 @@
package com.rj.config;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
/**
* MinIO 配置类
*
* @author rj
* @date 2025-10-02
*/
@Data
@Configuration
@ConfigurationProperties(prefix = "minio")
public class MinIOConfig {
/**
* MinIO服务器地址
*/
private String endpoint;
/**
* 访问密钥
*/
private String accessKey;
/**
* 秘密密钥
*/
private String secretKey;
/**
* 默认存储桶名称
*/
private String bucketName;
/**
* 创建MinIO客户端Bean
*/
@Bean
public MinioClient minioClient() {
// 验证必要的配置项
if (!StringUtils.hasText(endpoint)) {
throw new IllegalArgumentException("MinIO endpoint 配置不能为空,请在配置文件中设置 minio.endpoint");
}
if (!StringUtils.hasText(accessKey)) {
throw new IllegalArgumentException("MinIO accessKey 配置不能为空,请在配置文件中设置 minio.access-key");
}
if (!StringUtils.hasText(secretKey)) {
throw new IllegalArgumentException("MinIO secretKey 配置不能为空,请在配置文件中设置 minio.secret-key");
}
if (!StringUtils.hasText(bucketName)) {
throw new IllegalArgumentException("MinIO bucketName 配置不能为空,请在配置文件中设置 minio.bucket-name");
}
return MinioClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey)
.build();
}
/**
* 获取文件访问URL前缀
*/
public String getFileUrlPrefix() {
return endpoint + "/" + bucketName + "/";
}
}

View File

@@ -0,0 +1,48 @@
package com.rj.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* RestTemplate 配置类
*
* @author rj
* @date 2025-01-02
*/
@Configuration
public class RestTemplateConfig {
/**
* 创建RestTemplate Bean
* 支持音频流响应处理
*
* @return RestTemplate实例
*/
@Bean
public RestTemplate restTemplate() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(30000); // 连接超时30秒
factory.setReadTimeout(60000); // 读取超时60秒
RestTemplate restTemplate = new RestTemplate(factory);
// 添加支持音频流的HttpMessageConverter
ByteArrayHttpMessageConverter audioConverter = new ByteArrayHttpMessageConverter();
audioConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.valueOf("audio/mpeg")));
List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters =
new ArrayList<>(restTemplate.getMessageConverters());
messageConverters.add(audioConverter);
restTemplate.setMessageConverters(messageConverters);
return restTemplate;
}
}

View File

@@ -0,0 +1,43 @@
package com.rj.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* SiliconFlow API 配置类
*
* @author rj
* @date 2025-01-02
*/
@Data
@Configuration
@ConfigurationProperties(prefix = "siliconflow")
public class SiliconFlowConfig {
/**
* SiliconFlow API 基础URL
*/
private String baseUrl = "https://api.siliconflow.cn/v1";
/**
* API Token
*/
private String apiKey;
/**
* 默认TTS模型 免费模型: MOSS-TTSD-v0.5
*/
// private String defaultTtsModel = "fnlp/MOSS-TTSD-v0.5";
private String defaultTtsModel = "FunAudioLLM/CosyVoice2-0.5B";
/**
* 请求超时时间(毫秒)
*/
private int timeout = 30000;
/**
* 是否启用SiliconFlow服务
*/
private boolean enabled = true;
}