Esempio n. 1
0
        private async Task StoreRecognizedPhraseAsync(Guid combinedPhraseID, RecognizedPhrase recognizedPhrase, double previousEndInMs)
        {
            var silenceBetweenCurrentAndPreviousSegmentInMs = Math.Max(0, TimeSpan.FromTicks(recognizedPhrase.OffsetInTicks).TotalMilliseconds - previousEndInMs);

            var phraseId = Guid.NewGuid();
            var query    = "INSERT INTO dbo.RecognizedPhrases (ID, CombinedRecognizedPhraseID, RecognitionStatus, Speaker, Channel, Offset, Duration, SilenceBetweenCurrentAndPreviousSegmentInMs)" +
                           " VALUES (@id, @combinedRecognizedPhraseID, @recognitionStatus, @speaker, @channel, @offset, @duration, @silenceBetweenCurrentAndPreviousSegmentInMs)";

            using var command = new SqlCommand(query, Connection);
            command.Parameters.AddWithValue("@id", phraseId);
            command.Parameters.AddWithValue("@combinedRecognizedPhraseID", combinedPhraseID);
            command.Parameters.AddWithValue("@recognitionStatus", recognizedPhrase.RecognitionStatus);
            command.Parameters.AddWithValue("@speaker", recognizedPhrase.Speaker);
            command.Parameters.AddWithValue("@channel", recognizedPhrase.Channel);
            command.Parameters.AddWithValue("@offset", recognizedPhrase.Offset);
            command.Parameters.AddWithValue("@duration", recognizedPhrase.Duration);
            command.Parameters.AddWithValue("@silenceBetweenCurrentAndPreviousSegmentInMs", silenceBetweenCurrentAndPreviousSegmentInMs);

            var result = await command.ExecuteNonQueryAsync().ConfigureAwait(false);

            if (result < 0)
            {
                Logger.LogInformation("Did not store phrase in Db, command did not update table");
            }
            else
            {
                foreach (var nBestResult in recognizedPhrase.NBest)
                {
                    await StoreNBestAsync(phraseId, nBestResult).ConfigureAwait(false);
                }
            }
        }
Esempio n. 2
0
        private async Task StoreRecognizedPhraseAsync(Guid combinedPhraseID, RecognizedPhrase recognizedPhrase)
        {
            var phraseId = Guid.NewGuid();
            var query    = "INSERT INTO dbo.RecognizedPhrases (ID, CombinedRecognizedPhraseID, RecognitionStatus, Speaker, Channel, Offset, Duration)" +
                           " VALUES (@id, @combinedRecognizedPhraseID, @recognitionStatus, @speaker, @channel, @offset, @duration)";

            using (var command = new SqlCommand(query, Connection))
            {
                command.Parameters.AddWithValue("@id", phraseId);
                command.Parameters.AddWithValue("@combinedRecognizedPhraseID", combinedPhraseID);
                command.Parameters.AddWithValue("@recognitionStatus", recognizedPhrase.RecognitionStatus);
                command.Parameters.AddWithValue("@speaker", recognizedPhrase.Speaker);
                command.Parameters.AddWithValue("@channel", recognizedPhrase.Channel);
                command.Parameters.AddWithValue("@offset", recognizedPhrase.Offset);
                command.Parameters.AddWithValue("@duration", recognizedPhrase.Duration);

                var result = await command.ExecuteNonQueryAsync().ConfigureAwait(false);

                if (result < 0)
                {
                    Logger.LogInformation("Did not store phrase in Db, command did not update table");
                }
                else
                {
                    foreach (var nBestResult in recognizedPhrase.NBest)
                    {
                        await StoreNBestAsync(phraseId, nBestResult).ConfigureAwait(false);
                    }
                }
            }
        }