示例#1
0
        public void Test1(string input, string expected)
        {
            var dnaSequence = DnaSequence(input);
            var rnaSequence = new Transcriber().Transcribe(dnaSequence);

            Assert.AreEqual(RnaSequence(expected), rnaSequence);
        }
        public async Task SaveAsync(Transcriber transcriber)
        {
            var objectToSave = new CosmosObject <Transcriber>
            {
                Id   = $"{_objectType}::{transcriber.GuildId}::{transcriber.ChannelId}",
                Item = transcriber
            };

            await _cosmosContainer.UpsertItemAsync(objectToSave, new PartitionKey(_objectType));
        }
        private static async Task <bool> TranscribeIdentifiedSpeakers(string meetingMinutesFilePath,
                                                                      SpeechIdentifier.SpeechIdentifier speechIdentifier,
                                                                      string wavFilePath, SpeechConfig config)
        {
            using (var meetingMinutesWriter = new StreamWriter(meetingMinutesFilePath))
            {
                var recognitionResults = speechIdentifier.RecognitionResults.ToList();
                var startIndex         = 0;
                var currentResult      = recognitionResults.FirstOrDefault(x => x.Succeeded);
                if (currentResult == null)
                {
                    WriteLine("No recognized speaker identified. Skipping");
                    return(true);
                }

                for (var index = 0; index < recognitionResults.Count; index++)
                {
                    var result = recognitionResults[index];
                    if (!result.Succeeded || result.Value.IdentifiedProfileId == default)
                    {
                        continue;
                    }
                    if (index != recognitionResults.Count - 1 &&
                        currentResult.Value.IdentifiedProfileId == result.Value.IdentifiedProfileId)
                    {
                        continue;
                    }
                    WriteLine("Transcribing from {0} to {1}", startIndex, index);

                    var transcriber = new Transcriber(wavFilePath, meetingMinutesWriter);
                    var person      = GetSpeakerName(currentResult);
                    currentResult = result;
                    await transcriber.TranscribeSpeechFromAudioStream(config, person, startIndex, index);

                    startIndex = index;
                }
            }

            return(false);
        }
示例#4
0
        /// <summary>
        /// Uses Voiceprints to perform speaker recognition while transcribing the audio file MeetingRecording.
        /// Creates a formatted text output file holding the transcription.
        /// Sets the Transcription property holding string of transcription text
        /// </summary>
        /// <returns>Boolean true if success, false otherwise.</returns>
        public Boolean Perform(int lineLength = 120)
        {
            try
            {
                //Wait synchronously for transcript to be finished and written to minutes file.
                Transcriber.DoTranscription().Wait();
            }
            catch (Exception transcribeEx)
            {
                Console.Error.Write(">\tTranscription Failed: " + transcribeEx.Message);
                return(false);
            }


            /*Do speaker recognition concurrently for each TranscriptionOutput. */
            Recognizer.DoSpeakerRecognition(Transcriber.TranscriptionOutputs).Wait();

            MakeTranscription(lineLength);

            Console.WriteLine(">\tTranscription && Recognition Complete");
            return(true);
        }
        public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
        {
            // Check if the user has permission to use this command.
            if (!Config.HasPermission(command.Member, "transcript"))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "You do not have permission to use this command."
                };
                await command.RespondAsync("", false, error);

                command.Client.Logger.Log(LogLevel.Information, "User tried to use the transcript command but did not have permission.");
                return;
            }

            Database.Ticket ticket;
            string          strippedMessage = command.Message.Content.Replace(Config.prefix, "");

            string[] parsedMessage = strippedMessage.Replace("<@!", "").Replace("<@", "").Replace(">", "").Split();

            // If there are no arguments use current channel
            if (parsedMessage.Length < 2)
            {
                if (Database.TryGetOpenTicket(command.Channel.Id, out ticket))
                {
                    try
                    {
                        await Transcriber.ExecuteAsync(ticket.channelID.ToString(), ticket.id);
                    }
                    catch (Exception)
                    {
                        DiscordEmbed error = new DiscordEmbedBuilder
                        {
                            Color       = DiscordColor.Red,
                            Description = "ERROR: Could not save transcript file. Aborting..."
                        };
                        await command.RespondAsync("", false, error);

                        throw;
                    }
                }
                else
                {
                    DiscordEmbed error = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Red,
                        Description = "This channel is not a ticket."
                    };
                    await command.RespondAsync("", false, error);

                    return;
                }
            }
            else
            {
                // Check if argument is numerical, if not abort
                if (!uint.TryParse(parsedMessage[1], out uint ticketID))
                {
                    DiscordEmbed error = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Red,
                        Description = "Argument must be a number."
                    };
                    await command.RespondAsync("", false, error);

                    return;
                }

                // If the ticket is still open, generate a new fresh transcript
                if (Database.TryGetOpenTicketByID(ticketID, out ticket) && ticket?.creatorID == command.Member.Id)
                {
                    try
                    {
                        await Transcriber.ExecuteAsync(ticket.channelID.ToString(), ticket.id);
                    }
                    catch (Exception)
                    {
                        DiscordEmbed error = new DiscordEmbedBuilder
                        {
                            Color       = DiscordColor.Red,
                            Description = "ERROR: Could not save transcript file. Aborting..."
                        };
                        await command.RespondAsync("", false, error);

                        throw;
                    }
                }
                // If there is no open or closed ticket, send an error. If there is a closed ticket we will simply use the old transcript from when the ticket was closed.
                else if (!Database.TryGetClosedTicket(ticketID, out ticket) || (ticket?.creatorID != command.Member.Id && !Database.IsStaff(command.Member.Id)))
                {
                    DiscordEmbed error = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Red,
                        Description = "Could not find a closed ticket with that number which you opened." + (Config.HasPermission(command.Member, "list") ? "\n(Use the " + Config.prefix + "list command to see all your tickets)" : "")
                    };
                    await command.RespondAsync("", false, error);

                    return;
                }
            }

            string filePath = Transcriber.GetPath(ticket.id);

            // Log it if the log channel exists
            DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);

            if (logChannel != null)
            {
                DiscordEmbed logMessage = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Ticket " + ticket.id.ToString("00000") + " transcript generated by " + command.Member.Mention + ".\n",
                    Footer      = new DiscordEmbedBuilder.EmbedFooter {
                        Text = '#' + command.Channel.Name
                    }
                };
                await logChannel.SendFileAsync(filePath, "", false, logMessage);
            }

            try
            {
                // Send transcript privately
                DiscordEmbed directMessage = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Transcript generated, " + command.Member.Mention + "!\n"
                };
                await command.Member.SendFileAsync(filePath, "", false, directMessage);

                // Respond to message directly
                DiscordEmbed response = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Transcript sent, " + command.Member.Mention + "!\n"
                };
                await command.RespondAsync("", false, response);
            }
            catch (UnauthorizedException)
            {
                // Send transcript privately
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Not allowed to send direct message to you, " + command.Member.Mention + ", please check your privacy settings.\n"
                };
                await command.RespondAsync("", false, error);
            }
        }
示例#6
0
        public async Task OnExecute(CommandContext command)
        {
            // Check if the user has permission to use this command.
            if (!Config.HasPermission(command.Member, "close"))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "You do not have permission to use this command."
                };
                await command.RespondAsync("", false, error);

                command.Client.DebugLogger.LogMessage(LogLevel.Info, "SupportBoi", "User tried to use the close command but did not have permission.", DateTime.UtcNow);
                return;
            }

            ulong  channelID   = command.Channel.Id;
            string channelName = command.Channel.Name;

            // Check if ticket exists in the database
            if (!Database.TryGetOpenTicket(channelID, out Database.Ticket ticket))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "This channel is not a ticket."
                };
                await command.RespondAsync("", false, error);

                return;
            }

            // Build transcript
            try
            {
                await Transcriber.ExecuteAsync(command.Channel.Id.ToString(), ticket.id);
            }
            catch (Exception)
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "ERROR: Could not save transcript file. Aborting..."
                };
                await command.RespondAsync("", false, error);

                throw;
            }
            string filePath = Transcriber.GetPath(ticket.id);

            // Log it if the log channel exists
            DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);

            if (logChannel != null)
            {
                DiscordEmbed logMessage = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Ticket " + ticket.id.ToString("00000") + " closed by " + command.Member.Mention + ".\n",
                    Footer      = new DiscordEmbedBuilder.EmbedFooter {
                        Text = '#' + channelName
                    }
                };
                await logChannel.SendFileAsync(filePath, "", false, logMessage);
            }

            if (Config.closingNotifications)
            {
                DiscordEmbed message = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Ticket " + ticket.id.ToString("00000") + " which you opened has now been closed, check the transcript for more info.\n",
                    Footer      = new DiscordEmbedBuilder.EmbedFooter {
                        Text = '#' + channelName
                    }
                };

                try
                {
                    DiscordMember staffMember = await command.Guild.GetMemberAsync(ticket.creatorID);

                    DiscordMessage dm = await staffMember.SendFileAsync(filePath, "", false, message);

                    await dm.CreateReactionAsync(DiscordEmoji.FromName(command.Client, ":one:"));

                    await dm.CreateReactionAsync(DiscordEmoji.FromName(command.Client, ":two:"));

                    await dm.CreateReactionAsync(DiscordEmoji.FromName(command.Client, ":three:"));

                    await dm.CreateReactionAsync(DiscordEmoji.FromName(command.Client, ":four:"));

                    await dm.CreateReactionAsync(DiscordEmoji.FromName(command.Client, ":five:"));
                }
                catch (NotFoundException) { }
                catch (UnauthorizedException) { }
            }

            using (MySqlConnection c = Database.GetConnection())
            {
                // Create an entry in the ticket history database
                MySqlCommand archiveTicket = new MySqlCommand(@"INSERT INTO ticket_history (id, created_time, closed_time, creator_id, assigned_staff_id, summary, channel_id, rating) VALUES (@id, @created_time, now(), @creator_id, @assigned_staff_id, @summary, @channel_id, @rating);", c);
                archiveTicket.Parameters.AddWithValue("@id", ticket.id);
                archiveTicket.Parameters.AddWithValue("@created_time", ticket.createdTime);
                archiveTicket.Parameters.AddWithValue("@creator_id", ticket.creatorID);
                archiveTicket.Parameters.AddWithValue("@assigned_staff_id", ticket.assignedStaffID);
                archiveTicket.Parameters.AddWithValue("@summary", ticket.summary);
                archiveTicket.Parameters.AddWithValue("@channel_id", channelID);
                archiveTicket.Parameters.AddWithValue("@rating", 0);

                c.Open();
                archiveTicket.ExecuteNonQuery();

                // Delete the channel and database entry
                await command.Channel.DeleteAsync("Ticket closed.");

                MySqlCommand deletion = new MySqlCommand(@"DELETE FROM tickets WHERE channel_id=@channel_id", c);
                deletion.Parameters.AddWithValue("@channel_id", channelID);
                deletion.Prepare();
                deletion.ExecuteNonQuery();

                Sheets.DeleteTicketQueued(ticket.id);
            }
        }
示例#7
0
        public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
        {
            // Check if the user has permission to use this command.
            if (!Config.HasPermission(command.Member, "close"))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "You do not have permission to use this command."
                };
                await command.RespondAsync(error);

                command.Client.Logger.Log(LogLevel.Information, "User tried to use the close command but did not have permission.");
                return;
            }

            ulong  channelID   = command.Channel.Id;
            string channelName = command.Channel.Name;

            // Check if ticket exists in the database
            if (!Database.TryGetOpenTicket(channelID, out Database.Ticket ticket))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "This channel is not a ticket."
                };
                await command.RespondAsync(error);

                return;
            }

            // Build transcript
            try
            {
                await Transcriber.ExecuteAsync(command.Channel.Id, ticket.id);
            }
            catch (Exception)
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "ERROR: Could not save transcript file. Aborting..."
                };
                await command.RespondAsync(error);

                throw;
            }

            // Log it if the log channel exists
            DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);

            if (logChannel != null)
            {
                DiscordEmbed embed = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Ticket " + ticket.id.ToString("00000") + " closed by " + command.Member.Mention + ".\n",
                    Footer      = new DiscordEmbedBuilder.EmbedFooter {
                        Text = '#' + channelName
                    }
                };

                using (FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read))
                {
                    DiscordMessageBuilder message = new DiscordMessageBuilder();
                    message.WithEmbed(embed);
                    message.WithFiles(new Dictionary <string, Stream>()
                    {
                        { Transcriber.GetFilename(ticket.id), file }
                    });

                    await logChannel.SendMessageAsync(message);
                }
            }

            if (Config.closingNotifications)
            {
                DiscordEmbed embed = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Ticket " + ticket.id.ToString("00000") + " which you opened has now been closed, check the transcript for more info.\n",
                    Footer      = new DiscordEmbedBuilder.EmbedFooter {
                        Text = '#' + channelName
                    }
                };

                try
                {
                    DiscordMember staffMember = await command.Guild.GetMemberAsync(ticket.creatorID);

                    using (FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read))
                    {
                        DiscordMessageBuilder message = new DiscordMessageBuilder();
                        message.WithEmbed(embed);
                        message.WithFiles(new Dictionary <string, Stream>()
                        {
                            { Transcriber.GetFilename(ticket.id), file }
                        });

                        await staffMember.SendMessageAsync(message);
                    }
                }
                catch (NotFoundException) { }
                catch (UnauthorizedException) { }
            }

            Database.ArchiveTicket(ticket);

            // Delete the channel and database entry
            await command.Channel.DeleteAsync("Ticket closed.");

            Database.DeleteOpenTicket(ticket.id);
        }
        private static async Task CallCognitiveServices(MeetingMinutesUiPathArguments meetingMinutesUiPathArguments)
        {
            try
            {
                var wavFileCount = _audioWriter.WavFileCount;
                _audioWriter = new AudioWriter(OutputFolder);
                meetingMinutesUiPathArguments.KeyPhrasesFilePath  = $"{wavFileCount}.keyphrases.txt";
                meetingMinutesUiPathArguments.MinutesFilePath     = $"{wavFileCount}.minutes.txt";
                meetingMinutesUiPathArguments.SentimentFilePath   = $"{wavFileCount}.sentiment.txt";
                meetingMinutesUiPathArguments.TranscribedFilePath = $"{wavFileCount}.transcribed.txt";
                var fullTranscribeSpeechPath  = Combine(OutputFolder, meetingMinutesUiPathArguments.TranscribedFilePath);
                var meetingMinutesFilePath    = Combine(OutputFolder, meetingMinutesUiPathArguments.MinutesFilePath);
                var keyExtractionFilePath     = Combine(OutputFolder, meetingMinutesUiPathArguments.KeyPhrasesFilePath);
                var sentimentAnalysisFilePath = Combine(OutputFolder, meetingMinutesUiPathArguments.SentimentFilePath);

                var config = SpeechConfig.FromSubscription(Settings.SpeechServiceSubscriptionKey, "eastus");
                config.SpeechRecognitionLanguage = "en-US";

                WriteLine("===== Initializing Speech Identifier =====");
                var speakerIdentifierHttpRequests = new List <Task>();
                SpeechIdentifier.SpeechIdentifier speechIdentifier =
                    new SpeechIdentifier.SpeechIdentifier(_audioWriter.OutputFilePath, speakerIdentifierHttpRequests);
                await speechIdentifier.IdentifySpeakers();

                Task.WaitAll(speakerIdentifierHttpRequests.ToArray());
                WriteLine("===== Done Speaker Identification =====");
                WriteLine();
                WriteLine("===== Transcribing Identified Speakers =====");
                if (await TranscribeIdentifiedSpeakers(meetingMinutesFilePath, speechIdentifier,
                                                       _audioWriter.OutputFilePath,
                                                       config)
                    )
                {
                    return;
                }
                WriteLine("===== Done Transcribing Identified Speakers =====");
                WriteLine();
                WriteLine("===== Transcribing entire audio =====");
                using (var fullTranscribeSpeechWriter = new StreamWriter(fullTranscribeSpeechPath))
                {
                    var transcriber = new Transcriber(_audioWriter.OutputFilePath, fullTranscribeSpeechWriter);
                    await transcriber.TranscribeSpeechFromWavFileInput(config);
                }

                WriteLine("===== Done Transcribing entire audio =====");
                WriteLine();
                WriteLine("===== Initializing Key Extraction and Sentiment Analysis =====");
                var textAnalytics =
                    new TextAnalytics.TextAnalytics(meetingMinutesFilePath, fullTranscribeSpeechPath);

                textAnalytics.KeyExtraction(keyExtractionFilePath);
                textAnalytics.SentimentAnalysis(sentimentAnalysisFilePath);
                WriteLine("===== Done Key Extraction and Sentiment Analysis =====");
                WriteLine();
            }
            catch (Exception e)
            {
                WriteLine(e);
                ReadLine();
                throw;
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            string audioFile = null;
            string output    = null;
            string userId    = null;
            string token     = null;
            string lang      = null;

            try
            {
                // Parsing commandline arguments
                Parser.Default.ParseArguments <Options>(args)
                .WithParsed <Options>(opts => {
                    audioFile = opts.AudioFile;
                    output    = opts.Output;
                    userId    = opts.UserId;
                    token     = opts.ApiToken;
                    lang      = opts.Language;
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception thrown while parsing arguments: " + ex.Message);
                return;
            }

            Regex rx = new Regex(@"\b(https?://)?(www\.)?(youtube|youtu|youtube-nocookie|facebook|dailymotion|twitter)\.(com|be)\b",
                                 RegexOptions.Compiled | RegexOptions.IgnoreCase);

            Transcriber   transcriber = new Transcriber(userId, token, lang);
            Task <string> resultTask  = null;

            if (rx.Matches(audioFile).Count > 0)
            {
                resultTask = transcriber.TranscribeVideoLink(audioFile);
            }
            else
            {
                resultTask = transcriber.Transcribe(audioFile);
            }
            if (resultTask == null)
            {
                Console.WriteLine("Transcibing process failed.");
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
                return;
            }
            if (resultTask.IsCanceled || resultTask.IsFaulted)
            {
                Console.WriteLine("Transcibing process failed.");
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
                return;
            }
            if (!resultTask.IsCompleted)
            {
                resultTask.Wait();
            }
            string result = resultTask.Result;

            if (result == null)
            {
                Console.WriteLine("Transcibing process failed.");
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
                return;
            }
            if (output == null)
            {
                Console.WriteLine(result);
            }
            else
            {
                StreamWriter writer = new StreamWriter(output, false, Encoding.UTF8);
                writer.Write(result);
                writer.Close();
            }
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }