예제 #1
0
        /// <summary>
        /// Process message from queue
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task <string> ProcessAudioAsync(string message)
        {
            var msg = JsonConvert.DeserializeObject <ProcessAudioMessage>(message);

            ///get blob
            var blob = await _blobStorageService.GetFileAsync(Container.Audio, msg.FileName);

            ///extract text from audio file
            var capture = new TextCapture();
            await _speechService.ContinuousRecognitionWithFileAsync(await blob.OpenReadAsync(), capture);

            /// get auth token
            var token = await _tokenService.GetAuthTokenAsync();

            /// get overall sentiment
            var sentiment = await _textAnalyticsService.GetSentiment(capture.Text, token);

            /// related emotional taxonomies
            var taxonomy = await _textAnalyticsService.GetTaxonomy(capture.Text, token);

            string taxonomyStr = string
                                 .Join(", ", taxonomy.Data.Categories
                                       .Select(x => x.Label)).TrimEnd(',', ' ');

            ///create audio entry with details from above
            var audio = new Audio
            {
                FileName      = msg.FileName,
                FileExtension = Path.GetExtension(msg.FileName),
                Issue         = msg.Issue,
                Created       = DateTime.Now,
                Sentiment     = sentiment.Data.Sentiment.Overall,
                Taxonomy      = taxonomyStr,
                Status        = AuditStatus.Done,
                Transcript    = capture.Text
            };

            await _dbContext.Audios.AddAsync(audio);

            await _dbContext.SaveChangesAsync();

            return(audio.FileName);
        }