Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            var speechConfigSection = Configuration.GetSection("AzureSpeechConfig");
            var speechConfig        = new AzureSpeech.SpeechConfig()
            {
                AppName     = speechConfigSection.GetSection("AppName").Value,
                AudioFormat = speechConfigSection.GetSection("AudioFormat").Value,
                AzureRegion = speechConfigSection.GetSection("AzureRegion").Value,
                APIKey      = speechConfigSection.GetSection("APIKey").Value,
                Language    = speechConfigSection.GetSection("Language").Value,
                VoiceName   = speechConfigSection.GetSection("VoiceName").Value
            };

            services.AddTransient <ITranscriptRepository, TranscriptRepository>();
            services.AddTransient <IHubRepository, HubRepository>();
            services.AddSingleton <ISpeechService>(new SpeechService(speechConfig));
            services.AddSingleton(new LuisRecognizer(
                                      new LuisApplication(
                                          Configuration["DispatchAppId"],
                                          Configuration["DispatchAPIKey"],
                                          $"https://{ Configuration["DispatchAPIHostName"]}.api.cognitive.microsoft.com"
                                          ),
                                      new LuisPredictionOptions {
                IncludeAllIntents = true, IncludeInstanceData = true
            },
                                      true)
                                  );
            var children = Configuration.GetSection("BotIntents").GetChildren();
            List <BotIntent> botIntents = children.Select(s => new BotIntent
            {
                Intent   = s.GetSection("Intent").Value,
                Id       = s.GetSection("Id").Value,
                Key      = s.GetSection("Key").Value,
                HostName = s.GetSection("HostName").Value,
                IsLuis   = Convert.ToBoolean(s.GetSection("IsLuis").Value),
            }).ToList();

            services.AddSingleton(botIntents);
            services.AddTransient <IBot, ConversationDispatcher>();

            services.AddRazorPages();
            services.AddCors(options => {
                options.AddPolicy(
                    AllowOrigin,
                    builder =>
                {
                    builder
                    .AllowAnyOrigin();
                });
            }
                             );
            services.AddSignalR();
        }
Пример #2
0
 public SpeechService(object config)
 {
     _config = (SpeechConfig)config;
 }