示例#1
0
        public void ParallelItemAction(RegionTaskSettings settings, Func <RegionTaskSettings, string> action, string group)
        {
            string result;

            try
            {
                result = string.Format("{0}", action(settings));
            }
            catch (Exception ex)
            {
                result = string.Format("Exception: {0}", ex.Message);
            }
            // Report.
            lock (ParallelReportLock)
            {
                System.Threading.Interlocked.Increment(ref ParallelCount);
                var percent = (decimal)ParallelCount / (decimal)ParallelTotal * 100m;
                AddStatus(ParalelLineFormat, group, percent, ParallelCount, settings.Name, result);
            }
        }
示例#2
0
        string GetVoices(RegionTaskSettings settings)
        {
            var reg     = settings.Region;
            var engine  = settings.Engine;
            var culture = settings.Culture;

            settings.Voices = new List <InstalledVoiceEx>();
            //var engine = reg.e
            AmazonPolly client = null;

            try
            {
                client = new AmazonPolly(
                    SettingsManager.Options.AmazonAccessKey,
                    SettingsManager.Options.AmazonSecretKey,
                    reg.SystemName
                    );
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(ex.Message);
            }
            var request = new DescribeVoicesRequest();

            if (engine != null)
            {
                request.Engine = engine;
            }
            if (culture != null)
            {
                request.LanguageCode = culture.Name;
            }
            // Create stop watch to measure speed with the servers.
            var sw = new Stopwatch();

            sw.Start();
            var voices  = client.GetVoices(request, 5000);
            var elapsed = sw.Elapsed;

            if (client.LastException != null)
            {
                return(string.Format("Exception: {0}", client.LastException.Message));
            }
            var vex = 0;

            for (int v = 0; v < voices.Count; v++)
            {
                var voice        = voices[v];
                var cultureNames = new List <string>();
                cultureNames.Add(voice.LanguageCode);
                cultureNames.AddRange(voice.AdditionalLanguageCodes);
                // Add extra cultures.
                foreach (var cultureName in cultureNames)
                {
                    // Add engines.
                    var c = new CultureInfo(cultureName);
                    foreach (var engineName in voice.SupportedEngines)
                    {
                        var vx = new InstalledVoiceEx(voice);
                        vx.SetCulture(c);
                        vx.SourceRequestSpeed = elapsed;
                        var keys = System.Web.HttpUtility.ParseQueryString("");
                        keys.Add(InstalledVoiceEx._KeySource, vx.Source.ToString());
                        keys.Add(InstalledVoiceEx._KeyRegion, reg.SystemName);
                        keys.Add(InstalledVoiceEx._KeyCulture, cultureName);
                        keys.Add(InstalledVoiceEx._KeyEngine, engineName);
                        keys.Add(InstalledVoiceEx._KeyVoiceId, voice.Id);
                        vx.SourceKeys = keys.ToString();
                        // Override Description.
                        vx.Description = string.Format("{0}, {1}, {2}, {3}",
                                                       vx.Source, reg.DisplayName, cultureName, engineName);
                        // Add voice.
                        settings.Voices.Add(vx);
                        vex++;
                        if (_CancelGetVoices)
                        {
                            return("Cancelled");
                        }
                    }
                }
            }
            return(string.Format("Time (ms): {0,4}, Voices: {1,2}", (int)elapsed.Milliseconds, voices.Count));
        }