public static async Task<IEnumerable<SessionEvent>> Test(Options options)
        {
            ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
            ServicePointManager.DefaultConnectionLimit = 10000;
            List<SessionEvent> collector = new List<SessionEvent>();

            Action<SessionEvent> consoleDump = ConsoleDump(options);



            try
            {
                var client = new SessionClient(options, (evt) =>
                {
                    if (options.ConsoleOff == false)
                        consoleDump(evt);
                    //file dump
                    collector.Add(evt);

                });

                var ok = await client.Start();
                await client.Analyze(
                    progressCallback: (transferred, total, progress) =>
                        {
                            //Console.WriteLine("Sent: " + transferred + " bytes");
                        });

            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                if (options.OutputFile != null)
                {
                    try
                    {
                        DumpResultToJsonFile(options, collector);
                    }
                    catch { }
                }
            }
            return collector;
        }
        public static DataFormat Create( Options options)
        {
            if (options.SoundFile.EndsWith(".wav"))
                return new DataFormat()
                {
                    type = "WAV",
                    auto_detect = true,
                    channels = 1,

                };
            else
                return new DataFormat()
                {
                    type = "PCM",
                    bits_per_sample = options.BitsPerSample,
                    sample_rate = options.SamplingRate,
                    channels = 1,
                    auto_detect = false
                };
        }
        static Action<SessionEvent> ConsoleDump(Options options)
        {
            Func<Action<SessionEvent>> objectFunc = () =>
            {
                SessionEventType? recentEvtType = null;
                return (evt) =>
                {
                    //nice print
                    if (evt.EventType != SessionEventType.Progress && recentEvtType == SessionEventType.Progress)
                        Console.WriteLine();
                    recentEvtType = evt.EventType;


                    switch (evt.EventType)
                    {
                        case SessionEventType.Analysis:
                            Console.WriteLine(evt.Data);
                            break;
                        case SessionEventType.Progress:
                            Console.Write(".");
                            break;
                        case SessionEventType.Started:
                            Console.WriteLine("Started");
                            break;

                        case SessionEventType.Complete:
                            Console.WriteLine(evt.Data);
                            break;
                        case SessionEventType.Error:
                            Console.WriteLine(evt.Data);
                            break;
                    }
                };
            };
            return objectFunc();
        }
 public SessionClient(Options options, Action<SessionEvent> eventCallback)
 {
     this.options = options;
     this.eventCallback = eventCallback;
 }
        private static void DumpResultToJsonFile(Options options, IList<SessionEvent> events)
        {
            string fileName = options.FilenameIsTemplate ? string.Format(options.OutputFile, events.First().RecordingId) : options.OutputFile;

            using (FileStream fs = File.Open(fileName, FileMode.Create))
            using (StreamWriter sw = new StreamWriter(fs))
            using (JsonWriter jw = new JsonTextWriter(sw))
            {
                jw.Formatting = Formatting.Indented;
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(jw, events);
            }
        }