示例#1
0
        static void Main(string[] args)
        {
            var sessionApi                 = new SessionApi();
            var startSession               = new AuthRequestDto("user", 261, "password");
            var response                   = sessionApi.Login(startSession);
            var sessionId                  = response.SessionId;
            var recognizeApi               = new RecognizeApi();
            var soundBytes                 = File.ReadAllBytes("F:\\Art\\pcm\\0068_20170407_own_6944_181007-1496930080.wav");
            var audio                      = new AudioFileDto(soundBytes, "audio/x-wav");
            var recognitionRequest         = new RecognitionRequestDto(audio, "FarField");
            var recognitionRequestResponse = recognizeApi.RecognizeWords(Guid.Parse(sessionId), recognitionRequest);

            recognitionRequestResponse.ForEach(Console.WriteLine);
        }
示例#2
0
        public static string GetTwitterButton(string url)
        {
            // Credentials:
            var IMGUR_ID     = "12115820ce1d5b6";
            var IMGUR_SECRET = "dc71545b6d4f107e03d47b9dcab2268070e1658d";

            var CLOUDMERSIVE_ID = "28e63794-ef8a-4616-80bb-26fdd3709a19";

            // Download file:
            string imagesDir = "wwwroot/Images/";

            if (System.IO.File.Exists(imagesDir + "image.jpeg"))
            {
                System.IO.File.Delete(imagesDir + "image.jpeg");
            }

            using (WebClient wc = new WebClient())
            {
                wc.DownloadFile(new Uri(url), imagesDir + "image.jpeg");
            }

            // Imgur API:
            var client   = new ImgurClient(IMGUR_ID, IMGUR_SECRET);
            var endpoint = new ImageEndpoint(client);

            IImage imgur_image;

            using (var fs = new FileStream(imagesDir + "image.jpeg", FileMode.Open))
            {
                imgur_image = Task.Run(async() => { return(await endpoint.UploadImageStreamAsync(fs)); }).Result;
            }


            var imgur_link = imgur_image.Link;

            Console.WriteLine("Imgur link: " + imgur_link);

            // Cloudmersive API:

            Configuration.Default.AddApiKey("Apikey", CLOUDMERSIVE_ID);
            var cm_API = new RecognizeApi();

            string description = "";

            try
            {
                description = cm_API.RecognizeDescribe(new System.IO.FileStream(imagesDir + "image.jpeg", System.IO.FileMode.Open)).BestOutcome.Description;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                description = "something the Cloudmersive API could not identify.";
                //return "";
            }
            Console.WriteLine("DESCRIPTION: " + description);

            // Twitter button:
            string tweet_body     = "Here is a picture of " + description + " Posted through MealPlanner101: " + imgur_link;
            string tweet_body_url = "";

            foreach (var tweet_char in tweet_body)
            {
                if (tweet_char == ' ')
                {
                    tweet_body_url += "%20";
                }
                else
                {
                    tweet_body_url += tweet_char;
                }
            }

            string tweet_button =

                "<a class = \"twitter-share-button\" href = https://twitter.com/intent/tweet?text=" + tweet_body_url + ">Tweet</a>";

            Console.WriteLine("Tweet HTML: " + tweet_button);

            return(tweet_button);
        }
 public void Init()
 {
     instance = new RecognizeApi();
 }