github.com/aavshr/aws-sdk-go@v1.41.3/service/polly/examples_test.go (about)

     1  // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
     2  
     3  package polly_test
     4  
     5  import (
     6  	"fmt"
     7  	"strings"
     8  	"time"
     9  
    10  	"github.com/aavshr/aws-sdk-go/aws"
    11  	"github.com/aavshr/aws-sdk-go/aws/awserr"
    12  	"github.com/aavshr/aws-sdk-go/aws/session"
    13  	"github.com/aavshr/aws-sdk-go/service/polly"
    14  )
    15  
    16  var _ time.Duration
    17  var _ strings.Reader
    18  var _ aws.Config
    19  
    20  func parseTime(layout, value string) *time.Time {
    21  	t, err := time.Parse(layout, value)
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  	return &t
    26  }
    27  
    28  // To delete a lexicon
    29  //
    30  // Deletes a specified pronunciation lexicon stored in an AWS Region.
    31  func ExamplePolly_DeleteLexicon_shared00() {
    32  	svc := polly.New(session.New())
    33  	input := &polly.DeleteLexiconInput{
    34  		Name: aws.String("example"),
    35  	}
    36  
    37  	result, err := svc.DeleteLexicon(input)
    38  	if err != nil {
    39  		if aerr, ok := err.(awserr.Error); ok {
    40  			switch aerr.Code() {
    41  			case polly.ErrCodeLexiconNotFoundException:
    42  				fmt.Println(polly.ErrCodeLexiconNotFoundException, aerr.Error())
    43  			case polly.ErrCodeServiceFailureException:
    44  				fmt.Println(polly.ErrCodeServiceFailureException, aerr.Error())
    45  			default:
    46  				fmt.Println(aerr.Error())
    47  			}
    48  		} else {
    49  			// Print the error, cast err to awserr.Error to get the Code and
    50  			// Message from an error.
    51  			fmt.Println(err.Error())
    52  		}
    53  		return
    54  	}
    55  
    56  	fmt.Println(result)
    57  }
    58  
    59  // To describe available voices
    60  //
    61  // Returns the list of voices that are available for use when requesting speech synthesis.
    62  // Displayed languages are those within the specified language code. If no language
    63  // code is specified, voices for all available languages are displayed.
    64  func ExamplePolly_DescribeVoices_shared00() {
    65  	svc := polly.New(session.New())
    66  	input := &polly.DescribeVoicesInput{
    67  		LanguageCode: aws.String("en-GB"),
    68  	}
    69  
    70  	result, err := svc.DescribeVoices(input)
    71  	if err != nil {
    72  		if aerr, ok := err.(awserr.Error); ok {
    73  			switch aerr.Code() {
    74  			case polly.ErrCodeInvalidNextTokenException:
    75  				fmt.Println(polly.ErrCodeInvalidNextTokenException, aerr.Error())
    76  			case polly.ErrCodeServiceFailureException:
    77  				fmt.Println(polly.ErrCodeServiceFailureException, aerr.Error())
    78  			default:
    79  				fmt.Println(aerr.Error())
    80  			}
    81  		} else {
    82  			// Print the error, cast err to awserr.Error to get the Code and
    83  			// Message from an error.
    84  			fmt.Println(err.Error())
    85  		}
    86  		return
    87  	}
    88  
    89  	fmt.Println(result)
    90  }
    91  
    92  // To retrieve a lexicon
    93  //
    94  // Returns the content of the specified pronunciation lexicon stored in an AWS Region.
    95  func ExamplePolly_GetLexicon_shared00() {
    96  	svc := polly.New(session.New())
    97  	input := &polly.GetLexiconInput{
    98  		Name: aws.String(""),
    99  	}
   100  
   101  	result, err := svc.GetLexicon(input)
   102  	if err != nil {
   103  		if aerr, ok := err.(awserr.Error); ok {
   104  			switch aerr.Code() {
   105  			case polly.ErrCodeLexiconNotFoundException:
   106  				fmt.Println(polly.ErrCodeLexiconNotFoundException, aerr.Error())
   107  			case polly.ErrCodeServiceFailureException:
   108  				fmt.Println(polly.ErrCodeServiceFailureException, aerr.Error())
   109  			default:
   110  				fmt.Println(aerr.Error())
   111  			}
   112  		} else {
   113  			// Print the error, cast err to awserr.Error to get the Code and
   114  			// Message from an error.
   115  			fmt.Println(err.Error())
   116  		}
   117  		return
   118  	}
   119  
   120  	fmt.Println(result)
   121  }
   122  
   123  // To list all lexicons in a region
   124  //
   125  // Returns a list of pronunciation lexicons stored in an AWS Region.
   126  func ExamplePolly_ListLexicons_shared00() {
   127  	svc := polly.New(session.New())
   128  	input := &polly.ListLexiconsInput{}
   129  
   130  	result, err := svc.ListLexicons(input)
   131  	if err != nil {
   132  		if aerr, ok := err.(awserr.Error); ok {
   133  			switch aerr.Code() {
   134  			case polly.ErrCodeInvalidNextTokenException:
   135  				fmt.Println(polly.ErrCodeInvalidNextTokenException, aerr.Error())
   136  			case polly.ErrCodeServiceFailureException:
   137  				fmt.Println(polly.ErrCodeServiceFailureException, aerr.Error())
   138  			default:
   139  				fmt.Println(aerr.Error())
   140  			}
   141  		} else {
   142  			// Print the error, cast err to awserr.Error to get the Code and
   143  			// Message from an error.
   144  			fmt.Println(err.Error())
   145  		}
   146  		return
   147  	}
   148  
   149  	fmt.Println(result)
   150  }
   151  
   152  // To save a lexicon
   153  //
   154  // Stores a pronunciation lexicon in an AWS Region.
   155  func ExamplePolly_PutLexicon_shared00() {
   156  	svc := polly.New(session.New())
   157  	input := &polly.PutLexiconInput{
   158  		Content: aws.String("file://example.pls"),
   159  		Name:    aws.String("W3C"),
   160  	}
   161  
   162  	result, err := svc.PutLexicon(input)
   163  	if err != nil {
   164  		if aerr, ok := err.(awserr.Error); ok {
   165  			switch aerr.Code() {
   166  			case polly.ErrCodeInvalidLexiconException:
   167  				fmt.Println(polly.ErrCodeInvalidLexiconException, aerr.Error())
   168  			case polly.ErrCodeUnsupportedPlsAlphabetException:
   169  				fmt.Println(polly.ErrCodeUnsupportedPlsAlphabetException, aerr.Error())
   170  			case polly.ErrCodeUnsupportedPlsLanguageException:
   171  				fmt.Println(polly.ErrCodeUnsupportedPlsLanguageException, aerr.Error())
   172  			case polly.ErrCodeLexiconSizeExceededException:
   173  				fmt.Println(polly.ErrCodeLexiconSizeExceededException, aerr.Error())
   174  			case polly.ErrCodeMaxLexemeLengthExceededException:
   175  				fmt.Println(polly.ErrCodeMaxLexemeLengthExceededException, aerr.Error())
   176  			case polly.ErrCodeMaxLexiconsNumberExceededException:
   177  				fmt.Println(polly.ErrCodeMaxLexiconsNumberExceededException, aerr.Error())
   178  			case polly.ErrCodeServiceFailureException:
   179  				fmt.Println(polly.ErrCodeServiceFailureException, aerr.Error())
   180  			default:
   181  				fmt.Println(aerr.Error())
   182  			}
   183  		} else {
   184  			// Print the error, cast err to awserr.Error to get the Code and
   185  			// Message from an error.
   186  			fmt.Println(err.Error())
   187  		}
   188  		return
   189  	}
   190  
   191  	fmt.Println(result)
   192  }
   193  
   194  // To synthesize speech
   195  //
   196  // Synthesizes plain text or SSML into a file of human-like speech.
   197  func ExamplePolly_SynthesizeSpeech_shared00() {
   198  	svc := polly.New(session.New())
   199  	input := &polly.SynthesizeSpeechInput{
   200  		LexiconNames: []*string{
   201  			aws.String("example"),
   202  		},
   203  		OutputFormat: aws.String("mp3"),
   204  		SampleRate:   aws.String("8000"),
   205  		Text:         aws.String("All Gaul is divided into three parts"),
   206  		TextType:     aws.String("text"),
   207  		VoiceId:      aws.String("Joanna"),
   208  	}
   209  
   210  	result, err := svc.SynthesizeSpeech(input)
   211  	if err != nil {
   212  		if aerr, ok := err.(awserr.Error); ok {
   213  			switch aerr.Code() {
   214  			case polly.ErrCodeTextLengthExceededException:
   215  				fmt.Println(polly.ErrCodeTextLengthExceededException, aerr.Error())
   216  			case polly.ErrCodeInvalidSampleRateException:
   217  				fmt.Println(polly.ErrCodeInvalidSampleRateException, aerr.Error())
   218  			case polly.ErrCodeInvalidSsmlException:
   219  				fmt.Println(polly.ErrCodeInvalidSsmlException, aerr.Error())
   220  			case polly.ErrCodeLexiconNotFoundException:
   221  				fmt.Println(polly.ErrCodeLexiconNotFoundException, aerr.Error())
   222  			case polly.ErrCodeServiceFailureException:
   223  				fmt.Println(polly.ErrCodeServiceFailureException, aerr.Error())
   224  			case polly.ErrCodeMarksNotSupportedForFormatException:
   225  				fmt.Println(polly.ErrCodeMarksNotSupportedForFormatException, aerr.Error())
   226  			case polly.ErrCodeSsmlMarksNotSupportedForTextTypeException:
   227  				fmt.Println(polly.ErrCodeSsmlMarksNotSupportedForTextTypeException, aerr.Error())
   228  			case polly.ErrCodeLanguageNotSupportedException:
   229  				fmt.Println(polly.ErrCodeLanguageNotSupportedException, aerr.Error())
   230  			case polly.ErrCodeEngineNotSupportedException:
   231  				fmt.Println(polly.ErrCodeEngineNotSupportedException, aerr.Error())
   232  			default:
   233  				fmt.Println(aerr.Error())
   234  			}
   235  		} else {
   236  			// Print the error, cast err to awserr.Error to get the Code and
   237  			// Message from an error.
   238  			fmt.Println(err.Error())
   239  		}
   240  		return
   241  	}
   242  
   243  	fmt.Println(result)
   244  }