Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public RenderDocumentDirective BuildScrollingSequenceDirective(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()}",
                    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 AlexaBackground
                                {
                                    Width    = "100vw",
                                    Height   = "100vh",
                                    Position = new APLValue <string>("absolute"),
                                    BackgroundVideoSource = new APLValue <VideoSource>
                                    {
                                        Value = new VideoSource
                                        {
                                            Uri         = new APLValue <Uri>(new Uri("https://bestilldemo.azurewebsites.net/images/gifbg.gif")),
                                            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 Sequence
                                {
                                    Id            = "mySequence",
                                    Width         = "100vw",
                                    Height        = "100vh",
                                    PaddingLeft   = 60,
                                    PaddingRight  = 60,
                                    PaddingBottom = 140,
                                    Items         = new APLValue <List <APLComponent> >
                                    {
                                        Value = items
                                    },
                                    OnMount = new APLValue <IList <APLCommand> >
                                    {
                                        Value = new List <APLCommand>
                                        {
                                            new SpeakList
                                            {
                                                ComponentId      = "mySequence",
                                                Start            = new APLValue <int>(0),
                                                Count            = new APLValue <int>(prayers.Length),
                                                MinimumDwellTime = new APLValue <int?>(30000),
                                                ScreenLock       = new APLValue <bool?>(true),
                                                Align            = new APLValue <ItemAlignment?>(ItemAlignment.Center),
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            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);
        }
Exemplo n.º 3
0
 public Text(string text)
 {
     Content = new APLValue <string>(text);
 }