| @@ -1,61 +1,61 @@ | |||||
| package com.iformall.config; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.context.annotation.Bean; | |||||
| import org.springframework.context.annotation.Configuration; | |||||
| import springfox.documentation.builders.ApiInfoBuilder; | |||||
| import springfox.documentation.builders.ParameterBuilder; | |||||
| import springfox.documentation.builders.PathSelectors; | |||||
| import springfox.documentation.builders.RequestHandlerSelectors; | |||||
| import springfox.documentation.schema.ModelRef; | |||||
| import springfox.documentation.service.ApiInfo; | |||||
| import springfox.documentation.service.Parameter; | |||||
| import springfox.documentation.spi.DocumentationType; | |||||
| import springfox.documentation.spring.web.paths.RelativePathProvider; | |||||
| import springfox.documentation.spring.web.plugins.Docket; | |||||
| import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||||
| import javax.servlet.ServletContext; | |||||
| import java.util.ArrayList; | |||||
| import java.util.List; | |||||
| //参考:http://blog.csdn.net/catoop/article/details/50668896 | |||||
| @Configuration | |||||
| @EnableSwagger2 | |||||
| public class Swagger2Config { | |||||
| @Autowired | |||||
| private ServletContext servletContext; | |||||
| @Bean | |||||
| public Docket createRestApi() { | |||||
| ParameterBuilder tokenPar = new ParameterBuilder(); | |||||
| List<Parameter> pars = new ArrayList<Parameter>(); | |||||
| //增加一个request的header参数 | |||||
| tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); | |||||
| pars.add(tokenPar.build()); | |||||
| return new Docket(DocumentationType.SWAGGER_2) | |||||
| .apiInfo(apiInfo()) | |||||
| .select() | |||||
| .apis(RequestHandlerSelectors.basePackage("com.iformall.controller")) | |||||
| .paths(PathSelectors.any()) | |||||
| .build() | |||||
| .globalOperationParameters(pars) | |||||
| .pathProvider(new RelativePathProvider(servletContext) { | |||||
| @Override | |||||
| public String getApplicationBasePath() { | |||||
| return "/api"; | |||||
| } | |||||
| }); | |||||
| } | |||||
| private ApiInfo apiInfo() { | |||||
| return new ApiInfoBuilder() | |||||
| .title("c端 api") | |||||
| .description("c api") | |||||
| .termsOfServiceUrl("http://localhost:7000") | |||||
| .version("2.0") | |||||
| .build(); | |||||
| } | |||||
| } | |||||
| //package com.iformall.config; | |||||
| // | |||||
| //import org.springframework.beans.factory.annotation.Autowired; | |||||
| //import org.springframework.context.annotation.Bean; | |||||
| //import org.springframework.context.annotation.Configuration; | |||||
| //import springfox.documentation.builders.ApiInfoBuilder; | |||||
| //import springfox.documentation.builders.ParameterBuilder; | |||||
| //import springfox.documentation.builders.PathSelectors; | |||||
| //import springfox.documentation.builders.RequestHandlerSelectors; | |||||
| //import springfox.documentation.schema.ModelRef; | |||||
| //import springfox.documentation.service.ApiInfo; | |||||
| //import springfox.documentation.service.Parameter; | |||||
| //import springfox.documentation.spi.DocumentationType; | |||||
| //import springfox.documentation.spring.web.paths.RelativePathProvider; | |||||
| //import springfox.documentation.spring.web.plugins.Docket; | |||||
| //import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||||
| // | |||||
| //import javax.servlet.ServletContext; | |||||
| //import java.util.ArrayList; | |||||
| //import java.util.List; | |||||
| // | |||||
| ////参考:http://blog.csdn.net/catoop/article/details/50668896 | |||||
| //@Configuration | |||||
| //@EnableSwagger2 | |||||
| //public class Swagger2Config { | |||||
| // | |||||
| // @Autowired | |||||
| // private ServletContext servletContext; | |||||
| // | |||||
| // @Bean | |||||
| // public Docket createRestApi() { | |||||
| // ParameterBuilder tokenPar = new ParameterBuilder(); | |||||
| // List<Parameter> pars = new ArrayList<Parameter>(); | |||||
| // //增加一个request的header参数 | |||||
| // tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); | |||||
| // pars.add(tokenPar.build()); | |||||
| // return new Docket(DocumentationType.SWAGGER_2) | |||||
| // .apiInfo(apiInfo()) | |||||
| // .select() | |||||
| // .apis(RequestHandlerSelectors.basePackage("com.iformall.controller")) | |||||
| // .paths(PathSelectors.any()) | |||||
| // .build() | |||||
| // .globalOperationParameters(pars) | |||||
| // .pathProvider(new RelativePathProvider(servletContext) { | |||||
| // @Override | |||||
| // public String getApplicationBasePath() { | |||||
| // return "/api"; | |||||
| // } | |||||
| // }); | |||||
| // } | |||||
| // | |||||
| // private ApiInfo apiInfo() { | |||||
| // return new ApiInfoBuilder() | |||||
| // .title("c端 api") | |||||
| // .description("c api") | |||||
| // .termsOfServiceUrl("http://localhost:7000") | |||||
| // .version("2.0") | |||||
| // .build(); | |||||
| // } | |||||
| // | |||||
| //} | |||||
| @@ -45,7 +45,9 @@ public class WebMvcConfig implements WebMvcConfigurer { | |||||
| @Override | @Override | ||||
| public void addResourceHandlers(ResourceHandlerRegistry registry) { | public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||||
| registry.addResourceHandler("swagger-ui.html") | |||||
| // registry.addResourceHandler("swagger-ui.html") | |||||
| // .addResourceLocations("classpath:/META-INF/resources/"); | |||||
| registry.addResourceHandler("doc.html") | |||||
| .addResourceLocations("classpath:/META-INF/resources/"); | .addResourceLocations("classpath:/META-INF/resources/"); | ||||
| registry.addResourceHandler("/webjars/**") | registry.addResourceHandler("/webjars/**") | ||||
| .addResourceLocations("classpath:/META-INF/resources/webjars/"); | .addResourceLocations("classpath:/META-INF/resources/webjars/"); | ||||
| @@ -5,9 +5,39 @@ import io.swagger.annotations.ApiModel; | |||||
| import io.swagger.annotations.ApiModelProperty; | import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | import lombok.Data; | ||||
| /** | |||||
| * @author xmzhao71 | |||||
| * @date 2023-10-27 | |||||
| */ | |||||
| @ApiModel(value = "生成视频请求参数") | @ApiModel(value = "生成视频请求参数") | ||||
| @Data | @Data | ||||
| public class GenerateVideoDTO { | public class GenerateVideoDTO { | ||||
| /** | |||||
| * 请求参数 | |||||
| * { | |||||
| * "gen_txt":"大家好,我是渣渣辉。是兄弟就来贪玩蓝月砍我一刀。望我,再望我,还望我,再望我就把你喝掉。", | |||||
| * "video_template_id":"16938690720846922_vorSBabt", | |||||
| * "voice_id":"zh-CN-XiaomengNeural", | |||||
| * "voice_style":"chat", | |||||
| * "video_files":{ | |||||
| * "back_ground":{ | |||||
| * "image":"", | |||||
| * "type":"vertical" | |||||
| * }, | |||||
| * "digital_human":{ | |||||
| * "coord":[ | |||||
| * -202, | |||||
| * 7 | |||||
| * ], | |||||
| * "level":1, | |||||
| * "ratio":1.3 | |||||
| * } | |||||
| * }, | |||||
| * "subtitle":{ | |||||
| * "enabled":0 | |||||
| * } | |||||
| * } | |||||
| */ | |||||
| @ApiModelProperty(value = "视频唯一标识") | @ApiModelProperty(value = "视频唯一标识") | ||||
| private Long id; | private Long id; | ||||
| @ApiModelProperty(value = "生成视频参数") | @ApiModelProperty(value = "生成视频参数") | ||||
| @@ -5,6 +5,18 @@ import io.swagger.annotations.ApiModel; | |||||
| import io.swagger.annotations.ApiModelProperty; | import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | import lombok.Data; | ||||
| /** | |||||
| * 请求参数 | |||||
| * { | |||||
| * "paperwork": "文案", | |||||
| * "voiceId": "zh-CN-XiaomengNeural", | |||||
| * "voiceStyle": "default", | |||||
| * "gender": "male" | |||||
| * } | |||||
| * | |||||
| * @author xmzhao71 | |||||
| * @date 2023-10-27 | |||||
| */ | |||||
| @ApiModel(value = "预览视频请求参数") | @ApiModel(value = "预览视频请求参数") | ||||
| @Data | @Data | ||||
| public class PreviewVideoDTO { | public class PreviewVideoDTO { | ||||
| @@ -14,12 +26,15 @@ public class PreviewVideoDTO { | |||||
| private String voiceId; | private String voiceId; | ||||
| @ApiModelProperty("声音风格名称") | @ApiModelProperty("声音风格名称") | ||||
| private String voiceStyle; | private String voiceStyle; | ||||
| @ApiModelProperty("性别(male:男,female:女)") | |||||
| private String gender; | |||||
| public static AiPreviewParam mappingParam(PreviewVideoDTO dto) { | public static AiPreviewParam mappingParam(PreviewVideoDTO dto) { | ||||
| AiPreviewParam aiPreviewParam = new AiPreviewParam(); | AiPreviewParam aiPreviewParam = new AiPreviewParam(); | ||||
| aiPreviewParam.setGen_txt(dto.getPaperwork()); | aiPreviewParam.setGen_txt(dto.getPaperwork()); | ||||
| aiPreviewParam.setVoice_id(dto.getVoiceId()); | aiPreviewParam.setVoice_id(dto.getVoiceId()); | ||||
| aiPreviewParam.setVoice_style(dto.getVoiceStyle()); | aiPreviewParam.setVoice_style(dto.getVoiceStyle()); | ||||
| aiPreviewParam.setGender(dto.getGender()); | |||||
| return aiPreviewParam; | return aiPreviewParam; | ||||
| } | } | ||||
| } | } | ||||
| @@ -38,6 +38,9 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||||
| @Override | @Override | ||||
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||||
| if (true) { | |||||
| return true; | |||||
| } | |||||
| response.setHeader("Content-type", "application/json;charset=UTF-8"); | response.setHeader("Content-type", "application/json;charset=UTF-8"); | ||||
| @@ -204,6 +204,7 @@ logging: | |||||
| suimang: | suimang: | ||||
| oral_broadcasting: http://111.198.0.15:22266 | oral_broadcasting: http://111.198.0.15:22266 | ||||
| video_tts: http://111.198.0.15:22222 | |||||
| photo_speak: http://111.198.0.15:22299 | photo_speak: http://111.198.0.15:22299 | ||||
| photo_speak_hy: http://111.198.0.15:22288 | photo_speak_hy: http://111.198.0.15:22288 | ||||
| digital_avatar: http://nas.pucao.cn:2005 | digital_avatar: http://nas.pucao.cn:2005 | ||||
| @@ -47,7 +47,7 @@ public class SwaggerConfiguration { | |||||
| * @return {@link Docket} | * @return {@link Docket} | ||||
| */ | */ | ||||
| @Bean | @Bean | ||||
| public Docket api(ServletContext servletContext) { | |||||
| public Docket docket(ServletContext servletContext) { | |||||
| // base-path处理 | // base-path处理 | ||||
| if (swaggerProperties.getBasePath().isEmpty()) { | if (swaggerProperties.getBasePath().isEmpty()) { | ||||
| swaggerProperties.getBasePath().add(BASE_PATH); | swaggerProperties.getBasePath().add(BASE_PATH); | ||||
| @@ -67,6 +67,7 @@ public class AiVideoHelper { | |||||
| videoParam.setCallback_url(callbackUrl + "/callback/oral/broadcasting"); | videoParam.setCallback_url(callbackUrl + "/callback/oral/broadcasting"); | ||||
| log.info("生成视频start request:" + videoParam.neglectImgString()); | log.info("生成视频start request:" + videoParam.neglectImgString()); | ||||
| log.info("完整参数:{}", JSONObject.toJSONString(videoParam)); | |||||
| String response = doPost(oral_broadcasting+"/gen_dh_video", JSONObject.toJSONString(videoParam)); | String response = doPost(oral_broadcasting+"/gen_dh_video", JSONObject.toJSONString(videoParam)); | ||||
| log.info("生成视频end response:"+response); | log.info("生成视频end response:"+response); | ||||
| @@ -159,6 +160,7 @@ public class AiVideoHelper { | |||||
| } | } | ||||
| public static AiPreviewResult voicePreview(AiPreviewParam param) { | public static AiPreviewResult voicePreview(AiPreviewParam param) { | ||||
| log.info("TTS音色预览 start request:" + JSONObject.toJSONString(param)); | |||||
| String response = doPost(photo_speak + "/tts_wav", JSONObject.toJSONString(param)); | String response = doPost(photo_speak + "/tts_wav", JSONObject.toJSONString(param)); | ||||
| log.info("TTS音色预览 end response:" + response); | log.info("TTS音色预览 end response:" + response); | ||||
| AiPreviewResult result = new AiPreviewResult(); | AiPreviewResult result = new AiPreviewResult(); | ||||