import config from "../../config";

const tencentcloud = require("tencentcloud-sdk-nodejs");

const AsrClient = tencentcloud.asr.v20190614.Client;




class asyncTencentASR {
    constructor(options) {
        //配置项
        this.secretid= config.tencent.secretId;
        this.secretKey= config.tencent.secretKey;
        this.appId= config.tencent.appId;



    }

    async speechRecognition(audioContent, param) {
        const clientConfig = {
            credential: {
              secretId: this.secretid,
              secretKey: this.secretKey,
            },
            region: "",
            profile: {
              httpProfile: {
                endpoint: "asr.tencentcloudapi.com",
              },
            },
          };
          
          // 实例化要请求产品的client对象,clientProfile是可选的
          const client = new AsrClient(clientConfig);
          const params = {
            "ProjectId": 0,
            "UsrAudioKey":"1",
            "SubServiceType": 2,
            "EngSerViceType": "16k_zh",
            "SourceType": 1,
            "VoiceFormat": "pcm",
            "Data": audioContent,
            "DataLen":audioContent.length
          };
          var result={};
          try{
            result= await client.SentenceRecognition(params);
            //  console.log(result);
            result.status=200;
          }catch(e){
            console.error("【TENCENT ASR】初始化接口内部错误",e);
            result.statusText=e;
            result.status=500;
          }
        return result;
    }
}

export default asyncTencentASR;