1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package com.example.unusualsounds.common.utils;
- import jakarta.annotation.Resource;
- import lombok.extern.java.Log;
- import org.hibernate.validator.constraints.Length;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.*;
- import org.springframework.stereotype.Component;
- import org.springframework.web.client.RestTemplate;
- import java.io.IOException;
- import java.util.Map;
- /**
- * 音频算法分析类
- */
- @Log
- @Component
- public final class VoiceAnalysisUtils {
- private static RestTemplate restTemplateStatic;
- @Autowired
- public void setRestTemplate(RestTemplate restTemplate) {
- VoiceAnalysisUtils.restTemplateStatic = restTemplate;
- }
- public static String postVoxAnalysis(Map<String,Object> maps,String postAnalysisUrl){
- HttpHeaders httpHeaders = new HttpHeaders();
- httpHeaders.setContentType(MediaType.APPLICATION_JSON);
- HttpEntity<Map<String, Object>> mapHttpEntity = new HttpEntity<>(maps, httpHeaders);
- try {
- ResponseEntity<String> stringResponseEntity = restTemplateStatic.postForEntity(postAnalysisUrl, mapHttpEntity, String.class);
- if (stringResponseEntity.getStatusCode() == HttpStatus.OK){
- return "通知算法成功";
- }
- return "通知算法失败";
- }catch (Exception e){
- return "发送失败:"+e.getMessage();
- }
- }
- }
|