腾讯云语音识别.net-sdk使用笔记0818

时间:2022-07-23
本文章向大家介绍腾讯云语音识别.net-sdk使用笔记0818,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

第一步,在腾讯云的语音识别的帮助文档,找不到语音识别的SDK。

找不到dotnet的SDK。

一句话语音识别

第二步,既然这里找不到的话,那我们就去GitHub的代码找一下:

github的地址:https://github.com/TencentCloud/tencentcloud-sdk-dotnet/tree/master/TencentCloud/Asr/V20190614

现在的发行版本是3.0.112.

using System;
using System.Threading.Tasks;
using TencentCloud.Common;
using TencentCloud.Common.Profile;
using TencentCloud.Asr.V20190614;
using TencentCloud.Asr.V20190614.Models;

namespace TencentCloudExamples
{
    class SentenceRecognition
    {
        static void Main(string[] args)
        {
            try
            {
                Credential cred = new Credential
                {
                    SecretId = "SecretId",
                    SecretKey = "SecretKey"
                };

                ClientProfile clientProfile = new ClientProfile();
                HttpProfile httpProfile = new HttpProfile();
                httpProfile.Endpoint = ("asr.tencentcloudapi.com");
                clientProfile.HttpProfile = httpProfile;

                AsrClient client = new AsrClient(cred, "", clientProfile);
                SentenceRecognitionRequest req = new SentenceRecognitionRequest();
                string strParams = "{"ProjectId":0,"SubServiceType":2,"EngSerViceType":"8k_zh","SourceType":0,"Url":"https://asr-1257125007.cos.ap-guangzhou.myqcloud.com/%E4%B8%91%E5%B0%8F%E9%B8%AD%E5%9C%A8%E7%BA%BF%E6%9C%97%E8%AF%BB.mp3","VoiceFormat":"mp3","UsrAudioKey":"asr0624"}";
                req = SentenceRecognitionRequest.FromJsonString<SentenceRecognitionRequest>(strParams);
                SentenceRecognitionResponse resp = client.SentenceRecognitionSync(req);
                Console.WriteLine(AbstractModel.ToJsonString(resp));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            Console.Read();
        }
    }
}

错误的代码:

message:The request with exception: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 requestId

录音文件识别结果查询:

using System;
using System.Threading.Tasks;
using TencentCloud.Common;
using TencentCloud.Common.Profile;
using TencentCloud.Asr.V20190614;
using TencentCloud.Asr.V20190614.Models;

namespace TencentCloudExamples
{
    class DescribeTaskStatus
    {
        static void Main(string[] args)
        {
            try
            {
                Credential cred = new Credential
                {
                    SecretId = "SecretId",
                    SecretKey = "SecretKey"
                };

                ClientProfile clientProfile = new ClientProfile();
                HttpProfile httpProfile = new HttpProfile();
                httpProfile.Endpoint = ("asr.tencentcloudapi.com");
                clientProfile.HttpProfile = httpProfile;

                AsrClient client = new AsrClient(cred, "ap-guangzhou", clientProfile);
                DescribeTaskStatusRequest req = new DescribeTaskStatusRequest();
                string strParams = "{"TaskId":859181183}";
                req = DescribeTaskStatusRequest.FromJsonString<DescribeTaskStatusRequest>(strParams);
                DescribeTaskStatusResponse resp = client.DescribeTaskStatusSync(req);
                Console.WriteLine(AbstractModel.ToJsonString(resp));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            Console.Read();
        }
    }
}