Esempio n. 1
0
    public static IEnumerable <CSVInput> GetAllQuestions(IConfig c)
    {
        List <CSVInput> ret = new List <CSVInput>();

        foreach (string inCSVMask in c.FileInPut.CSVFiles)
        {
            Console.WriteLine(inCSVMask);

            string[] parts = inCSVMask.Split('|');
            string[] files = Directory.GetFiles(parts[0], parts[1]);

            foreach (string f in files)
            {
                Console.WriteLine(f);
                CSVInput        csv = new CSVInput();
                List <CSVInput> tmp = csv.GetRecs(f).ToList();

                int lnCtr = 0;

                foreach (CSVInput fn in tmp)
                {
                    fn.SourceCSVFile = f;
                    fn.FileLineNum   = lnCtr++;
                }

                ret.AddRange(tmp);
            }
        }

        return(ret);
    } // GetAllQuestions()
Esempio n. 2
0
        public void TestExpectingNoExceptionWhenFileExists()
        {
            string   filepath = @"D:\a\DummyReviews\DummyReviews\SenderTests\TestSample.csv";
            CSVInput csvInput = new CSVInput(filepath);

            Assert.False(csvInput.InputExceptionHandler());
        }
Esempio n. 3
0
        public void TestExpectingExceptionWhenFileCouldNotBeFoundOrOpened()
        {
            string   filepath = @"D:\a\DummyReviews\DummyReviews\SenderTests\TestSample2.csv";
            CSVInput csvInput = new CSVInput(filepath);

            Assert.Throws <FileNotFoundException>(() => csvInput.InputExceptionHandler());
        }
Esempio n. 4
0
        public void TestExpectingValidFilepathAssignmentToClassMemberWhenCalledWithValidFilepath()
        {
            string   filepath = @"EmptySample.csv";
            CSVInput csvInput = new CSVInput(filepath);

            Assert.Equal("EmptySample.csv", csvInput.filepath);
        }
Esempio n. 5
0
        public void TestExpectingOutputToBeEmptyWhenCalledWithFilePathWhereFileIsEmpty()
        {
            string   filepath = @"D:\a\DummyReviews\DummyReviews\SenderTests\EmptySample.csv";
            CSVInput csvInput = new CSVInput(filepath);
            List <List <string> > testOutput = (List <List <string> >)csvInput.ReadInput();

            Assert.True(testOutput.Count == 0);
        }
        public static void TestExpectingAnObjectOfCSVInputTypeToBeAssignedToControllersInputInterface()
        {
            CSVInput      csvInput   = new CSVInput("TestSample.csv");
            ConsoleOutput output     = new ConsoleOutput();
            Controller    controller = new Controller(csvInput, output);
            var           type       = controller.inputInterface.GetType();

            Debug.Assert(type == csvInput.GetType());
        }
        public void TestExpectingAppropriateReadInputMethodToBeCalledWhenCalled()
        {
            string        filepath      = @"D:\a\DummyReviews\DummyReviews\SenderTests\TestSample.csv";
            CSVInput      csvInput      = new CSVInput(filepath);
            ConsoleOutput consoleOutput = new ConsoleOutput();
            Controller    controller    = new Controller(csvInput, consoleOutput);
            var           parsedinput   = (List <List <string> >)controller.ReadInput();

            Assert.Equal("sampledata", parsedinput[0][0]);
        }
Esempio n. 8
0
        public void TestExpectingCSVFileToBeReadWhenCalledWithFilePath()
        {
            string   filepath = @"D:\a\DummyReviews\DummyReviews\SenderTests\TestSample.csv";
            CSVInput csvInput = new CSVInput(filepath);
            List <List <string> > testOutput = (List <List <string> >)csvInput.ReadInput();

            Debug.Assert(testOutput[0][0] == "sampledata");
            Console.WriteLine(testOutput[0][0]);
            Console.WriteLine("test");
        }
        public void TestExpectingAppropriateWriteOutputMethodToBeCalledWhenCalledWithTwoDimensionalIEnumerable()
        {
            string            filepath      = @"D:\a\DummyReviews\DummyReviews\SenderTests\TestSample.csv";
            CSVInput          csvInput      = new CSVInput(filepath);
            MockConsoleOutput consoleOutput = new MockConsoleOutput();
            Controller        controller    = new Controller(csvInput, consoleOutput);
            var parsedinput = (List <List <string> >)controller.ReadInput();

            controller.WriteOutput(parsedinput);
            Assert.Equal("sampledata", consoleOutput.OutputOnConsole[0][0]);
        }
Esempio n. 10
0
        /// <summary>
        /// Do we have the input type to convert?
        /// </summary>
        /// <returns>true - its covered : otherwise false</returns>
        internal virtual bool IsInputTypeCovered()
        {
            //
            // Is it just a straight conversion
            //
            switch (InPutType)
            {
            case "csv":
                InputReader = new CSVInput(_filefullPath);
                return(true);

            case "xml":
                InputReader = XMLPatternsInput.AssignXMLReader(InputPatternType, _filefullPath);
                return(InputReader != null);

            case "json":
                InputReader = JSONPatternsInput.AssignJSONReader(InputPatternType, _filefullPath);
                return(InputReader != null);

            default:
                Problem = new Exception(string.Format(FileInputConstants.NoValidExtension, InputConnection));
                return(false);
            }
        }
Esempio n. 11
0
        static async Task Main(string[] args)
        {
            string configName = "";

            if (args.Length > 0)
            {
                configName = args[0];
            }
            else
            {
                configName = "_samples/_bin/config_sample.json";
            }

            Console.WriteLine($"{configName}");

            if (!File.Exists(configName))
            {
                Console.WriteLine($"File does not exist: {configName}");
                Environment.Exit((int)RetCodes.ConfigFileNotFound);
            }

            IConfig c = new Config();

            try
            {
                c = JsonConvert.DeserializeObject <Config>(File.ReadAllText(configName));
                c.Authentication = JsonConvert.DeserializeObject <Authentication>(File.ReadAllText(c.FileInPut.authFile));
            }
            catch (Exception e)
            {
                Environment.Exit((int)RetCodes.InvalidConfigInit);
            }

            ILogger lg = new Logger();

            lg.LogFile = String.Concat(c.FileOutPut.LogFolder, "/runLog.txt");
            lg.Write(new string('-', 50));
            lg.Write($"{DateTime.Now}");

            IEnumerable <CSVInput> allQuests = CSVInput.GetAllQuestions(c);

            // build wav output
            int fileCntr = c.FileOutPut.StartOutNum;
            int numRecs  = allQuests.Where(x => x.IsActive.ToUpper() == "TRUE").Count();

            if (numRecs == 0)
            {
                Environment.Exit((int)RetCodes.NoRecs);
            }

            int       numZerosCalc = Convert.ToInt32(Math.Log10(numRecs) + 1);
            int       numZeros     = Math.Max(c.FileOutPut.OutNumPad, numZerosCalc);
            SoundUtil sndUtil      = new SoundUtil();

            const int QUESTION = 0;
            const int ANSWER   = 1;

            TTS_QA[] ttsQA           = { new TTS_QA(), new TTS_QA() };
            string   outFileNameBase = "";

            foreach (CSVInput ln in allQuests.Where(x => x.IsActive.ToUpper() == "TRUE"))
            {
                lg.Write("-".PadLeft(20, '-'));
                lg.Write($"Src file: {ln.SourceCSVFile}, Line#: {ln.FileLineNum}");

                outFileNameBase = string.Format(@"{0}/{1}.wav", c.FileOutPut.SoundFolder
                                                , c.FileOutPut.WAVPrefix.Replace("{#}", fileCntr.ToString().PadLeft(numZeros, '0')));

                int    pauseSec  = Convert.ToInt32(ln.AnswerWaitSeconds) * 1000;
                string pauseText = $"<break time=\"{pauseSec}ms\"/>";

                string question = $"{ln.Question} {pauseText}";

                ttsQA[QUESTION] = new TTS_QA {
                    QAText = question,
                    Lang   = ln.QuesLang, ProsodyRate = ln.QuesProsodyRate, OutFile = outFileNameBase.Replace(".wav", "_ques.wav")
                };

                ttsQA[ANSWER] = new TTS_QA {
                    QAText = ln.Answer,
                    Lang   = ln.AnsLang, ProsodyRate = ln.AnsProsodyRate, OutFile = outFileNameBase.Replace(".wav", "_resp.wav")
                };                                                                                                              // append "resp" for sorting purposes if Q/A files are separate

                foreach (TTS_QA qa in ttsQA)
                {
                    TextToSpeech t = new TextToSpeech();

                    ISound sndOut = new SoundOutput(c.SoundDefault);
                    t.Sound = sndOut;

                    t.TextIn         = qa.QAText;
                    t.Sound.Language = sndUtil.GetSoundProp(qa.Lang, c.SoundDefault.Language);

                    // random speaker from avail list
                    string spkr = sndUtil.GetRandSpeakerName(t.Sound.Language, c.SoundDefault.Speakers);
                    t.Sound.Speaker     = sndUtil.GetSoundProp(spkr, c.SoundDefault.Speaker);
                    t.Sound.ProsodyRate = sndUtil.GetSoundProp(qa.ProsodyRate, c.SoundDefault.ProsodyRate);

                    t.FileOut = qa.OutFile;

                    if (!string.IsNullOrEmpty(t.TextIn))
                    {
                        lg.Write($"Spkr: {t.Sound.Speaker}, Text: {t.TextIn.Substring(0, Math.Min(t.TextIn.Length, 20))} ... -> {t.FileOut}");
                    }

                    while (File.Exists(t.FileOut))
                    {
                        File.Delete(t.FileOut);
                    }

                    await t.OutPutTTS(c.Authentication);
                }

                if (!c.FileOutPut.SplitQAFiles) // need to merge them
                {
                    var ques = new AudioFileReader(ttsQA[QUESTION].OutFile);
                    var ans  = new AudioFileReader(ttsQA[ANSWER].OutFile);

                    File.Delete(outFileNameBase);

                    ConcatenatingSampleProvider playlist = new ConcatenatingSampleProvider(new[] { ques, ans });

                    lg.Write($"\n---> Merging {ttsQA[QUESTION].OutFile} and {ttsQA[ANSWER].OutFile} to {outFileNameBase}");

                    WaveFileWriter.CreateWaveFile16(outFileNameBase, playlist);

                    ques.Dispose();
                    ans.Dispose();

                    File.Delete(ttsQA[QUESTION].OutFile);
                    File.Delete(ttsQA[ANSWER].OutFile);
                }


                fileCntr++;
            }

            // update config file with last counter ref
            String cOut    = File.ReadAllText(configName);
            string incrTxt = $"\"StartOutNum\":";

            cOut = Regex.Replace(cOut, $"{incrTxt}\\s+\"\\d+\""
                                 , $"{incrTxt} \"{fileCntr.ToString()}\"");

            File.WriteAllText(configName, cOut);

            lg.Write("Done");
            lg.Dispose();

            Console.WriteLine($"Done");
            Environment.Exit((int)RetCodes.Success);
        }