当前位置: 首页 > wzjs >正文

寻找网站建设推广上海网站seo招聘

寻找网站建设推广,上海网站seo招聘,石家庄营销策划公司排名,网站建设1对象存储服务 OSS 对应 Azure Blob Storage语音识别 ASR 对应 Azure Speech-to-Text语音合成 TTS 对应 Azure Text-to-Speech上传..mp3文件或者上传OSS地址 返回音频的文字示例demo依赖<dependencies><dependency><groupId>org.springframework.boot…

对象存储服务 OSS 对应    Azure Blob Storage

语音识别 ASR 对应   Azure Speech-to-Text

语音合成 TTS 对应   Azure Text-to-Speech

上传..mp3文件或者上传OSS地址  返回音频的文字示例demo

依赖

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webflux</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--   microsoft ASR     --><dependency><groupId>com.microsoft.cognitiveservices.speech</groupId><artifactId>client-sdk</artifactId><version>1.43.0</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>io.projectreactor</groupId><artifactId>reactor-test</artifactId><scope>test</scope></dependency></dependencies>

代码    在application.properties或者yaml中配置key和endpoint

package com.example.microsoftasr.controller;import com.microsoft.cognitiveservices.speech.*;
import com.microsoft.cognitiveservices.speech.audio.AudioConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;import java.io.File;
import java.net.URI;
import java.nio.file.Files;@RestController
@RequestMapping("/asr")
public class TestController {@Value("${azure.speech.key}")private String speechKey;@Value("${azure.speech.endpoint}")private String speechEndpoint;@GetMapping("/hello")public String test() {return "Hello World";}@PostMapping("/recognize")public String recognize(@RequestParam(value = "file", required = false) MultipartFile file,@RequestParam(value = "url", required = false) String ossUrl) {if ((file == null || file.isEmpty()) && (ossUrl == null || ossUrl.isBlank())) {return "未提供音频文件或音频地址";}File tempInput = null;File tempWav = null;try {// 1. 保存临时原始音频if (file != null && !file.isEmpty()) {String suffix = getSuffix(file.getOriginalFilename());tempInput = File.createTempFile("audio-input-", "." + suffix);file.transferTo(tempInput);} else {String suffix = getSuffix(ossUrl);tempInput = File.createTempFile("audio-input-", "." + suffix);try (var in = new java.net.URL(ossUrl).openStream()) {Files.copy(in, tempInput.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);}}// 2. 转换成 WAV(16kHz 单声道)tempWav = File.createTempFile("audio-output-", ".wav");if (!getSuffix(tempInput.getName()).equalsIgnoreCase("wav")) {ProcessBuilder pb = new ProcessBuilder("F:\\ffmpeg-7.1.1-full_build\\ffmpeg-7.1.1-full_build\\bin\\ffmpeg.exe", "-y","-i", tempInput.getAbsolutePath(),"-ar", "16000","-ac", "1",tempWav.getAbsolutePath());Process process = pb.inheritIO().start();int exitCode = process.waitFor();if (exitCode != 0) return "ffmpeg 转换失败,exitCode=" + exitCode;} else {Files.copy(tempInput.toPath(), tempWav.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);}// 3. 调用微软 ASR 识别SpeechConfig speechConfig = SpeechConfig.fromEndpoint(new URI(speechEndpoint), speechKey);speechConfig.setSpeechRecognitionLanguage("zh-CN");try (AudioConfig audioConfig = AudioConfig.fromWavFileInput(tempWav.getAbsolutePath());SpeechRecognizer recognizer = new SpeechRecognizer(speechConfig, audioConfig)) {SpeechRecognitionResult result = recognizer.recognizeOnceAsync().get();if (result.getReason() == ResultReason.RecognizedSpeech) {return result.getText();} else {return "识别失败: " + result.getReason();}}} catch (Exception e) {e.printStackTrace();return "识别异常: " + e.getMessage();} finally {try {if (tempInput != null) Files.deleteIfExists(tempInput.toPath());if (tempWav != null) Files.deleteIfExists(tempWav.toPath());} catch (Exception ex) {ex.printStackTrace();}}}private String getSuffix(String filenameOrUrl) {if (filenameOrUrl == null || !filenameOrUrl.contains(".")) return "tmp";return filenameOrUrl.substring(filenameOrUrl.lastIndexOf('.') + 1);}}

http://www.dtcms.com/wzjs/317263.html

相关文章:

  • 门网站制作图片外链生成工具
  • 昭通网站开发公司搜索引擎优化工作
  • 主播网站开发百度关键词推广
  • 用wordpress仿一个网站模板下载百度竞价托管靠谱吗
  • 网站建设用什么字体seo中介平台
  • 蒙自市建设局网站2022百度搜索风云榜
  • 深圳专业网站设计专业定制佳木斯seo
  • 能看wordpress泰州百度seo公司
  • 网站排名超快100个常用的关键词
  • 乐清英文网站建设怎么把网站排名排上去
  • 建设好学校网站做互联网项目怎么推广
  • 成都微信网站建设公司哪家好下载百度app最新版并安装
  • 印度电商平台网站建设策划十大搜索引擎排名
  • 做网站如何月入10万网推获客平台
  • 一个主机一个域名做网站seo实战培训王乃用
  • 企业网站建设定位注意的问题杭州优化公司在线留言
  • 网站服务公司哪个好查看域名每日ip访问量
  • 郴州市宜章网站建设南昌seo实用技巧
  • 中国移动网上商城优化营商环境心得体会个人
  • 网站备案幕布照规范五个成功品牌推广案例
  • 家电网站策划福州短视频seo公司
  • 114百事通做网站600网上销售平台有哪些
  • 上海专业做网站公合肥网站优化方案
  • 顺义网站制作windows优化大师怎么用
  • 做网站的模版seo优化工具软件
  • 大连 网站制作 外贸酒吧营销用什么软件找客源
  • 效果好企业营销型网站建设网页设计成品源代码
  • 网站的关键词推扩是怎样做百度网盘app官网
  • 医院网站怎么做优化排名企业培训内容有哪些
  • 谁能帮我做网站seo百度关键词优化软件