Esempio n. 1
0
        private static async Task <MemoryStream> GenerateAsync(string text, string voice)
        {
            Task <string> pollyRequest = Http.SendRequestAsync("https://streamlabs.com/polly/speak",
                                                               parameters: new Dictionary <string, string> {
                { "text", text }, { "voice", voice }
            }, method: Http.Method.Post);

            string pollyRequestData = await pollyRequest;

            if (pollyRequest.IsCompletedSuccessfully)
            {
                Polly polly = Http.DeserializeJson <Polly>(pollyRequestData);

                if (polly is Polly && polly.Success)
                {
                    Task <MemoryStream> pollyStream     = Http.GetStreamAsync(polly.SpeakUrl);
                    MemoryStream        pollyStreamData = await pollyStream;

                    if (pollyStream.IsCompletedSuccessfully)
                    {
                        return(pollyStreamData);
                    }
                    else
                    {
                        LoggingManager.Log.Error(pollyStream.Exception);
                    }
                }
            }
            else
            {
                LoggingManager.Log.Error(pollyRequest.Exception);
            }

            return(null);
        }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            /* SCOPE */
            using IServiceScope serviceScope = _serviceProvider.CreateScope();
            IServiceProvider scopeServiceProvider = serviceScope.ServiceProvider;

            /* BOT DATA */
            await using TtsDbContext ttsDbContext = scopeServiceProvider.GetRequiredService <TtsDbContext>();
            BotDataAccess.Prefetch(ttsDbContext.BotData);

            /* POLLY */
            Polly polly = scopeServiceProvider.GetRequiredService <Polly>();
            await polly.InitVoicesData();

            /* EVENT SUB */
            Subscriptions subscriptions = scopeServiceProvider.GetRequiredService <Subscriptions>();

            Transport.Default = _hostEnvironment.IsDevelopment()
                ? Transport.DefaultDevelopment
                : Transport.DefaultProduction;
            await subscriptions.SetRequiredSubscriptionsForAllChannels();
        }
 public SynthesizeSpeechController(ILogger <SynthesizeSpeechController> logger, Polly polly)
 {
     _logger = logger;
     _polly  = polly;
 }