Пример #1
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;
        }
Пример #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);
        }