/******************************************************************************* * Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"). You may not use * this file except in compliance with the License. A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * ***************************************************************************** * * AWS Tools for Windows (TM) PowerShell (TM) * */ using System; using System.Collections.Generic; using System.Linq; using System.Management.Automation; using System.Text; using Amazon.PowerShell.Common; using Amazon.Runtime; using Amazon.Polly; using Amazon.Polly.Model; namespace Amazon.PowerShell.Cmdlets.POL { /// /// Allows the creation of an asynchronous synthesis task, by starting a new SpeechSynthesisTask. /// This operation requires all the standard information needed for speech synthesis, /// plus the name of an Amazon S3 bucket for the service to store the output of the synthesis /// task and two optional parameters (OutputS3KeyPrefix and SnsTopicArn). /// Once the synthesis task is created, this operation will return a SpeechSynthesisTask /// object, which will include an identifier of this task as well as the current status. /// The SpeechSynthesisTask object is available for 72 hours after starting /// the asynchronous synthesis task. /// [Cmdlet("Start", "POLSpeechSynthesisTask", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.Polly.Model.SynthesisTask")] [AWSCmdlet("Calls the Amazon Polly StartSpeechSynthesisTask API operation.", Operation = new[] {"StartSpeechSynthesisTask"}, SelectReturnType = typeof(Amazon.Polly.Model.StartSpeechSynthesisTaskResponse))] [AWSCmdletOutput("Amazon.Polly.Model.SynthesisTask or Amazon.Polly.Model.StartSpeechSynthesisTaskResponse", "This cmdlet returns an Amazon.Polly.Model.SynthesisTask object.", "The service call response (type Amazon.Polly.Model.StartSpeechSynthesisTaskResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class StartPOLSpeechSynthesisTaskCmdlet : AmazonPollyClientCmdlet, IExecutor { #region Parameter Engine /// /// /// Specifies the engine (standard or neural) for Amazon Polly /// to use when processing input text for speech synthesis. Using a voice that is not /// supported for the engine selected will result in an error. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.Polly.Engine")] public Amazon.Polly.Engine Engine { get; set; } #endregion #region Parameter LanguageCode /// /// /// Optional language code for the Speech Synthesis request. This is only necessary if /// using a bilingual voice, such as Aditi, which can be used for either Indian English /// (en-IN) or Hindi (hi-IN). If a bilingual voice is used and no language code is specified, Amazon Polly uses /// the default language of the bilingual voice. The default language for any voice is /// the one returned by the DescribeVoices /// operation for the LanguageCode parameter. For example, if no language /// code is specified, Aditi will use Indian English rather than Hindi. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.Polly.LanguageCode")] public Amazon.Polly.LanguageCode LanguageCode { get; set; } #endregion #region Parameter LexiconName /// /// /// List of one or more pronunciation lexicon names you want the service to apply during /// synthesis. Lexicons are applied only if the language of the lexicon is the same as /// the language of the voice. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("LexiconNames")] public System.String[] LexiconName { get; set; } #endregion #region Parameter OutputFormat /// /// /// The format in which the returned output will be encoded. For audio stream, this will /// be mp3, ogg_vorbis, or pcm. For speech marks, this will be json. /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] [AWSConstantClassSource("Amazon.Polly.OutputFormat")] public Amazon.Polly.OutputFormat OutputFormat { get; set; } #endregion #region Parameter OutputS3BucketName /// /// /// Amazon S3 bucket name to which the output file will be saved. /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowEmptyString] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] public System.String OutputS3BucketName { get; set; } #endregion #region Parameter OutputS3KeyPrefix /// /// /// The Amazon S3 key prefix for the output speech file. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String OutputS3KeyPrefix { get; set; } #endregion #region Parameter SampleRate /// /// /// The audio frequency specified in Hz.The valid values for mp3 and ogg_vorbis are "8000", "16000", "22050", and "24000". /// The default value for standard voices is "22050". The default value for neural voices /// is "24000".Valid values for pcm are "8000" and "16000" The default value is "16000". /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SampleRate { get; set; } #endregion #region Parameter SnsTopicArn /// /// /// ARN for the SNS topic optionally used for providing status notification for a speech /// synthesis task. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SnsTopicArn { get; set; } #endregion #region Parameter SpeechMarkType /// /// /// The type of speech marks returned for the input text. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("SpeechMarkTypes")] public System.String[] SpeechMarkType { get; set; } #endregion #region Parameter Text /// /// /// The input text to synthesize. If you specify ssml as the TextType, follow the SSML /// format for the input text. /// /// #if !MODULAR [System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)] #else [System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, Mandatory = true)] [System.Management.Automation.AllowEmptyString] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] public System.String Text { get; set; } #endregion #region Parameter TextType /// /// /// Specifies whether the input text is plain text or SSML. The default value is plain /// text. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.Polly.TextType")] public Amazon.Polly.TextType TextType { get; set; } #endregion #region Parameter VoiceId /// /// /// Voice ID to use for the synthesis. /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] [AWSConstantClassSource("Amazon.Polly.VoiceId")] public Amazon.Polly.VoiceId VoiceId { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'SynthesisTask'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Polly.Model.StartSpeechSynthesisTaskResponse). /// Specifying the name of a property of type Amazon.Polly.Model.StartSpeechSynthesisTaskResponse will result in that property being returned. /// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value. /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public string Select { get; set; } = "SynthesisTask"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the Text parameter. /// The -PassThru parameter is deprecated, use -Select '^Text' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^Text' instead. This parameter will be removed in a future version.")] [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public SwitchParameter PassThru { get; set; } #endregion #region Parameter Force /// /// This parameter overrides confirmation prompts to force /// the cmdlet to continue its operation. This parameter should always /// be used with caution. /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public SwitchParameter Force { get; set; } #endregion protected override void ProcessRecord() { this._AWSSignerType = "v4"; base.ProcessRecord(); var resourceIdentifiersText = string.Empty; if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Start-POLSpeechSynthesisTask (StartSpeechSynthesisTask)")) { return; } var context = new CmdletContext(); // allow for manipulation of parameters prior to loading into context PreExecutionContextLoad(context); #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute if (ParameterWasBound(nameof(this.Select))) { context.Select = CreateSelectDelegate(Select) ?? throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select)); if (this.PassThru.IsPresent) { throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select)); } } else if (this.PassThru.IsPresent) { context.Select = (response, cmdlet) => this.Text; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.Engine = this.Engine; context.LanguageCode = this.LanguageCode; if (this.LexiconName != null) { context.LexiconName = new List(this.LexiconName); } context.OutputFormat = this.OutputFormat; #if MODULAR if (this.OutputFormat == null && ParameterWasBound(nameof(this.OutputFormat))) { WriteWarning("You are passing $null as a value for parameter OutputFormat which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues."); } #endif context.OutputS3BucketName = this.OutputS3BucketName; #if MODULAR if (this.OutputS3BucketName == null && ParameterWasBound(nameof(this.OutputS3BucketName))) { WriteWarning("You are passing $null as a value for parameter OutputS3BucketName which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues."); } #endif context.OutputS3KeyPrefix = this.OutputS3KeyPrefix; context.SampleRate = this.SampleRate; context.SnsTopicArn = this.SnsTopicArn; if (this.SpeechMarkType != null) { context.SpeechMarkType = new List(this.SpeechMarkType); } context.Text = this.Text; #if MODULAR if (this.Text == null && ParameterWasBound(nameof(this.Text))) { WriteWarning("You are passing $null as a value for parameter Text which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues."); } #endif context.TextType = this.TextType; context.VoiceId = this.VoiceId; #if MODULAR if (this.VoiceId == null && ParameterWasBound(nameof(this.VoiceId))) { WriteWarning("You are passing $null as a value for parameter VoiceId which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues."); } #endif // allow further manipulation of loaded context prior to processing PostExecutionContextLoad(context); var output = Execute(context) as CmdletOutput; ProcessOutput(output); } #region IExecutor Members public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.Polly.Model.StartSpeechSynthesisTaskRequest(); if (cmdletContext.Engine != null) { request.Engine = cmdletContext.Engine; } if (cmdletContext.LanguageCode != null) { request.LanguageCode = cmdletContext.LanguageCode; } if (cmdletContext.LexiconName != null) { request.LexiconNames = cmdletContext.LexiconName; } if (cmdletContext.OutputFormat != null) { request.OutputFormat = cmdletContext.OutputFormat; } if (cmdletContext.OutputS3BucketName != null) { request.OutputS3BucketName = cmdletContext.OutputS3BucketName; } if (cmdletContext.OutputS3KeyPrefix != null) { request.OutputS3KeyPrefix = cmdletContext.OutputS3KeyPrefix; } if (cmdletContext.SampleRate != null) { request.SampleRate = cmdletContext.SampleRate; } if (cmdletContext.SnsTopicArn != null) { request.SnsTopicArn = cmdletContext.SnsTopicArn; } if (cmdletContext.SpeechMarkType != null) { request.SpeechMarkTypes = cmdletContext.SpeechMarkType; } if (cmdletContext.Text != null) { request.Text = cmdletContext.Text; } if (cmdletContext.TextType != null) { request.TextType = cmdletContext.TextType; } if (cmdletContext.VoiceId != null) { request.VoiceId = cmdletContext.VoiceId; } CmdletOutput output; // issue call var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; pipelineOutput = cmdletContext.Select(response, this); output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } return output; } public ExecutorContext CreateContext() { return new CmdletContext(); } #endregion #region AWS Service Operation Call private Amazon.Polly.Model.StartSpeechSynthesisTaskResponse CallAWSServiceOperation(IAmazonPolly client, Amazon.Polly.Model.StartSpeechSynthesisTaskRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Polly", "StartSpeechSynthesisTask"); try { #if DESKTOP return client.StartSpeechSynthesisTask(request); #elif CORECLR return client.StartSpeechSynthesisTaskAsync(request).GetAwaiter().GetResult(); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } } #endregion internal partial class CmdletContext : ExecutorContext { public Amazon.Polly.Engine Engine { get; set; } public Amazon.Polly.LanguageCode LanguageCode { get; set; } public List LexiconName { get; set; } public Amazon.Polly.OutputFormat OutputFormat { get; set; } public System.String OutputS3BucketName { get; set; } public System.String OutputS3KeyPrefix { get; set; } public System.String SampleRate { get; set; } public System.String SnsTopicArn { get; set; } public List SpeechMarkType { get; set; } public System.String Text { get; set; } public Amazon.Polly.TextType TextType { get; set; } public Amazon.Polly.VoiceId VoiceId { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.SynthesisTask; } } }