Ejemplo n.º 1
0
        public RenderDocumentDirective BuildScrollingSequenceWithVoiceDirective(string sentences, string bg = "", string title = "", string subtitle = "")
        {
            if (!string.IsNullOrEmpty(bg))
            {
                bgUrl = bg;
            }
            var items   = new List <APLComponent>();
            var prayers = sentences.Replace("\n", "").Split(",");

            for (int i = 0; i < prayers.Length; i++)
            {
                items.Add(new Text()
                {
                    Id                = $"itm{i.ToString()}",
                    Width             = "100vw",
                    Height            = "100vh",
                    PaddingLeft       = 40,
                    PaddingRight      = 40,
                    TextAlign         = new APLValue <string>("center"),
                    AlignSelf         = new APLValue <string>("center"),
                    TextAlignVertical = new APLValue <string>("center"),
                    Content           = APLValue.To <string>("${payload.script.properties.text" + i.ToString() + "}"),
                    //Speech = APLValue.To<string>("${payload.script.properties.speech" + i.ToString() + "}")
                });
            }

            var    ppt    = new Dictionary <string, object>();
            Speech speech = null;

            for (int i = 0; i < prayers.Length; i++)
            {
                speech = new Speech(new PlainText($"{i + 1}. {prayers[i]}"));
                ppt.Add($"ssml{i}", speech.ToXml());
            }

            var ff = new List <APLTransformer>();

            for (int i = 0; i < prayers.Length; i++)
            {
                ff.Add(APLTransformer.SsmlToText($"ssml{i}", $"text{i}"));
                ff.Add(APLTransformer.SsmlToSpeech($"ssml{i}", $"speech{i}"));
            }

            var layout = new Layout
            {
                Parameters = new List <Parameter> {
                    new Parameter("payload")
                },

                Items = new Container[]
                {
                    new Container
                    {
                        Height = "100vh",
                        Items  = new APLValue <List <APLComponent> >
                        {
                            Value = new List <APLComponent>
                            {
                                //new Video
                                //{
                                //   Width = "100vw",
                                //   Height = "100vh",
                                //   Position = new APLValue<string>("absolute"),
                                //   Scale = new APLValue<Scale>(Scale.BestFill),
                                //   Autoplay = new APLValue<bool?>(true),
                                //   AudioTrack = new APLValue<string>("none"),
                                //   //Source = new APLValue<string>("https://bestilldemo.azurewebsites.net/images/gifbg.gif")
                                //   Source = new APLValue<IList<VideoSource>>
                                //   {
                                //       Value = new List<VideoSource>
                                //       {
                                //           new VideoSource
                                //           {
                                //               RepeatCount = new APLValue<int?>(10),
                                //               Uri = new APLValue<Uri>(new Uri("https://bestilldemo.azurewebsites.net/images/soundwave.mp4"))
                                //           }
                                //       }
                                //   }
                                //},
                                new AlexaBackground
                                {
                                    Width                 = "100vw",
                                    Height                = "100vh",
                                    Position              = new APLValue <string>("absolute"),
                                    VideoAudioTrack       = new APLValue <string>("none"),
                                    BackgroundVideoSource = new APLValue <VideoSource>
                                    {
                                        Value = new VideoSource
                                        {
                                            Uri         = new APLValue <Uri>(new Uri("https://bestilldemo.azurewebsites.net/images/soundwave.mp4")),
                                            RepeatCount = new APLValue <int?>(10)
                                        }
                                    },
                                    VideoAutoPlay = new APLValue <bool?>(true)
                                },

                                new AlexaHeader
                                {
                                    HeaderTitle            = new APLValue <string>(title),
                                    HeaderSubtitle         = new APLValue <string>(subtitle),
                                    HeaderAttributionImage = new APLValue <string>(logoUrl)
                                },

                                new Pager
                                {
                                    Id            = "myPager",
                                    Width         = "100vw",
                                    Height        = "100vh",
                                    PaddingBottom = 140,
                                    AlignSelf     = new APLValue <string>("center"),
                                    Items         = new APLValue <List <APLComponent> >
                                    {
                                        Value = items
                                    },
                                    OnMount = new APLValue <IList <APLCommand> >
                                    {
                                        Value = new List <APLCommand>
                                        {
                                            new AutoPage
                                            {
                                                ComponentId       = "myPager",
                                                ScreenLock        = new APLValue <bool?>(true),
                                                DelayMilliseconds = new APLValue <int?>(40000),
                                                Count             = new APLValue <int?>(items.Count),
                                                Duration          = new APLValue <int?>(40000),
                                            }

                                            //new Parallel
                                            //{
                                            //    Commands= new APLValue<IList<APLCommand>>
                                            //    {
                                            //        Value = new List<APLCommand>
                                            //        {
                                            //            new SpeakList
                                            //            {
                                            //                ComponentId = "myPager",
                                            //                Start = new APLValue<int>(0),
                                            //                Count = new APLValue<int>(items.Count),
                                            //                MinimumDwellTime = new APLValue<int?>(40000),
                                            //                ScreenLock = new APLValue<bool?>(true),
                                            //                Align = new APLValue<ItemAlignment?>(ItemAlignment.Center),
                                            //            },

                                            //            new AutoPage
                                            //            {
                                            //                ComponentId = "myPager",
                                            //                ScreenLock = new APLValue<bool?>(true),
                                            //                DelayMilliseconds = new APLValue<int?>(40000),
                                            //                Count = new APLValue<int?>(items.Count),
                                            //                Duration = new APLValue<int?>(40000),
                                            //            }
                                            //        }
                                            //    }
                                            //}
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var renderDocument = new RenderDocumentDirective
            {
                Token    = "randomToken",
                Document = new APLDocument
                {
                    MainTemplate = layout,
                    Version      = APLDocumentVersion.V1_3,
                    Imports      = new List <Import>
                    {
                        new Import
                        {
                            Name    = "alexa-layouts",
                            Version = "1.1.0"
                        }
                    }
                },
                DataSources = new Dictionary <string, APLDataSource>
                {
                    {
                        "script", new ObjectDataSource
                        {
                            Properties   = ppt,
                            Transformers = ff
                        }
                    }
                }
            };

            return(renderDocument);
        }
Ejemplo n.º 2
0
 public static void AddKaraoke(Speech speech, ObjectDataSource dataSource)
 {
     dataSource.Properties.Add("ssml", speech.ToXml());
     dataSource.Transformers.Add(APLTransformer.SsmlToText("ssml", "text"));
     dataSource.Transformers.Add(APLTransformer.SsmlToSpeech("ssml", "speech"));
 }
Ejemplo n.º 3
0
        public RenderDocumentDirective BuildScrollingTextDirective(string sentences, string bg = "", string title = "", string subtitle = "")
        {
            if (!string.IsNullOrEmpty(bg))
            {
                bgUrl = bg;
            }
            var speech = new Speech(new PlainText(sentences));

            var layout = new Layout
            {
                Parameters = new List <Parameter> {
                    new Parameter("payload")
                },

                Items = new Container[]
                {
                    new Container
                    {
                        Height = "100vh",
                        Items  = new APLValue <List <APLComponent> >
                        {
                            Value = new List <APLComponent>
                            {
                                new Image
                                {
                                    Width    = "100vw",
                                    Height   = "100vh",
                                    Position = new APLValue <string>("absolute"),
                                    Scale    = new APLValue <Scale?>(Scale.BestFill),
                                    Source   = new APLValue <string>(bgUrl)
                                },

                                new AlexaHeader
                                {
                                    HeaderTitle            = new APLValue <string>(title),
                                    HeaderSubtitle         = new APLValue <string>(subtitle),
                                    HeaderAttributionImage = new APLValue <string>(logoUrl)
                                },

                                new ScrollView(
                                    new Text(sentences)
                                {
                                    FontSize  = "40dp",
                                    TextAlign = "Center",
                                    Id        = "talker",
                                    Content   = APLValue.To <string>("${payload.script.properties.text}"),
                                    Speech    = APLValue.To <string>("${payload.script.properties.speech}"),
                                    OnMount   = new APLValue <IList <APLCommand> >
                                    {
                                        Value = new List <APLCommand>
                                        {
                                            new SpeakItem
                                            {
                                                ComponentId   = "talker",
                                                HighlightMode = new APLValue <HighlightMode?>(HighlightMode.Line)
                                            }
                                        }
                                    }
                                }
                                    )
                                {
                                    Width = "100vw", Height = "100vh", PaddingLeft = 60, PaddingRight = 60, PaddingBottom = 140
                                }
                            }
                        }
                    }
                }
            };

            var renderDocument = new RenderDocumentDirective
            {
                Token    = "randomToken",
                Document = new APLDocument
                {
                    MainTemplate = layout,
                    Version      = APLDocumentVersion.V1_3,
                    Imports      = new List <Import>
                    {
                        new Import
                        {
                            Name    = "alexa-layouts",
                            Version = "1.1.0"
                        }
                    }
                },
                DataSources = new Dictionary <string, APLDataSource>
                {
                    {
                        "script", new ObjectDataSource
                        {
                            Properties = new Dictionary <string, object>
                            {
                                { "ssml", speech.ToXml() }
                            },
                            Transformers = new List <APLTransformer> {
                                APLTransformer.SsmlToText(
                                    "ssml",
                                    "text"),
                                APLTransformer.SsmlToSpeech(
                                    "ssml",
                                    "speech")
                            }
                        }
                    }
                }
            };

            return(renderDocument);
        }