// Call to Python code for agent/robot to move or speak
        private static void moveSpeak(string path, string pathResponseFile, int movementCode, string verbalManagerFile, string useraudio, string condition, string userid, DateTime time, int numturns, string robotIP, string enttype, bool agent)
        {
            try
            {
                if (agent)
                {
                    string agentAudioPath = "../data/agentAudio/" + generateSpeech(userid, condition, pathResponseFile, path);
                    if (enttype == "None")
                    {
                        ProcessThreadCollection currentThreads = Process.GetCurrentProcess().Threads;
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        string pythonexe  = Globals.pythonDirectory() + "python.exe";
                        string formatdate = string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", time);
                        if (useraudio == "")
                        {
                            useraudio = Globals.pythonDirectory() + "NaoNRIPrograms\\NicoAudio\\response.wav";
                        }
                        string agentAudio = agentAudioPath;
                        string gender     = SQLConditionGenderInfo.GetGender(userid);
                        string pythonargs = verbalManagerFile + userid + " " + formatdate + " " + useraudio + " " + agentAudio + " " + condition + " " + numturns.ToString() + " " + enttype + " " + gender;
                        ExternalMethodsCaller.PythonProcess(pythonexe, pythonargs);

                        Thread.Sleep(1000);
                    }

                    MyHub.Start(userid, agentAudioPath);
                }
                else
                {
                    string pythonexe  = Globals.pythonDirectory() + "python.exe";
                    string formatdate = string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", time);
                    if (useraudio == "")
                    {
                        useraudio = Globals.pythonDirectory() + "NaoNRIPrograms\\NicoAudio\\response.wav";
                    }
                    string pythonargs = verbalManagerFile + userid + " " + formatdate + " " + useraudio + " " + pathResponseFile + " " + condition + " " + numturns.ToString() + " " + robotIP + " " + enttype;
                    ExternalMethodsCaller.PythonProcess(pythonexe, pythonargs);
                }
            }
            catch (Exception error)
            {
                SQLLog.InsertLog(DateTime.Now, error.Message, error.StackTrace, "ResponseGeneration.moveSpeak", 1);
            }
        }
Exemple #2
0
        private static string generateSpeech(string userid, string condition, string pathResponseFile, string path)
        {
            // *********  generate wav file voicing the response *****************
            // Using Microsoft voices

            // initiate new instance of speech synthesizer
            // needs own separate dedicated thread...

            string response      = readResponse(pathResponseFile);
            string audioFilePath = "";

            SQLLog.InsertLog(DateTime.Now, "Beginning Thread", "Beginning Thread", "ResponseGeneration.moveSpeak", 1);
            Thread t = new Thread(() =>
            {
                try
                {
                    System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer();
                    string gender = SQLConditionGenderInfo.GetGender(userid);
                    bool makecopy = false;

                    if (synth != null)
                    {
                        if (gender.Contains("female"))
                        {
                            synth.SelectVoice("Microsoft Zira Desktop");
                        }
                        else
                        {
                            synth.SelectVoice("Microsoft David Desktop");
                        }

                        if (condition == "nonsocial" || condition == "social")
                        {
                            synth.SetOutputToWaveFile(path + "data\\agentAudio\\transformed.wav");
                            audioFilePath = "transformed.wav";
                            makecopy      = true;
                        }
                        else
                        {
                            synth.SetOutputToWaveFile(path + "data\\agentAudio\\response.wav");
                            audioFilePath = "response.wav";
                        }

                        synth.Speak(response);

                        if (makecopy)
                        {
                            string formatFileName = string.Format("data\\agentAudio\\transformed_{0:yyyy-MM-dd_hh-mm-ss-tt}.wav", DateTime.Now);
                            audioFilePath         = string.Format("transformed_{0:yyyy-MM-dd_hh-mm-ss-tt}.wav", DateTime.Now);                            synth.SetOutputToWaveFile(path + formatFileName);
                            synth.Speak(response);
                        }

                        synth.SetOutputToNull();
                    }
                }
                catch (Exception e)
                {
                    SQLLog.InsertLog(DateTime.Now, "Something went wrong in generating speech", "", "ResponseGeneration.generateSpeech", 1);
                }
            });

            t.Start();
            t.Join();

            Thread.Sleep(1000);

            return(audioFilePath);
        }