使用腾讯云实现录音语音转换文字简单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(
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值