public CEKResponse ToClovaResponse() { var response = new CEKResponse(); // normal foreach (var output in OutputObjects .Where(output => output.TargetPlatform == Platform.All || output.TargetPlatform == Platform.Clova)) { if (output.Type == OutputType.Text) { response.AddText(output.Value); } else if (output.Type == OutputType.Url) { response.AddUrl(output.Value); } else if (output.Type == OutputType.Break) { if (output.BreakTime <= 5) { response.AddUrl($"https://himanago.github.io/silent-mp3/silent_{output.BreakTime}s.mp3"); } else { response.AddUrl($"https://himanago.github.io/silent-mp3/silent_5s.mp3"); response.AddUrl($"https://himanago.github.io/silent-mp3/silent_{output.BreakTime - 5}s.mp3"); } } } // AudioPlayer foreach (var audio in AudioItemObjects .Where(audio => audio.TargetPlatform == Platform.All || audio.TargetPlatform == Platform.Clova)) { response.Response.Directives.Add(new Directive() { Header = new DirectiveHeader() { Namespace = DirectiveHeaderNamespace.AudioPlayer, Name = DirectiveHeaderName.Play }, Payload = new AudioPlayPayload { AudioItem = new LineDC.CEK.Models.AudioItem { AudioItemId = audio.AudioItemId, HeaderText = audio.Title, TitleText = audio.Title, TitleSubText1 = audio.SubTitle, ArtImageUrl = audio.ImageUrl, Stream = new AudioStreamInfoObject { BeginAtInMilliseconds = 0, Url = audio.Url, UrlPlayable = true } }, PlayBehavior = audio.AudioPlayBehavior == AudioPlayBehavior.Enqueue ? LineDC.CEK.Models.AudioPlayBehavior.ENQUEUE : LineDC.CEK.Models.AudioPlayBehavior.REPLACE_ALL, Source = new Source { Name = audio.Title } } }); } if (!ShouldEndSession) { response.KeepListening(); } return(response); }
public SkillResponse ToAlexaResponse() { if (AudioItemObjects.Any(obj => obj.TargetPlatform == Platform.All || obj.TargetPlatform == Platform.Alexa)) { // AudioPlayer var response = new SkillResponse { Response = new ResponseBody { ShouldEndSession = ShouldEndSession, Directives = new List <IDirective>() }, Version = "1.0" }; if (OutputObjects.Any(obj => obj.TargetPlatform == Platform.All || obj.TargetPlatform == Platform.Alexa)) { response.Response.OutputSpeech = new SsmlOutputSpeech { Ssml = GetSsmlResponse(Platform.Alexa) }; response.Response.Reprompt = !string.IsNullOrEmpty(RepromptText) ? new Alexa.NET.Response.Reprompt(RepromptText) : null; } foreach (var audio in AudioItemObjects .Where(audio => audio.TargetPlatform == Platform.All || audio.TargetPlatform == Platform.Alexa)) { response.Response.Directives.Add(new AudioPlayerPlayDirective { PlayBehavior = audio.AudioPlayBehavior == AudioPlayBehavior.Enqueue ? PlayBehavior.Enqueue : PlayBehavior.ReplaceAll, AudioItem = new Alexa.NET.Response.Directive.AudioItem { Stream = new AudioItemStream { Url = audio.Url, Token = audio.AudioItemId, ExpectedPreviousToken = audio.PreviousAudioItemId }, Metadata = new AudioItemMetadata { Title = audio.Title, Subtitle = audio.SubTitle } } }); } return(response); } else if (OutputObjects.Any(obj => obj.TargetPlatform == Platform.All || obj.TargetPlatform == Platform.Alexa)) { // normal return(new SkillResponse { Response = new ResponseBody { OutputSpeech = new SsmlOutputSpeech { Ssml = GetSsmlResponse(Platform.Alexa) }, Reprompt = !string.IsNullOrEmpty(RepromptText) ? new Alexa.NET.Response.Reprompt(RepromptText) : null, ShouldEndSession = ShouldEndSession }, Version = "1.0" }); } else { // nothing return(null); } }