ACRCloudWebAPITest.IdentifyProtocolV1.recognize C# (CSharp) Method

recognize() public static method

public static recognize ( string host, string accessKey, string secretKey, byte queryData, string queryType, int timeout = 8000 ) : string
host string
accessKey string
secretKey string
queryData byte
queryType string
timeout int
return string
        public static string recognize(string host, string accessKey, string secretKey, byte[] queryData, string queryType, int timeout = 8000)
        {
            string method = "POST";
               string httpURL = "/v1/identify";
               string dataType = queryType;
               string sigVersion = "1";
               string timestamp = ((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds).ToString();

               string reqURL = "http://" + host + httpURL;

               string sigStr = method + "\n" + httpURL + "\n" + accessKey + "\n" + dataType + "\n" + sigVersion + "\n" + timestamp;
               string signature = encryptByHMACSHA1(sigStr, secretKey);

               var dict = new Dictionary<string, object>();
               dict.Add("access_key", accessKey);
               dict.Add("sample_bytes", queryData.Length.ToString());
               dict.Add("sample", queryData);
               dict.Add("timestamp", timestamp);
               dict.Add("signature", signature);
               dict.Add("data_type", queryType);
               dict.Add("signature_version", sigVersion);

               string res = postHttp(reqURL, dict, timeout);

               return res;
        }

Usage Example

        static void Main(string[] args)
        {
            using (FileStream fs = new FileStream(@"E:\sample.wav", FileMode.Open))
            {
                using (BinaryReader reader = new BinaryReader(fs))
                {
                    byte[] datas = reader.ReadBytes((int)fs.Length);
                    // Replace "xxxxxxxx" below with your project's access_key and access_secret.
                    string result = IdentifyProtocolV1.recognize("ap-southeast-1.api.acrcloud.com", "xxxxxxxx", "xxxxxxxx", datas, "audio");
                    Console.WriteLine(result);
                }
            }

            Console.ReadLine();
        }
All Usage Examples Of ACRCloudWebAPITest.IdentifyProtocolV1::recognize