使用腾讯云实现录音语音转换文字简单DEMO
感谢
首先贴出后台提供 点这里
前台都是东拼西凑这里就不贴了 还是感谢
对接腾讯云
先去腾讯云登录 然后对接接口会免费送体验次数
https://cloud.tencent.com/document/product/1093/35691
生成自己的AppId、SecretId和SecretKey
新建springboot项目
添加依赖
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
<version>3.1.62</version>
</dependency>
在配置文件(application.properties)中加入申请的
spring.secretId=改成自己的SecretId
spring.secretKey=改成自己的SecretKey
还有上传文件限制也设置大一点
创建一个接口(VoiceService)
String Sentence();
创捷一个继承接口的具体方法类(VoiceServiceImpl)
6. package com.example.luyin.service;
import com.tencentcloudapi.asr.v20190614.AsrClient;
import com.tencentcloudapi.asr.v20190614.models.SentenceRecognitionRequest;
import com.tencentcloudapi.asr.v20190614.models.SentenceRecognitionResponse;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Base64;
@Service
public class VoiceServiceImpl implements VoiceService {
//取出application.properties配置中配置的secretId和secretKey的值
//并把值赋给对应的变量
@Value("${spring.secretId}")
private String secretId;
@Value("${spring.secretKey}")
private String secretKey;
@Override
public String Sentence(File file) {
try{
Credential cred = new Credential(secretId, secretKey);
HttpProfile httpProfile = new HttpProfile(