Пример #1
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string             say;
            ConditionVariables statementvars;

            if (FromString(userdata, out say, out statementvars))
            {
                string             errlist = null;
                ConditionVariables vars    = statementvars.ExpandAll(ap.functions, statementvars, out errlist);

                if (errlist == null)
                {
                    bool wait = vars.GetInt(waitname, 0) != 0;
                    Audio.AudioQueue.Priority priority = Audio.AudioQueue.GetPriority(vars.GetString(priorityname, "Normal"));
                    string start  = vars.GetString(startname);
                    string finish = vars.GetString(finishname);
                    string voice  = vars.Exists(voicename) ? vars[voicename] : (ap.VarExist(globalvarspeechvoice) ? ap[globalvarspeechvoice] : "Default");

                    int vol = vars.GetInt(volumename, -999);
                    if (vol == -999)
                    {
                        vol = ap.variables.GetInt(globalvarspeechvolume, 60);
                    }

                    int rate = vars.GetInt(ratename, -999);
                    if (rate == -999)
                    {
                        rate = ap.variables.GetInt(globalvarspeechrate, 0);
                    }

                    string culture = vars.Exists(culturename) ? vars[culturename] : (ap.VarExist(globalvarspeechculture) ? ap[globalvarspeechculture] : "Default");

                    bool literal   = vars.GetInt(literalname, 0) != 0;
                    bool dontspeak = vars.GetInt(dontspeakname, 0) != 0;

                    Audio.SoundEffectSettings ses = new Audio.SoundEffectSettings(vars);       // use the rest of the vars to place effects

                    if (!ses.Any && !ses.OverrideNone && ap.VarExist(globalvarspeecheffects))  // if can't see any, and override none if off, and we have a global, use that
                    {
                        vars = new ConditionVariables(ap[globalvarspeecheffects], ConditionVariables.FromMode.MultiEntryComma);
                    }

                    string expsay;
                    if (ap.functions.ExpandString(say, out expsay) != EDDiscovery.ConditionFunctions.ExpandResult.Failed)
                    {
                        if (!literal)
                        {
                            expsay = expsay.PickOneOfGroups(rnd);       // expand grouping if not literal
                        }
                        ap["SaySaid"] = expsay;

                        if ((ap.VarExist("SpeechDebug") && ap["SpeechDebug"].Contains("Print")))
                        {
                            ap.actioncontroller.LogLine("Say: " + expsay);
                            expsay = "";
                        }

                        if (dontspeak)
                        {
                            expsay = "";
                        }

                        System.IO.MemoryStream ms = ap.actioncontroller.DiscoveryForm.SpeechSynthesizer.Speak(expsay, culture, voice, rate);

                        if (ms != null)
                        {
                            Audio.AudioQueue.AudioSample audio = ap.actioncontroller.DiscoveryForm.AudioQueueSpeech.Generate(ms, vars, true);

                            if (audio != null)
                            {
                                if (start != null && start.Length > 0)
                                {
                                    audio.sampleStartTag = new AudioEvent {
                                        apr = ap, eventname = start, triggername = "onSayStarted"
                                    };
                                    audio.sampleStartEvent += Audio_sampleEvent;
                                }
                                if (wait || (finish != null && finish.Length > 0))       // if waiting, or finish call
                                {
                                    audio.sampleOverTag = new AudioEvent()
                                    {
                                        apr = ap, wait = wait, eventname = finish, triggername = "onSayFinished"
                                    };
                                    audio.sampleOverEvent += Audio_sampleEvent;
                                }

                                ap.actioncontroller.DiscoveryForm.AudioQueueSpeech.Submit(audio, vol, priority);

                                return(!wait);       //False if wait, meaning terminate and wait for it to complete, true otherwise, continue
                            }
                            else
                            {
                                ap.ReportError("Say could not create audio, check Effects settings");
                            }
                        }
                    }
                    else
                    {
                        ap.ReportError(expsay);
                    }
                }
                else
                {
                    ap.ReportError(errlist);
                }
            }
            else
            {
                ap.ReportError("Say command line not in correct format");
            }


            return(true);
        }
Пример #2
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string             pathunexpanded;
            ConditionVariables statementvars;

            if (FromString(userdata, out pathunexpanded, out statementvars))
            {
                string             errlist = null;
                ConditionVariables vars    = statementvars.ExpandAll(ap.functions, statementvars, out errlist);

                if (errlist == null)
                {
                    string path;
                    if (ap.functions.ExpandString(pathunexpanded, out path) != ConditionFunctions.ExpandResult.Failed)
                    {
                        if (System.IO.File.Exists(path))
                        {
                            bool wait = vars.GetInt(waitname, 0) != 0;
                            Audio.AudioQueue.Priority priority = Audio.AudioQueue.GetPriority(vars.GetString(priorityname, "Normal"));
                            string start  = vars.GetString(startname);
                            string finish = vars.GetString(finishname);

                            int vol = vars.GetInt(volumename, -999);
                            if (vol == -999)
                            {
                                vol = ap.variables.GetInt(globalvarplayvolume, 60);
                            }

                            Audio.SoundEffectSettings ses = new Audio.SoundEffectSettings(vars);     // use the rest of the vars to place effects

                            if (!ses.Any && !ses.OverrideNone && ap.VarExist(globalvarplayeffects))  // if can't see any, and override none if off, and we have a global, use that
                            {
                                vars = new ConditionVariables(ap[globalvarplayeffects], ConditionVariables.FromMode.MultiEntryComma);
                            }

                            Audio.AudioQueue.AudioSample audio = ap.actioncontroller.DiscoveryForm.AudioQueueWave.Generate(path, vars);

                            if (audio != null)
                            {
                                if (start != null && start.Length > 0)
                                {
                                    audio.sampleStartTag = new AudioEvent {
                                        apr = ap, eventname = start, triggername = "onPlayStarted"
                                    };
                                    audio.sampleStartEvent += Audio_sampleEvent;
                                }
                                if (wait || (finish != null && finish.Length > 0))       // if waiting, or finish call
                                {
                                    audio.sampleOverTag = new AudioEvent()
                                    {
                                        apr = ap, wait = wait, eventname = finish, triggername = "onPlayFinished"
                                    };
                                    audio.sampleOverEvent += Audio_sampleEvent;
                                }

                                ap.actioncontroller.DiscoveryForm.AudioQueueWave.Submit(audio, vol, priority);
                                return(!wait);       //False if wait, meaning terminate and wait for it to complete, true otherwise, continue
                            }
                            else
                            {
                                ap.ReportError("Play could not create audio, check audio file format is supported and effects settings");
                            }
                        }
                        else
                        {
                            ap.ReportError("Play could not find file " + path);
                        }
                    }
                    else
                    {
                        ap.ReportError(path);
                    }
                }
                else
                {
                    ap.ReportError(errlist);
                }
            }
            else
            {
                ap.ReportError("Play command line not in correct format");
            }

            return(true);
        }