Пример #1
0
        public async Task <JsonResult> OnGetSelectedSpeaker(string speakerName)
        {
            var connectionString = Environment.GetEnvironmentVariable("MONGO_CONNECT_STR");
            var database         = CosmosUtils.ConnectToDatabase(connectionString, "Samples");
            var collection       = database.GetCollection <SamplesCollection>("Samples");

            var transcripts = new List <Transcript>();

            foreach (var samplesCollection in await CosmosUtils.GetAllAsync(collection))
            {
                var transcriptParts = samplesCollection.samples.Where(s => s.speakerName == speakerName)
                                      .Select(s => new Part()
                {
                    Text      = s.text,
                    Time      = $"{s.duration}",
                    StartTime = s.startTime,
                    EndTime   = s.endTime
                }).ToList();
                if (transcriptParts.Count > 0)
                {
                    transcripts.Add(new Transcript()
                    {
                        TranscriptId = samplesCollection.transcriptId,
                        VideoUri     = samplesCollection.VideoUri,
                        Parts        = transcriptParts
                    });
                }
            }

            return(new JsonResult(transcripts));
        }
Пример #2
0
        public async Task <IActionResult> CosmosMongo()
        {
            var invoice = new InvoiceEntity()
            {
                Id      = "5deb1cf715755c43e4d1a615",
                Article = new Article()
                {
                    Name  = "Forklift",
                    Price = 54000
                },
                AmountPaid  = 24000,
                AmountToPay = 30000
            };



            var database   = CosmosUtils.ConnectToDatabase(_cosmosMongoConnString, "Invoices");
            var collection = database.GetCollection <InvoiceEntity>("Invoices");
            await CosmosUtils.AddDocumentAsync(collection, invoice);

            invoice.Article.Name = "Forklift X320";
            await CosmosUtils.UpdateDocumentAsync(collection, invoice);

            foreach (var invoiceEntity in await CosmosUtils.GetAllAsync(collection))
            {
                Console.WriteLine(invoiceEntity.Article.Name);
            }

            await CosmosUtils.DeleteAsync(collection, invoice);

            return(Ok());
        }
Пример #3
0
        public async Task <IActionResult> OnPost(string?transcriptId, List <SampleDto> samples)
        {
            var connectionString = Environment.GetEnvironmentVariable("MONGO_CONNECT_STR");
            var database         = CosmosUtils.ConnectToDatabase(connectionString, "Samples");
            var collection       = database.GetCollection <SamplesCollection>("Samples");
            SamplesCollection samplesCollection = null;

            foreach (var samplesEntity in await CosmosUtils.GetAllAsync(collection))
            {
                if (samplesEntity.transcriptId == transcriptId)
                {
                    samplesCollection = samplesEntity;
                    break;
                }
            }

            foreach (var classifiedSample in samples)
            {
                foreach (var sample in samplesCollection.samples
                         .Where(s => s.speakerId == classifiedSample.SpeakerId))
                {
                    sample.speakerName = classifiedSample.SpeakerName;
                }
            }
            await CosmosUtils.UpdateDocumentAsync(collection, samplesCollection);

            return(RedirectToPage("../Speakers/Index"));
        }
Пример #4
0
        private async Task <SamplesCollection> LoadSamples(string transcriptId)
        {
            var connectionString = Environment.GetEnvironmentVariable("MONGO_CONNECT_STR");
            var database         = CosmosUtils.ConnectToDatabase(connectionString, "Samples");
            var collection       = database.GetCollection <SamplesCollection>("Samples");

            foreach (var samplesEntity in await CosmosUtils.GetAllAsync(collection))
            {
                if (samplesEntity.transcriptId == transcriptId)
                {
                    return(samplesEntity);
                }
            }

            throw new ArgumentException($"Samples not found: {transcriptId}");
        }
Пример #5
0
        public async Task <IActionResult> OnGet()
        {
            var connectionString = Environment.GetEnvironmentVariable("MONGO_CONNECT_STR");
            var database         = CosmosUtils.ConnectToDatabase(connectionString, "Samples");
            var collection       = database.GetCollection <SamplesCollection>("Samples");

            var speakers = new List <string>();

            foreach (var samplesEntity in await CosmosUtils.GetAllAsync(collection))
            {
                speakers.AddRange(samplesEntity.samples.Select(s => s.speakerName).Distinct().ToList());
            }

            Speakers = speakers.Distinct().Select(s => new SelectListItem(s, s)).ToList();


            return(Page());
        }
Пример #6
0
        public async Task FindSamples(string transcriptId, LongRunningRecognizeResponse recognizeResponse, string sourceUri, string originUri)
        {
            var result = recognizeResponse.Results.Last();

            if (result == null)
            {
                throw new ArgumentException("Empty recognition response. Cannot find samples.");
            }

            var             words              = result.Alternatives.Last().Words;
            int             currentSpeakerTag  = -1;
            List <WordInfo> currentSampleWords = new List <WordInfo>();
            List <Sample>   samples            = new List <Sample>();

            foreach (WordInfo wordInfo in words)
            {
                if (currentSpeakerTag == -1)
                {
                    currentSpeakerTag = wordInfo.SpeakerTag;
                    currentSampleWords.Add(wordInfo);
                }
                else
                {
                    if (currentSpeakerTag != wordInfo.SpeakerTag) // save new sample
                    {
                        await AddSample();

                        //switch speaker
                        currentSampleWords.Clear();
                        currentSpeakerTag = wordInfo.SpeakerTag;
                    }
                    else
                    {
                        currentSampleWords.Add(wordInfo);
                    }
                }
            }

            //last sample
            await AddSample();

            var samplesToSave = new SamplesCollection()
            {
                samples      = samples,
                transcriptId = transcriptId,
                VideoUri     = originUri
            };

            var connectionString = Environment.GetEnvironmentVariable("MONGO_CONNECT_STR");
            var database         = CosmosUtils.ConnectToDatabase(connectionString, "Samples");
            var collection       = database.GetCollection <SamplesCollection>("Samples");
            await CosmosUtils.AddDocumentAsync(collection, samplesToSave);

            foreach (var invoiceEntity in await CosmosUtils.GetAllAsync(collection))
            {
                Console.WriteLine(invoiceEntity.transcriptId);
            }

            async Task AddSample()
            {
                var      orderedWords = currentSampleWords.OrderBy(w => w.StartTime.Nanos);
                var      firstWord    = orderedWords.First();
                var      lastWord     = orderedWords.Last();
                Duration duration     = orderedWords.Last().EndTime - orderedWords.First().StartTime;
                string   trimmedFile  = AudioTrimmer.SaveTrimmed(
                    (int)(firstWord.StartTime.Seconds * 1000) + firstWord.StartTime.Nanos / 1000_000,
                    (int)(lastWord.EndTime.Seconds * 1000) + lastWord.EndTime.Nanos / 1000_000,
                    sourceUri);
                string blobName = await StorageLoader.PutIntoBlob(trimmedFile);

                samples.Add(new Sample()
                {
                    duration   = (int)(duration.Seconds * 1000) + duration.Nanos / 1000_000,
                    wordCount  = orderedWords.Count(),
                    speakerId  = currentSpeakerTag,
                    startTime  = firstWord.StartTime.ToTimeSpan().ToString("g"),
                    endTime    = lastWord.EndTime.ToTimeSpan().ToString("g"),
                    storageUri = $"{StorageLoader.BlobServiceClient.Uri}{StorageLoader.BlobName}/{blobName}",
                    text       = string.Join(' ', currentSampleWords.Select(w => w.Word))
                });
            }