コード例 #1
0
ファイル: NLPPage.xaml.cs プロジェクト: eman226/carl
        private void Summarize_Click(object sender, RoutedEventArgs e)
        {
            string fin  = " ";
            string fout = " ";

            System.Windows.Forms.MessageBox.Show("Choose text file");
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                fin = openFileDialog1.FileName;
                System.Windows.Forms.MessageBox.Show(fin);
            }

            System.Windows.Forms.MessageBox.Show("Choose output file");
            OpenFileDialog openFileDialog2 = new OpenFileDialog();

            if (openFileDialog2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                fout = openFileDialog2.FileName;
                System.Windows.Forms.MessageBox.Show(fout);
            }

            string path = fout;                      //path to refined text

            File.WriteAllText(path, String.Empty);   //clear temp file
            StreamWriter sw = File.AppendText(path); //pointer to write to temp file

            ProcessStartInfo pythonInfo = new ProcessStartInfo();
            Process          python;

            pythonInfo.FileName               = @"C:\Users\Emmanuel\AppData\Local\Programs\Python\Python35\python.exe";
            pythonInfo.Arguments              = @"C:\Users\Emmanuel\Documents\Engineering_4\Degree\SpeechtoText\speech-to-text-wavenet-master\summarize.py" + " " + fin;
            pythonInfo.CreateNoWindow         = false;
            pythonInfo.UseShellExecute        = false;
            pythonInfo.RedirectStandardOutput = true;
            ConsoleManager.Show();
            Console.WriteLine("Python Starting");
            python = Process.Start(pythonInfo);
            StreamReader myStreamReader = python.StandardOutput;
            string       myString       = myStreamReader.ReadToEnd();

            python.WaitForExit();
            python.Close();

            sw.WriteLine("SUMMARY:");
            sw.WriteLine(" ");
            sw.WriteLine(myString);
            sw.Close();
            ConsoleManager.Hide();
        }
コード例 #2
0
ファイル: RecordPage.xaml.cs プロジェクト: eman226/carl
        private void Transcribe_Click(object sender, RoutedEventArgs e)
        {
            string wav  = " ";
            string fout = " ";

            System.Windows.Forms.MessageBox.Show("Choose audio file");
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                wav = openFileDialog1.FileName;
                System.Windows.Forms.MessageBox.Show(wav);
            }

            System.Windows.Forms.MessageBox.Show("Choose output file");
            OpenFileDialog openFileDialog2 = new OpenFileDialog();

            if (openFileDialog2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                fout = openFileDialog2.FileName;
                System.Windows.Forms.MessageBox.Show(fout);
            }

            //remember to change working directory
            ProcessStartInfo pythonInfo = new ProcessStartInfo();
            Process          python;

            pythonInfo.FileName  = @"C:\Users\Emmanuel\AppData\Local\Programs\Python\Python35\python.exe";
            pythonInfo.Arguments = @"C:\Users\Emmanuel\Documents\Engineering_4\Degree\SpeechtoText\speech-to-text-wavenet-master\recognize.py" + " " + wav + " " +
                                   fout;
            pythonInfo.CreateNoWindow         = false;
            pythonInfo.UseShellExecute        = false;
            pythonInfo.RedirectStandardOutput = true;

            ConsoleManager.Show();
            Console.WriteLine("Python Starting");

            python = Process.Start(pythonInfo);
            StreamReader myStreamReader = python.StandardOutput;
            string       myString       = myStreamReader.ReadLine();

            python.WaitForExit();
            python.Close();

            Console.WriteLine("Value received from script: " + myString);
            //Console.WriteLine(fout);

            try
            {
                //Pass the filepath and filename to the StreamWriter Constructor
                StreamWriter sw = new StreamWriter(fout);

                //Write a line of text
                sw.WriteLine(myString);

                //Write a second line of text
                sw.WriteLine("From the StreamWriter class");

                //Close the file
                sw.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }

            /* finally
             * {
             *   Console.WriteLine("Executing finally block.");
             * }*/
            //ConsoleManager.Hide();
        }
コード例 #3
0
ファイル: NLPPage.xaml.cs プロジェクト: eman226/carl
        private void Refine_Click(object sender, RoutedEventArgs e)
        {
            string fin  = " ";
            string fout = " ";

            System.Windows.Forms.MessageBox.Show("Choose raw file");
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                fin = openFileDialog1.FileName;
                System.Windows.Forms.MessageBox.Show(fin);
            }

            System.Windows.Forms.MessageBox.Show("Choose output file");
            OpenFileDialog openFileDialog2 = new OpenFileDialog();

            if (openFileDialog2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                fout = openFileDialog2.FileName;
                System.Windows.Forms.MessageBox.Show(fout);
            }

            string corp = File.ReadAllText(fin, Encoding.UTF8);                                  //read raw text file

            string[]      words     = corp.Split(new string[] { " " }, StringSplitOptions.None); //tokenize raw text file
            List <string> line      = new List <string>();                                       //initialize line, temporarily holds words for each line in new refined text
            string        path      = fout;                                                      //path of refined text
            string        temp_path = @"C:\Users\Emmanuel\Documents\Engineering_4\Degree\SpeechtoText\speech-to-text-wavenet-master\asset\transcripts\temp_path.txt";

            StreamWriter sw = File.AppendText(path);


            int    i = 0;
            string temp;

            while (i < words.Length)
            {
                StreamWriter temp_sw = File.AppendText(temp_path);
                for (int j = 0; j < 10; j++)
                {
                    for (int k = 0; k < 17; k++)
                    {
                        if ((i + k) < words.Length - 1)
                        {
                            line.Add(words[i + k]);
                        }
                    }

                    temp = string.Join(" ", line);

                    temp_sw.WriteLine(temp);

                    line.Clear();
                    i += 17;
                }
                temp_sw.Close();
                ProcessStartInfo pythonInfo = new ProcessStartInfo();
                Process          python;
                pythonInfo.FileName               = @"C:\Users\Emmanuel\AppData\Local\Programs\Python\Python35\python.exe";
                pythonInfo.Arguments              = @"C:\Users\Emmanuel\Documents\Engineering_4\Degree\SpeechtoText\speech-to-text-wavenet-master\subject_extract.py" + " " + temp_path;
                pythonInfo.CreateNoWindow         = false;
                pythonInfo.UseShellExecute        = false;
                pythonInfo.RedirectStandardOutput = true;
                ConsoleManager.Show();
                Console.WriteLine("Python Starting");
                python = Process.Start(pythonInfo);
                StreamReader myStreamReader = python.StandardOutput;
                string       myString       = myStreamReader.ReadLine();
                python.WaitForExit();
                python.Close();

                sw.WriteLine(myString);
                sw.WriteLine(File.ReadAllText(temp_path, Encoding.UTF8));
                sw.WriteLine(" ");
                sw.WriteLine(" ");
                sw.WriteLine(" ");

                File.WriteAllText(temp_path, String.Empty);//clear temporary file
            }

            sw.Close();
        }
コード例 #4
0
ファイル: NLPPage.xaml.cs プロジェクト: eman226/carl
        private void SpellCorrect_Click(object sender, RoutedEventArgs e)
        {
            ConsoleManager.Show();
            const int initialCapacity = 82765 * 2;
            const int maxEditDistance = 5;
            const int prefixLength    = 7;
            SymSpell  symSpell        = new SymSpell(initialCapacity, maxEditDistance, prefixLength);

            long memSize = GC.GetTotalMemory(true);
            // Load a frequency dictionary
            //wordfrequency_en.txt  ensures high correction quality by combining two data sources:
            //Google Books Ngram data  provides representative word frequencies (but contains many entries with spelling errors)
            //SCOWL — Spell Checker Oriented Word Lists which ensures genuine English vocabulary (but contained no word frequencies)
            string path  = @"C:\Users\Emmanuel\source\repos\Project-Carl\Project-CARL\WpfApp1\frequency_dictionary_en_82_765.txt";
            string dict2 = @"C:\Users\Emmanuel\source\repos\Project-Carl\Project-CARL\WpfApp1\unigram_freq.txt";


            long memDelta = GC.GetTotalMemory(true) - memSize;

            if (!symSpell.LoadDictionary(path, 0, 1))
            {
                Console.Error.WriteLine("\rFile not found: " + System.IO.Path.GetFullPath(path));
                Console.ReadKey();
                //return;
            }
            if (!symSpell.LoadDictionary(dict2, 0, 1))
            {
                Console.Error.WriteLine("\rFile not found: " + System.IO.Path.GetFullPath(path));
                Console.ReadKey();
                //return;
            }


            //Open textfile
            String correctionFile = "";

            System.Windows.Forms.MessageBox.Show("Choose file to Correct");
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                correctionFile = openFileDialog1.FileName;
                System.Windows.Forms.MessageBox.Show(correctionFile);
            }


            //read words into array/list
            string corp = File.ReadAllText(correctionFile, Encoding.UTF8);              //read raw text file

            string[] words = corp.Split(new string[] { " " }, StringSplitOptions.None); //tokenize raw text file
            List <SymSpell.SuggestItem> suggestedWord = null;                           //list of all corrected words
            List <string> correctedWords = new List <string>();                         //Output of the corrected words

            //submit word to symSpell
            for (int i = 0; i < words.Length; i++)
            {
                suggestedWord = (symSpell.Lookup(words[i], SymSpell.Verbosity.Closest));
                correctedWords.Add(suggestedWord.First().term);
            }

            //save words to file
            string fileName = System.IO.Path.GetRandomFileName() + ".txt"; //random file name for our corrected text

            //save the directory of the correction file we selected previously
            string pathString = System.IO.Path.GetDirectoryName(correctionFile);

            // Use Combine again to add the file name to the path.
            pathString = System.IO.Path.Combine(pathString, fileName);

            string tmpstring = "";

            foreach (string word in correctedWords)
            {
                tmpstring += (word + " ");
            }

            File.WriteAllText(pathString, tmpstring);
        }