VoiceAnalysisUtils.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.example.unusualsounds.common.utils;
  2. import jakarta.annotation.Resource;
  3. import lombok.extern.java.Log;
  4. import org.hibernate.validator.constraints.Length;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.http.*;
  7. import org.springframework.stereotype.Component;
  8. import org.springframework.web.client.RestTemplate;
  9. import java.io.IOException;
  10. import java.util.Map;
  11. /**
  12. * 音频算法分析类
  13. */
  14. @Log
  15. @Component
  16. public final class VoiceAnalysisUtils {
  17. private static RestTemplate restTemplateStatic;
  18. @Autowired
  19. public void setRestTemplate(RestTemplate restTemplate) {
  20. VoiceAnalysisUtils.restTemplateStatic = restTemplate;
  21. }
  22. public static String postVoxAnalysis(Map<String,Object> maps,String postAnalysisUrl){
  23. HttpHeaders httpHeaders = new HttpHeaders();
  24. httpHeaders.setContentType(MediaType.APPLICATION_JSON);
  25. HttpEntity<Map<String, Object>> mapHttpEntity = new HttpEntity<>(maps, httpHeaders);
  26. try {
  27. ResponseEntity<String> stringResponseEntity = restTemplateStatic.postForEntity(postAnalysisUrl, mapHttpEntity, String.class);
  28. if (stringResponseEntity.getStatusCode() == HttpStatus.OK){
  29. return "通知算法成功";
  30. }
  31. return "通知算法失败";
  32. }catch (Exception e){
  33. return "发送失败:"+e.getMessage();
  34. }
  35. }
  36. }