Ejemplo n.º 1
0
        private List<string> _prepare_moh(FSOutbound outboundClient)
        {
            List<string> sound_files = new List<string>(); //[]
            if (!Util.IsUrlExist(moh_sound))
            {
                DirectoryInfo file = new DirectoryInfo(moh_sound);
                if (Util.IsFileExist(moh_sound))
                {
                    moh_sound = string.Format("file_string://{0}", moh_sound);
                    sound_files.Add(moh_sound);
                }
            }
            else
            {

                XElement doc = null;
                if (!string.IsNullOrEmpty(moh_sound))
                {
                    try
                    {
                        string response = outboundClient.SendToUrl(moh_sound, outboundClient.session_params, method);
                        doc = XElement.Parse(response);
                    }
                    catch (Exception ex)
                    {
                    }
                    if (doc.Name != "Response")
                        return sound_files;

                    // build play string from remote restxml
                    foreach (XElement element in doc.Elements())
                    {
                        //Play element
                        if (element.Name == "Play")
                        {
                            Play child = new Play();
                            child.ParseElement(element);
                            string sound_file = child.SoundFilePath;
                            if (!string.IsNullOrEmpty(sound_file))
                            {
                                int loop = child.LoopTimes;
                                if (loop == 0)
                                    loop = MAX_LOOPS;  //Add a high number to Play infinitely
                                //Play the file loop number of times
                                for (int i = 0; i < loop; i++)
                                {
                                    sound_files.Add(sound_file);
                                }
                                // Infinite Loop, so ignore other children
                                if (loop == MAX_LOOPS)
                                    break;
                            }
                        }
                        //Say element
                        else if (element.Name == "Say")
                        {
                            Say child = new Say();
                            child.ParseElement(element);
                           // child.Execute(outboundClient);
                            //sound_files.Add(pause_str);
                        }

                         //Redirect element
                        else if (element.Name == "Redirect")
                        {
                            Redirect child = new Redirect();
                            child.ParseElement(element);
                            child.Execute(outboundClient);
                        }
                    }
                }
            }
            return sound_files;
        }
Ejemplo n.º 2
0
        private List <string> _prepare_play_string(FSOutbound outboundClient, string remote_url)
        {
            List <string> sound_files = new List <string>();

            if (!string.IsNullOrEmpty(remote_url))
            {
                return(sound_files);
            }
            try
            {
                string   response = outboundClient.SendToUrl(remote_url, outboundClient.session_params, this.method);
                XElement doc      = XElement.Load(response);
                if (doc.Name != "Response")
                {
                    return(sound_files);
                }

                // build play string from remote restxml
                foreach (XElement ele in doc.Nodes())
                {
                    //Play element
                    if (ele.Name == "Play")
                    {
                        var child = new Play();
                        child.ParseElement(ele);
                        string sound_file = child.SoundFilePath;
                        if (!string.IsNullOrEmpty(sound_file))
                        {
                            var loop = child.LoopTimes;
                            if (loop == 0)
                            {
                                loop = 1000;  // Add a high number to Play infinitely
                            }
                            // Play the file loop number of times
                            for (int i = 1; i < loop; i++)
                            {
                                sound_files.Add(sound_file);
                            }
                            //Infinite Loop, so ignore other children
                            if (loop == 1000)
                            {
                                break;
                            }
                        }
                    }
                    //Say element
                    else if (ele.Name == "Say")
                    {
                        var child = new Say();
                        child.ParseElement(ele);
                        var text = child.Text;
                        // escape simple quote
                        text = text.Replace("'", "\\'");
                        var loop    = child.loop_times;
                        var engine  = child.engine;
                        var voice   = child.voice;
                        var say_str = string.Format("say:{0}:{1}:'{2}'", engine, voice, text);
                        for (int i = 1; i < loop; i++)
                        {
                            sound_files.Add(say_str);
                        }
                    }
                    //Pause element
                    else if (ele.Name == "Pause")
                    {
                        var child = new Pause();
                        child.ParseElement(ele);
                        var    pause_secs = child.length;
                        string pause_str  = string.Format("file_string://silence_stream://{0}", (pause_secs * 1000));
                        sound_files.Add(pause_str);
                    }
                }
            }
            catch (Exception e)
            {
            }
            return(sound_files);
        }
Ejemplo n.º 3
0
        private List<string> _prepare_play_string(FSOutbound outboundClient, string remote_url)
        {
            List<string> sound_files = new List<string>();
            if (!string.IsNullOrEmpty(remote_url))
                return sound_files;
            try
            {
                string response = outboundClient.SendToUrl(remote_url, outboundClient.session_params, this.method);
                XElement doc = XElement.Load(response);
                if (doc.Name != "Response")
                    return sound_files;

                // build play string from remote restxml
                foreach (XElement ele in doc.Nodes())
                {
                    //Play element
                    if (ele.Name == "Play")
                    {
                        var child = new Play();
                        child.ParseElement(ele);
                        string sound_file = child.SoundFilePath;
                        if (!string.IsNullOrEmpty(sound_file))
                        {
                            var loop = child.LoopTimes;
                            if (loop == 0)
                                loop = 1000;  // Add a high number to Play infinitely
                            // Play the file loop number of times
                            for (int i = 1; i < loop; i++)
                                sound_files.Add(sound_file);
                            //Infinite Loop, so ignore other children
                            if (loop == 1000)
                                break;
                        }
                    }
                    //Say element
                    else if (ele.Name == "Say")
                    {
                        var child = new Say();
                        child.ParseElement(ele);
                        var text = child.Text;
                        // escape simple quote
                        text = text.Replace("'", "\\'");
                        var loop = child.loop_times;
                        var engine = child.engine;
                        var voice = child.voice;
                        var say_str = string.Format("say:{0}:{1}:'{2}'", engine, voice, text);
                        for (int i = 1; i < loop; i++)
                            sound_files.Add(say_str);
                    }
                    //Pause element
                    else if (ele.Name == "Pause")
                    {
                        var child = new Pause();
                        child.ParseElement(ele);
                        var pause_secs = child.length;
                        string pause_str = string.Format("file_string://silence_stream://{0}", (pause_secs * 1000));
                        sound_files.Add(pause_str);
                    }
                }
            }
            catch (Exception e)
            {
            }
            return sound_files;
        }
Ejemplo n.º 4
0
        private List <string> _prepare_moh(FSOutbound outboundClient)
        {
            List <string> sound_files = new List <string>(); //[]

            if (!Util.IsUrlExist(moh_sound))
            {
                DirectoryInfo file = new DirectoryInfo(moh_sound);
                if (Util.IsFileExist(moh_sound))
                {
                    moh_sound = string.Format("file_string://{0}", moh_sound);
                    sound_files.Add(moh_sound);
                }
            }
            else
            {
                XElement doc = null;
                if (!string.IsNullOrEmpty(moh_sound))
                {
                    try
                    {
                        string response = outboundClient.SendToUrl(moh_sound, outboundClient.session_params, method);
                        doc = XElement.Parse(response);
                    }
                    catch (Exception ex)
                    {
                    }
                    if (doc.Name != "Response")
                    {
                        return(sound_files);
                    }

                    // build play string from remote restxml
                    foreach (XElement element in doc.Elements())
                    {
                        //Play element
                        if (element.Name == "Play")
                        {
                            Play child = new Play();
                            child.ParseElement(element);
                            string sound_file = child.SoundFilePath;
                            if (!string.IsNullOrEmpty(sound_file))
                            {
                                int loop = child.LoopTimes;
                                if (loop == 0)
                                {
                                    loop = MAX_LOOPS;  //Add a high number to Play infinitely
                                }
                                //Play the file loop number of times
                                for (int i = 0; i < loop; i++)
                                {
                                    sound_files.Add(sound_file);
                                }
                                // Infinite Loop, so ignore other children
                                if (loop == MAX_LOOPS)
                                {
                                    break;
                                }
                            }
                        }
                        //Say element
                        else if (element.Name == "Say")
                        {
                            Say child = new Say();
                            child.ParseElement(element);
                            // child.Execute(outboundClient);
                            //sound_files.Add(pause_str);
                        }

                        //Redirect element
                        else if (element.Name == "Redirect")
                        {
                            Redirect child = new Redirect();
                            child.ParseElement(element);
                            child.Execute(outboundClient);
                        }
                    }
                }
            }
            return(sound_files);
        }