Prompt.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
5 using Newtonsoft.Json;
6 
7 namespace Microsoft.Bot.Builder.Calling.ObjectModel.Contracts
8 {
12  [JsonObject(MemberSerialization.OptOut)]
13  public class Prompt
14  {
20  [JsonProperty(Required = Required.Default)]
21  public string Value { get; set; }
22 
26  public Uri FileUri { get; set; }
27 
31  [JsonProperty(Required = Required.Default)]
32  public VoiceGender? Voice { get; set; }
33 
37  [JsonProperty(Required = Required.Default)]
38  public Culture? Culture { get; set; }
39 
44  [JsonProperty(Required = Required.Default)]
45  public uint? SilenceLengthInMilliseconds { get; set; }
46 
50  [JsonProperty(Required = Required.Default)]
51  public bool? Emphasize { get; set; }
52 
56  [JsonProperty(Required = Required.Default)]
57  public SayAs? SayAs { get; set; }
58 
59  public void Validate()
60  {
61  bool fileSpecified = (this.FileUri != null);
62  bool textSpecified = !String.IsNullOrWhiteSpace(this.Value);
64  fileSpecified || textSpecified || this.SilenceLengthInMilliseconds.GetValueOrDefault() > 0,
65  "Either a prompt file/text has to be specified or a valid period of silence has to be specified or both can be specified");
66  Utils.AssertArgument(!(fileSpecified && textSpecified), "Both a prompt file and a TTS text cannot be specified at the same time.");
67 
68  if (textSpecified)
69  {
70  Utils.AssertArgument(this.Value.Length <= MaxValues.LengthOfTTSText, "Length of text to be TTS'd has to be smaller than {0} characters", MaxValues.LengthOfTTSText);
71  }
72 
73  if (this.SilenceLengthInMilliseconds.HasValue)
74  {
75  Utils.AssertArgument(this.SilenceLengthInMilliseconds.Value <= MaxValues.SilentPromptDuration.TotalMilliseconds,
76  "SilenceLengthInMilliSeconds has to be specified in the range of 0 - {0} msecs", MaxValues.SilentPromptDuration.TotalMilliseconds);
77  }
78  }
79 
80  public static void Validate(IEnumerable<Prompt> prompts)
81  {
82  Utils.AssertArgument(prompts != null, "Prompts list cannot be null");
83  Utils.AssertArgument(prompts.Any(), "Prompts list cannot be empty");
84  foreach (Prompt prompt in prompts)
85  {
86  Utils.AssertArgument(prompt != null, "Prompt cannot be null");
87  prompt.Validate();
88  }
89  }
90  }
91 }
VoiceGender
Voice genders we support for tts
Definition: VoiceGender.cs:9
static readonly TimeSpan SilentPromptDuration
max silent prompt duration
Definition: MaxValues.cs:47
Root namespace for the Microsoft Bot Builder Calling SDK object model.
static void AssertArgument(bool condition, string format, params object[] args)
Argument checker
Definition: Utils.cs:17
SayAs
Difference SayAs attributes we support for tts
Definition: SayAs.cs:9
This class represents a single prompt
Definition: Prompt.cs:13
Root namespace for the Microsoft Bot Builder Calling SDK.
static readonly uint LengthOfTTSText
Maximum number of speech variations for a choice
Definition: MaxValues.cs:52
static void Validate(IEnumerable< Prompt > prompts)
Definition: Prompt.cs:80
Namespace for utilities and helpers in the Microsoft Bot Builder Calling SDK.
Culture
Cultures we support for recognition or prompt playing
Definition: Culture.cs:10
Root namespace for the Microsoft Bot Builder SDK.