diff --git a/README.md b/README.md index cf2b2ca..6b8769d 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ A ready-to-use package is available through Maven: com.ivona ivona-speechcloud-sdk-java - 0.3.0 + 1.0.0 ``` diff --git a/pom.xml b/pom.xml index 40208db..795db73 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.ivona ivona-speechcloud-sdk-java - 0.3.1 + 1.0.0 IVONA SpeechCloud SDK for Java IVONA SpeechCloud SDK for Java provides Java API. http://www.ivona.com/ @@ -39,7 +39,7 @@ - 1.9.19 + 1.10.4 diff --git a/src/main/java/com/ivona/services/tts/IvonaSpeechCloud.java b/src/main/java/com/ivona/services/tts/IvonaSpeechCloud.java index ff0641d..cb0de32 100644 --- a/src/main/java/com/ivona/services/tts/IvonaSpeechCloud.java +++ b/src/main/java/com/ivona/services/tts/IvonaSpeechCloud.java @@ -22,8 +22,13 @@ import com.amazonaws.regions.Region; import com.ivona.services.tts.model.CreateSpeechRequest; import com.ivona.services.tts.model.CreateSpeechResult; +import com.ivona.services.tts.model.DeleteLexiconRequest; +import com.ivona.services.tts.model.GetLexiconRequest; +import com.ivona.services.tts.model.GetLexiconResult; +import com.ivona.services.tts.model.ListLexiconsResult; import com.ivona.services.tts.model.ListVoicesRequest; import com.ivona.services.tts.model.ListVoicesResult; +import com.ivona.services.tts.model.PutLexiconRequest; /** * Ivona Speech Cloud Client interface. @@ -133,4 +138,47 @@ public void setEndpoint(String endpoint, String serviceName, String regionId) public void setRegion(Region region) throws IllegalArgumentException; public void shutdown(); + + /** + * Method that calls Ivona Speech Cloud and deletes lexicon specified in the lexiconNameRequest. + * + * @param deleteLexiconRequest + * request of the DeleteLexicon operation + * @throws AmazonServiceException + * @throws AmazonClientException + */ + public void deleteLexicon(DeleteLexiconRequest deleteLexiconRequest) + throws AmazonServiceException, AmazonClientException; + + /** + * Method that calls Ivona Speech Cloud and returns a lexicon. + * + * @param getLexiconRequest + * request of the GetLexicon operation + * @return GetLexiconResult + * result of the GetLexicon call + * @throws AmazonServiceException + * @throws AmazonClientException + */ + public GetLexiconResult getLexicon(GetLexiconRequest getLexiconRequest) + throws AmazonServiceException, AmazonClientException; + + /** + * Method that calls Ivona Speech Cloud and returns list of lexicons. + * + * @return ListLexiconsOutput + * result of the ListLexicons call + */ + public ListLexiconsResult listLexicons(); + + /** + * Method that calls Ivona Speech Cloud and creates or updates a lexicon. + * + * @param putLexiconRequest + * request of the PutLexicon operation + * @throws AmazonServiceException + * @throws AmazonClientException + */ + public void putLexicon(PutLexiconRequest putLexiconRequest) + throws AmazonServiceException, AmazonClientException; } diff --git a/src/main/java/com/ivona/services/tts/IvonaSpeechCloudClient.java b/src/main/java/com/ivona/services/tts/IvonaSpeechCloudClient.java index 9dc4670..38e9c7b 100644 --- a/src/main/java/com/ivona/services/tts/IvonaSpeechCloudClient.java +++ b/src/main/java/com/ivona/services/tts/IvonaSpeechCloudClient.java @@ -40,11 +40,27 @@ import com.ivona.services.tts.http.StreamResponseHandler; import com.ivona.services.tts.model.CreateSpeechRequest; import com.ivona.services.tts.model.CreateSpeechResult; +import com.ivona.services.tts.model.DeleteLexiconRequest; +import com.ivona.services.tts.model.GetLexiconRequest; +import com.ivona.services.tts.model.GetLexiconResult; +import com.ivona.services.tts.model.ListLexiconsRequest; +import com.ivona.services.tts.model.ListLexiconsResult; import com.ivona.services.tts.model.ListVoicesRequest; import com.ivona.services.tts.model.ListVoicesResult; import com.ivona.services.tts.model.MethodType; +import com.ivona.services.tts.model.PutLexiconRequest; import com.ivona.services.tts.model.transform.createspeech.CreateSpeechRequestMarshallerFactory; import com.ivona.services.tts.model.transform.createspeech.CreateSpeechResultUnmarshaller; +import com.ivona.services.tts.model.transform.lexicons.DeleteLexiconPostRequestMarshaller; +import com.ivona.services.tts.model.transform.lexicons.DeleteLexiconRequestMarshaller; +import com.ivona.services.tts.model.transform.lexicons.GetLexiconPostRequestMarshaller; +import com.ivona.services.tts.model.transform.lexicons.GetLexiconRequestMarshaller; +import com.ivona.services.tts.model.transform.lexicons.GetLexiconResultJsonUnmarshaller; +import com.ivona.services.tts.model.transform.lexicons.ListLexiconsPostRequestMarshaller; +import com.ivona.services.tts.model.transform.lexicons.ListLexiconsRequestMarshaller; +import com.ivona.services.tts.model.transform.lexicons.ListLexiconsResultJsonUnmarshaller; +import com.ivona.services.tts.model.transform.lexicons.PutLexiconPostRequestMarshaller; +import com.ivona.services.tts.model.transform.lexicons.PutLexiconRequestMarshaller; import com.ivona.services.tts.model.transform.listvoices.ListVoicesRequestMarshallerFactory; import com.ivona.services.tts.model.transform.listvoices.ListVoicesResultJsonUnmarshaller; import org.joda.time.DateTime; @@ -70,8 +86,8 @@ public class IvonaSpeechCloudClient extends AmazonWebServiceClient implements Iv private final static String SERVICE_PROTOCOL = "https://"; private final static String SERVICE_DOMAIN = "ivonacloud.com"; - private final static Pattern REGION_PATTERN = Pattern.compile(SERVICE_PROTOCOL + SERVICE_NAME + - "\\.([^.]*)\\." + SERVICE_DOMAIN.replace(".", "\\.")); + private final static Pattern REGION_PATTERN = Pattern.compile(SERVICE_PROTOCOL + SERVICE_NAME + + "\\.([^.]*)\\." + SERVICE_DOMAIN.replace(".", "\\.")); private final static int DEFAULT_GET_REQUEST_EXPIRATION_MINUTES = 5; @@ -131,7 +147,8 @@ public IvonaSpeechCloudClient(AWSCredentialsProvider awsCredentialsProvider) { * @param awsCredentialsProvider * @param clientConfiguration */ - public IvonaSpeechCloudClient(AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration) { + public IvonaSpeechCloudClient(AWSCredentialsProvider awsCredentialsProvider, + ClientConfiguration clientConfiguration) { super(clientConfiguration); this.awsCredentialsProvider = awsCredentialsProvider; init(); @@ -145,8 +162,8 @@ public CreateSpeechResult createSpeech(CreateSpeechRequest createSpeechRequest) Request request = CreateSpeechRequestMarshallerFactory.getMarshaller( createSpeechRequest.getMethodType()).marshall(createSpeechRequest); CreateSpeechResultUnmarshaller unmarshaller = new CreateSpeechResultUnmarshaller(); - StreamResponseHandler responseHandler = new StreamResponseHandler(unmarshaller); - + StreamResponseHandler responseHandler = + new StreamResponseHandler(unmarshaller); Response response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } @@ -167,8 +184,8 @@ public ListVoicesResult listVoices(ListVoicesRequest listVoicesRequest) throws A Request request = ListVoicesRequestMarshallerFactory.getMarshaller( listVoicesRequest.getMethodType()).marshall(listVoicesRequest); Unmarshaller unmarshaller = new ListVoicesResultJsonUnmarshaller(); - JsonResponseHandler responseHandler = new JsonResponseHandler(unmarshaller); - + JsonResponseHandler responseHandler = + new JsonResponseHandler(unmarshaller); Response response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } @@ -236,6 +253,59 @@ public void setRegion(Region region) throws IllegalArgumentException { throw new UnsupportedOperationException(); } + @Override + public void deleteLexicon(DeleteLexiconRequest deleteLexiconRequest) + throws AmazonServiceException, AmazonClientException { + + ExecutionContext executionContext = createExecutionContext(deleteLexiconRequest); + DeleteLexiconRequestMarshaller marshaller = new DeleteLexiconPostRequestMarshaller(); + Request request = marshaller.marshall(deleteLexiconRequest); + JsonResponseHandler responseHandler = new JsonResponseHandler(null); + + invoke(request, responseHandler, executionContext); + } + + @Override + public GetLexiconResult getLexicon(GetLexiconRequest getLexiconRequest) + throws AmazonServiceException, AmazonClientException { + + ExecutionContext executionContext = createExecutionContext(getLexiconRequest); + GetLexiconRequestMarshaller marshaller = new GetLexiconPostRequestMarshaller(); + Request request = marshaller.marshall(getLexiconRequest); + Unmarshaller unmarshaller = new GetLexiconResultJsonUnmarshaller(); + JsonResponseHandler responseHandler = new JsonResponseHandler(unmarshaller); + + Response response = invoke(request, responseHandler, executionContext); + return response.getAwsResponse(); + } + + @Override + public ListLexiconsResult listLexicons() { + ListLexiconsRequest listLexiconsRequest = new ListLexiconsRequest(); + ExecutionContext executionContext = createExecutionContext(listLexiconsRequest); + ListLexiconsRequestMarshaller marshaller = new ListLexiconsPostRequestMarshaller(); + Request request = marshaller.marshall(listLexiconsRequest); + Unmarshaller unmarshaller = + new ListLexiconsResultJsonUnmarshaller(); + JsonResponseHandler responseHandler = + new JsonResponseHandler(unmarshaller); + + Response response = invoke(request, responseHandler, executionContext); + return response.getAwsResponse(); + } + + @Override + public void putLexicon(PutLexiconRequest putLexiconRequest) + throws AmazonServiceException, AmazonClientException { + + ExecutionContext executionContext = createExecutionContext(putLexiconRequest); + PutLexiconRequestMarshaller marshaller = new PutLexiconPostRequestMarshaller(); + Request request = marshaller.marshall(putLexiconRequest); + JsonResponseHandler responseHandler = new JsonResponseHandler(null); + + invoke(request, responseHandler, executionContext); + } + private void init() { exceptionUnmarshallers = new ArrayList(); exceptionUnmarshallers.add(new JsonErrorUnmarshaller()); diff --git a/src/main/java/com/ivona/services/tts/model/CreateSpeechRequest.java b/src/main/java/com/ivona/services/tts/model/CreateSpeechRequest.java index 97909ac..a4743f2 100644 --- a/src/main/java/com/ivona/services/tts/model/CreateSpeechRequest.java +++ b/src/main/java/com/ivona/services/tts/model/CreateSpeechRequest.java @@ -12,24 +12,24 @@ */ package com.ivona.services.tts.model; -import java.io.Serializable; - import com.amazonaws.AmazonWebServiceRequest; +import java.util.List; + /** * Class representing CreateSpeech request *

* Please check the service documentation for more details. * - * @see Speech Cloud Developer Guide + * @see + * Speech Cloud Developer Guide */ -public class CreateSpeechRequest extends AmazonWebServiceRequest implements Serializable { - - private static final long serialVersionUID = 1L; +public class CreateSpeechRequest extends AmazonWebServiceRequest { private Input input; private OutputFormat outputFormat; private Parameters parameters; + private List lexiconNames; private Voice voice; private MethodType methodType; @@ -49,7 +49,6 @@ public void setInput(Input input) { this.input = input; } - /** * Set the input text for the request. *

@@ -112,6 +111,32 @@ public CreateSpeechRequest withParameters(Parameters parameters) { return this; } + /** + * Get the lexicons for the request. + *

+ * Lexicons are optional. + */ + public List getLexiconNames() { + return lexiconNames; + } + + /** + * Set the lexicons for the request. + */ + public void setLexiconNames(List lexiconNames) { + this.lexiconNames = lexiconNames; + } + + /** + * Set the lexicons for the request. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public CreateSpeechRequest withLexiconNames(List lexiconNames) { + this.lexiconNames = lexiconNames; + return this; + } + /** * Get which Voice is requested to speak. *

@@ -173,10 +198,12 @@ public String toString() { builder.append(outputFormat); builder.append(", parameters="); builder.append(parameters); + builder.append(", lexiconNames="); + builder.append(lexiconNames); builder.append(", voice="); builder.append(voice); builder.append(", methodType="); - builder.append(methodType.toString()); + builder.append(methodType); builder.append("]"); return builder.toString(); } @@ -188,6 +215,7 @@ public int hashCode() { result = prime * result + ((input == null) ? 0 : input.hashCode()); result = prime * result + ((outputFormat == null) ? 0 : outputFormat.hashCode()); result = prime * result + ((parameters == null) ? 0 : parameters.hashCode()); + result = prime * result + ((lexiconNames == null) ? 0 : lexiconNames.hashCode()); result = prime * result + ((voice == null) ? 0 : voice.hashCode()); result = prime * result + ((methodType == null) ? 0 : methodType.hashCode()); return result; @@ -196,44 +224,58 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; - + } CreateSpeechRequest other = (CreateSpeechRequest) obj; if (input == null) { - if (other.input != null) + if (other.input != null) { return false; - } else if (!input.equals(other.input)) + } + } else if (!input.equals(other.input)) { return false; - + } if (outputFormat == null) { - if (other.outputFormat != null) + if (other.outputFormat != null) { return false; - } else if (!outputFormat.equals(other.outputFormat)) + } + } else if (!outputFormat.equals(other.outputFormat)) { return false; - + } if (parameters == null) { - if (other.parameters != null) + if (other.parameters != null) { return false; - } else if (!parameters.equals(other.parameters)) + } + } else if (!parameters.equals(other.parameters)) { return false; - + } + if (lexiconNames == null) { + if (other.lexiconNames != null) { + return false; + } + } else if (!lexiconNames.equals(other.lexiconNames)) { + return false; + } if (voice == null) { - if (other.voice != null) + if (other.voice != null) { return false; - } else if (!voice.equals(other.voice)) + } + } else if (!voice.equals(other.voice)) { return false; - + } if (methodType == null) { - if (other.methodType != null) + if (other.methodType != null) { return false; - } else if (!methodType.equals(other.methodType)) + } + } else if (!methodType.equals(other.methodType)) { return false; - + } return true; } } diff --git a/src/main/java/com/ivona/services/tts/model/CreateSpeechResult.java b/src/main/java/com/ivona/services/tts/model/CreateSpeechResult.java index 7bf036a..7f9ca45 100644 --- a/src/main/java/com/ivona/services/tts/model/CreateSpeechResult.java +++ b/src/main/java/com/ivona/services/tts/model/CreateSpeechResult.java @@ -13,18 +13,16 @@ package com.ivona.services.tts.model; import java.io.InputStream; -import java.io.Serializable; /** * Class representing CreateSpeech result *

* Please check the service documentation for more details. * - * @see Speech Cloud Developer Guide + * @see + * Speech Cloud Developer Guide */ -public class CreateSpeechResult implements Serializable { - - private static final long serialVersionUID = 1L; +public class CreateSpeechResult { private String requestId; private String contentType; diff --git a/src/main/java/com/ivona/services/tts/model/DeleteLexiconRequest.java b/src/main/java/com/ivona/services/tts/model/DeleteLexiconRequest.java new file mode 100644 index 0000000..af05f44 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/DeleteLexiconRequest.java @@ -0,0 +1,91 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model; + +import com.amazonaws.AmazonWebServiceRequest; + +import java.io.Serializable; + +/** + * Class representing DeleteLexiconRequest request + *

+ * Please check the service documentation for more details. + * + * @see Speech Cloud Developer Guide + */ +public class DeleteLexiconRequest extends AmazonWebServiceRequest implements Serializable { + + private static final long serialVersionUID = 1L; + private String lexiconName; + + /** + * Get the lexicon name for the request. + */ + public String getLexiconName() { + return lexiconName; + } + + /** + * Set the lexicon name for the request. + */ + public void setLexiconName(String lexiconName) { + this.lexiconName = lexiconName; + } + + /** + * Set the lexicon name for the request. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public DeleteLexiconRequest withLexiconName(String lexiconName) { + this.lexiconName = lexiconName; + return this; + } + + @Override + public String toString() { + return "DeleteLexiconRequest [lexiconName=" + lexiconName + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((lexiconName == null) ? 0 : lexiconName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + DeleteLexiconRequest other = (DeleteLexiconRequest) obj; + if (lexiconName == null) { + if (other.lexiconName != null) { + return false; + } + } else if (!lexiconName.equals(other.lexiconName)) { + return false; + } + + return true; + } +} diff --git a/src/main/java/com/ivona/services/tts/model/GetLexiconRequest.java b/src/main/java/com/ivona/services/tts/model/GetLexiconRequest.java new file mode 100644 index 0000000..1d8ffb1 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/GetLexiconRequest.java @@ -0,0 +1,90 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model; + +import com.amazonaws.AmazonWebServiceRequest; + +/** + * Class representing GetLexiconRequest request + *

+ * Please check the service documentation for more details. + * + * @see Speech Cloud Developer Guide + */ +public class GetLexiconRequest extends AmazonWebServiceRequest { + + private String lexiconName; + + /** + * Get the lexicon name for the request. + *

+ * Lexicon name is required. + */ + public String getLexiconName() { + return lexiconName; + } + + /** + * Set the lexicon name for the request. + */ + public void setLexiconName(String lexiconName) { + this.lexiconName = lexiconName; + } + + /** + * Set the lexicon name for the request. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public GetLexiconRequest withLexiconName(String lexiconName) { + this.lexiconName = lexiconName; + return this; + } + + @Override + public String toString() { + return "GetLexiconRequest [lexiconName=" + lexiconName + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((lexiconName == null) ? 0 : lexiconName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + GetLexiconRequest other = (GetLexiconRequest) obj; + if (lexiconName == null) { + if (other.lexiconName != null) { + return false; + } + } else if (!lexiconName.equals(other.lexiconName)) { + return false; + } + + return true; + } +} diff --git a/src/main/java/com/ivona/services/tts/model/GetLexiconResult.java b/src/main/java/com/ivona/services/tts/model/GetLexiconResult.java new file mode 100644 index 0000000..3f1f221 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/GetLexiconResult.java @@ -0,0 +1,90 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model; + +/** + * Class representing GetLexicon result + *

+ * Please check the service documentation for more details. + * + * @see Speech Cloud Developer Guide + */ +public class GetLexiconResult { + + private Lexicon lexicon; + + /** + * Get the lexicon from result. + */ + public Lexicon getLexicon() { + return lexicon; + } + + /** + * Set the lexicon for this result. + */ + public void setLexicon(Lexicon lexicon) { + this.lexicon = lexicon; + } + + /** + * Set the lexicon for this result. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public GetLexiconResult withLexicon(Lexicon lexicon) { + this.lexicon = lexicon; + return this; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GetLexiconResult [lexicon="); + builder.append(lexicon); + builder.append("]"); + return builder.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((lexicon == null) ? 0 : lexicon.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + GetLexiconResult other = (GetLexiconResult) obj; + if (lexicon == null) { + if (other.lexicon != null) { + return false; + } + } else if (!lexicon.equals(other.lexicon)) { + return false; + } + + return true; + } +} diff --git a/src/main/java/com/ivona/services/tts/model/Input.java b/src/main/java/com/ivona/services/tts/model/Input.java index 8e80457..39efa14 100644 --- a/src/main/java/com/ivona/services/tts/model/Input.java +++ b/src/main/java/com/ivona/services/tts/model/Input.java @@ -17,7 +17,8 @@ *

* Please check the service documentation for more details. * - * @see Speech Cloud Developer Guide + * @see + * Speech Cloud Developer Guide */ public class Input { @@ -100,23 +101,30 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Input other = (Input) obj; if (data == null) { - if (other.data != null) + if (other.data != null) { return false; - } else if (!data.equals(other.data)) + } + } else if (!data.equals(other.data)) { return false; + } if (type == null) { - if (other.type != null) + if (other.type != null) { return false; - } else if (!type.equals(other.type)) + } + } else if (!type.equals(other.type)) { return false; + } return true; } } diff --git a/src/main/java/com/ivona/services/tts/model/Lexicon.java b/src/main/java/com/ivona/services/tts/model/Lexicon.java new file mode 100644 index 0000000..e27b362 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/Lexicon.java @@ -0,0 +1,125 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model; + +/** + * Class representing a lexicon. + *

+ * Please check the service documentation for more details. + * + * @see Speech Cloud Developer Guide + */ +public class Lexicon { + private String name; + private String contents; + + /** + * Get the lexicon name. + */ + public String getName() { + return this.name; + } + + /** + * Set the lexicon name. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Set the lexicon name. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public Lexicon withName(String name) { + this.name = name; + return this; + } + + /** + * Get the PLS contents of this lexicon. + */ + public String getContents() { + return this.contents; + } + + /** + * Set the PLS contents of this lexicon. + */ + public void setContents(String contents) { + this.contents = contents; + } + + /** + * Set the PLS contents of this lexicon. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public Lexicon withContents(String contents) { + this.contents = contents; + return this; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Lexicon [name="); + builder.append(name); + builder.append(", contents="); + builder.append(contents); + builder.append("]"); + return builder.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((contents == null) ? 0 : contents.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + Lexicon other = (Lexicon) obj; + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + if (contents == null) { + if (other.contents != null) { + return false; + } + } else if (!contents.equals(other.contents)) { + return false; + } + + return true; + } + +} diff --git a/src/main/java/com/ivona/services/tts/model/ListLexiconsRequest.java b/src/main/java/com/ivona/services/tts/model/ListLexiconsRequest.java new file mode 100644 index 0000000..5c19146 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/ListLexiconsRequest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model; + +import com.amazonaws.AmazonWebServiceRequest; + +/** + * Class representing ListLexiconsRequest request + *

+ * Please check the service documentation for more details. + * + * @see Speech Cloud Developer Guide + */ +public class ListLexiconsRequest extends AmazonWebServiceRequest { + + @Override + public String toString() { + return "ListLexiconsRequest []"; + } +} diff --git a/src/main/java/com/ivona/services/tts/model/ListLexiconsResult.java b/src/main/java/com/ivona/services/tts/model/ListLexiconsResult.java new file mode 100644 index 0000000..a39c8ce --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/ListLexiconsResult.java @@ -0,0 +1,87 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model; + +import java.util.List; + +/** + * Class representing ListLexicons result + *

+ * Please check the service documentation for more details. + * + * @see Speech Cloud Developer Guide + */ +public class ListLexiconsResult { + private List lexiconNames; + + /** + * Get the list of lexicon names from result. + */ + public List getLexiconNames() { + return lexiconNames; + } + + /** + * Set the list of lexicon names for this result. + */ + public void setLexiconNames(List lexiconNames) { + this.lexiconNames = lexiconNames; + } + + /** + * Set the list of lexicon names for this result. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public ListLexiconsResult withLexiconNames(List lexiconNames) { + this.lexiconNames = lexiconNames; + return this; + } + + @Override + public String toString() { + return "ListLexiconsResult [lexiconNames=" + lexiconNames + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((lexiconNames == null) ? 0 : lexiconNames.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + ListLexiconsResult other = (ListLexiconsResult) obj; + if (lexiconNames == null) { + if (other.lexiconNames != null) { + return false; + } + } else if (!lexiconNames.equals(other.lexiconNames)) { + return false; + } + + return true; + } +} diff --git a/src/main/java/com/ivona/services/tts/model/ListVoicesRequest.java b/src/main/java/com/ivona/services/tts/model/ListVoicesRequest.java index 311fe7b..463a204 100644 --- a/src/main/java/com/ivona/services/tts/model/ListVoicesRequest.java +++ b/src/main/java/com/ivona/services/tts/model/ListVoicesRequest.java @@ -12,8 +12,6 @@ */ package com.ivona.services.tts.model; -import java.io.Serializable; - import com.amazonaws.AmazonWebServiceRequest; /** @@ -23,9 +21,8 @@ * * @see Speech Cloud Developer Guide */ -public class ListVoicesRequest extends AmazonWebServiceRequest implements Serializable { +public class ListVoicesRequest extends AmazonWebServiceRequest { - private static final long serialVersionUID = 1L; private Voice voice; private MethodType methodType; @@ -101,7 +98,6 @@ public ListVoicesRequest withMethodType(MethodType methodType) { return this; } - @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -124,26 +120,30 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; - + } ListVoicesRequest other = (ListVoicesRequest) obj; if (voice == null) { - if (other.voice != null) + if (other.voice != null) { return false; - } else if (!voice.equals(other.voice)) + } + } else if (!voice.equals(other.voice)) { return false; - + } if (methodType == null) { - if (other.methodType != null) + if (other.methodType != null) { return false; - } else if (!methodType.equals(other.methodType)) + } + } else if (!methodType.equals(other.methodType)) { return false; - + } return true; } } diff --git a/src/main/java/com/ivona/services/tts/model/ListVoicesResult.java b/src/main/java/com/ivona/services/tts/model/ListVoicesResult.java index f555fa0..7bdcc29 100644 --- a/src/main/java/com/ivona/services/tts/model/ListVoicesResult.java +++ b/src/main/java/com/ivona/services/tts/model/ListVoicesResult.java @@ -64,20 +64,23 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; - + } ListVoicesResult other = (ListVoicesResult) obj; if (voices == null) { - if (other.voices != null) + if (other.voices != null) { return false; - } else if (!voices.equals(other.voices)) + } + } else if (!voices.equals(other.voices)) { return false; - + } return true; } } diff --git a/src/main/java/com/ivona/services/tts/model/OutputFormat.java b/src/main/java/com/ivona/services/tts/model/OutputFormat.java index 9c8e27d..f503d21 100644 --- a/src/main/java/com/ivona/services/tts/model/OutputFormat.java +++ b/src/main/java/com/ivona/services/tts/model/OutputFormat.java @@ -23,6 +23,7 @@ public class OutputFormat { private String codec; private Short sampleRate; + private SpeechMarks speechMarks; /** * Get the codec used for this synthesis. @@ -72,6 +73,30 @@ public OutputFormat withSampleRate(Short sampleRate) { return this; } + /** + * Get the speech marks for this synthesis. + */ + public SpeechMarks getSpeechMarks() { + return speechMarks; + } + + /** + * Set the speech marks for this format. + */ + public void setSpeechMarks(SpeechMarks speechMarks) { + this.speechMarks = speechMarks; + } + + /** + * Set the speech marks for this format. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public OutputFormat withSpeechMarks(SpeechMarks speechMarks) { + this.speechMarks = speechMarks; + return this; + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -79,6 +104,8 @@ public String toString() { builder.append(codec); builder.append(", sampleRate="); builder.append(sampleRate); + builder.append(", speechMarks="); + builder.append(speechMarks); builder.append("]"); return builder.toString(); } @@ -89,28 +116,43 @@ public int hashCode() { int result = 1; result = prime * result + ((codec == null) ? 0 : codec.hashCode()); result = prime * result + ((sampleRate == null) ? 0 : sampleRate.hashCode()); + result = prime * result + ((speechMarks == null) ? 0 : speechMarks.hashCode()); return result; } @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } OutputFormat other = (OutputFormat) obj; if (codec == null) { - if (other.codec != null) + if (other.codec != null) { return false; - } else if (!codec.equals(other.codec)) + } + } else if (!codec.equals(other.codec)) { return false; + } if (sampleRate == null) { - if (other.sampleRate != null) + if (other.sampleRate != null) { + return false; + } + } else if (!sampleRate.equals(other.sampleRate)) { + return false; + } + if (speechMarks == null) { + if (other.speechMarks != null) { return false; - } else if (!sampleRate.equals(other.sampleRate)) + } + } else if (!speechMarks.equals(other.speechMarks)) { return false; + } return true; } } diff --git a/src/main/java/com/ivona/services/tts/model/Parameters.java b/src/main/java/com/ivona/services/tts/model/Parameters.java index 0366f73..04e8af7 100644 --- a/src/main/java/com/ivona/services/tts/model/Parameters.java +++ b/src/main/java/com/ivona/services/tts/model/Parameters.java @@ -150,33 +150,44 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Parameters other = (Parameters) obj; if (paragraphBreak == null) { - if (other.paragraphBreak != null) + if (other.paragraphBreak != null) { return false; - } else if (!paragraphBreak.equals(other.paragraphBreak)) + } + } else if (!paragraphBreak.equals(other.paragraphBreak)) { return false; + } if (rate == null) { - if (other.rate != null) + if (other.rate != null) { return false; - } else if (!rate.equals(other.rate)) + } + } else if (!rate.equals(other.rate)) { return false; + } if (sentenceBreak == null) { - if (other.sentenceBreak != null) + if (other.sentenceBreak != null) { return false; - } else if (!sentenceBreak.equals(other.sentenceBreak)) + } + } else if (!sentenceBreak.equals(other.sentenceBreak)) { return false; + } if (volume == null) { - if (other.volume != null) + if (other.volume != null) { return false; - } else if (!volume.equals(other.volume)) + } + } else if (!volume.equals(other.volume)) { return false; + } return true; } } diff --git a/src/main/java/com/ivona/services/tts/model/PutLexiconRequest.java b/src/main/java/com/ivona/services/tts/model/PutLexiconRequest.java new file mode 100644 index 0000000..4d90d99 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/PutLexiconRequest.java @@ -0,0 +1,92 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model; + +import com.amazonaws.AmazonWebServiceRequest; + +/** + * Class representing PutLexicon request + *

+ * Please check the service documentation for more details. + * + * @see Speech Cloud Developer Guide + */ +public class PutLexiconRequest extends AmazonWebServiceRequest { + + private Lexicon lexicon; + + /** + * Get the lexicon for the request. + */ + public Lexicon getLexicon() { + return lexicon; + } + + /** + * Set the lexicon for the request. + */ + public void setLexicon(Lexicon lexicon) { + this.lexicon = lexicon; + } + + /** + * Set the lexicon for the request. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public PutLexiconRequest withLexicon(Lexicon lexicon) { + this.lexicon = lexicon; + return this; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("PutLexiconRequest [lexicon="); + builder.append(lexicon); + builder.append("]"); + return builder.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((lexicon == null) ? 0 : lexicon.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + PutLexiconRequest other = (PutLexiconRequest) obj; + if (lexicon == null) { + if (other.lexicon != null) { + return false; + } + } else if (!lexicon.equals(other.lexicon)) { + return false; + } + + return true; + } +} diff --git a/src/main/java/com/ivona/services/tts/model/SpeechMarks.java b/src/main/java/com/ivona/services/tts/model/SpeechMarks.java new file mode 100644 index 0000000..81f15fb --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/SpeechMarks.java @@ -0,0 +1,176 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model; + +/** + * Class representing the speech marks requested for a synthesis. + *

+ * Please check the service documentation for more details. + * + * @see Speech Cloud Developer Guide + */ +public class SpeechMarks { + private boolean sentence; + private boolean ssml; + private boolean viseme; + private boolean word; + + /** + * Returns true if sentence speech marks are . + */ + public boolean isSentence() { + return sentence; + } + + /** + * Enable or disable sentence speech marks. + */ + public void setSentence(boolean sentence) { + this.sentence = sentence; + } + + /** + * Enable or disable sentence speech marks. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public SpeechMarks withSentence(boolean sentence) { + this.sentence = sentence; + return this; + } + + /** + * Returns true if SSML speech marks are . + */ + public boolean isSsml() { + return ssml; + } + + /** + * Enable or disable SSML speech marks. + */ + public void setSsml(boolean ssml) { + this.ssml = ssml; + } + + /** + * Enable or disable SSML speech marks. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public SpeechMarks withSsml(boolean ssml) { + this.ssml = ssml; + return this; + } + + /** + * Returns true if viseme speech marks are . + */ + public boolean isViseme() { + return viseme; + } + + /** + * Enable or disable viseme speech marks. + */ + public void setViseme(boolean viseme) { + this.viseme = viseme; + } + + /** + * Enable or disable viseme speech marks. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public SpeechMarks withViseme(boolean viseme) { + this.viseme = viseme; + return this; + } + + /** + * Returns true if word speech marks are . + */ + public boolean isWord() { + return word; + } + + /** + * Enable or disable word speech marks. + */ + public void setWord(boolean word) { + this.word = word; + } + + /** + * Enable or disable word speech marks. + *

+ * Returns a reference to this object so that method calls can be chained together. + */ + public SpeechMarks withWord(boolean word) { + this.word = word; + return this; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SpeechMarks [sentence="); + builder.append(sentence); + builder.append(", ssml="); + builder.append(ssml); + builder.append(", viseme="); + builder.append(viseme); + builder.append(", word="); + builder.append(word); + builder.append("]"); + return builder.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (sentence ? 1 : 0); + result = prime * result + (ssml ? 1 : 0); + result = prime * result + (viseme ? 1 : 0); + result = prime * result + (word ? 1 : 0); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + SpeechMarks other = (SpeechMarks) obj; + if (sentence != other.sentence) { + return false; + } + if (ssml != other.ssml) { + return false; + } + if (viseme != other.viseme) { + return false; + } + if (word != other.word) { + return false; + } + return true; + } +} diff --git a/src/main/java/com/ivona/services/tts/model/Voice.java b/src/main/java/com/ivona/services/tts/model/Voice.java index 59a727f..9d65957 100644 --- a/src/main/java/com/ivona/services/tts/model/Voice.java +++ b/src/main/java/com/ivona/services/tts/model/Voice.java @@ -126,28 +126,37 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Voice other = (Voice) obj; if (gender == null) { - if (other.gender != null) + if (other.gender != null) { return false; - } else if (!gender.equals(other.gender)) + } + } else if (!gender.equals(other.gender)) { return false; + } if (language == null) { - if (other.language != null) + if (other.language != null) { return false; - } else if (!language.equals(other.language)) + } + } else if (!language.equals(other.language)) { return false; + } if (name == null) { - if (other.name != null) + if (other.name != null) { return false; - } else if (!name.equals(other.name)) + } + } else if (!name.equals(other.name)) { return false; + } return true; } } diff --git a/src/main/java/com/ivona/services/tts/model/transform/MarshallerHelper.java b/src/main/java/com/ivona/services/tts/model/transform/MarshallerHelper.java index 3004e2a..95d8e07 100644 --- a/src/main/java/com/ivona/services/tts/model/transform/MarshallerHelper.java +++ b/src/main/java/com/ivona/services/tts/model/transform/MarshallerHelper.java @@ -12,21 +12,54 @@ */ package com.ivona.services.tts.model.transform; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; import java.util.Map; /** * The class which contains simple methods used by CreateSpeech and ListVoices marshallers. */ public class MarshallerHelper { - public static void putToMapIfNotNull(Map map, final String key, final String value) { + public static void putToMapIfNotNull(Map> map, final String key, final String value) { if (value != null) { - map.put(key, value); + map.put(key, Collections.singletonList(value)); } } - public static void putToMapIfNotNull(Map map, final String key, final Short value) { + public static void putToMapIfNotNull(Map> map, final String key, final Short value) { if (value != null) { - map.put(key, value.toString()); + map.put(key, Collections.singletonList(value.toString())); } } + + public static void putToMapIfTrue(Map> map, final String key, final boolean value) { + if (value) { + map.put(key, Collections.singletonList("true")); + } + } + + public static boolean stringIsNotBlank(String value) { + return value != null && !value.trim().isEmpty(); + } + + public static void putToMapIfNotNull(Map> map, final String key, final List values) { + if (values != null && !values.isEmpty()) { + map.put(key, Collections.singletonList(convertListToString(values))); + } + } + + private static String convertListToString(final List values) { + StringBuilder sb = new StringBuilder(); + Iterator it = values.iterator(); + boolean isFirst = true; + while (it.hasNext()) { + if (!isFirst) { + sb.append(","); + } + sb.append(it.next()); + isFirst = false; + } + return sb.toString(); + } } diff --git a/src/main/java/com/ivona/services/tts/model/transform/createspeech/CreateSpeechGetRequestMarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/createspeech/CreateSpeechGetRequestMarshaller.java index a7bac64..920bc94 100644 --- a/src/main/java/com/ivona/services/tts/model/transform/createspeech/CreateSpeechGetRequestMarshaller.java +++ b/src/main/java/com/ivona/services/tts/model/transform/createspeech/CreateSpeechGetRequestMarshaller.java @@ -19,9 +19,11 @@ import com.amazonaws.transform.Marshaller; import com.ivona.services.tts.IvonaSpeechCloudClient; import com.ivona.services.tts.model.CreateSpeechRequest; +import com.ivona.services.tts.model.SpeechMarks; import com.ivona.services.tts.model.transform.MarshallerHelper; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -36,10 +38,15 @@ public class CreateSpeechGetRequestMarshaller implements Marshaller marshall(CreateSpeechRequest createSpeechReq } private void setRequestParameters(Request request, CreateSpeechRequest createSpeechRequest) { - Map parameters = new HashMap(); + Map> parameters = new HashMap>(); - MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_INPUT_DATA, createSpeechRequest.getInput().getData()); - MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_INPUT_TYPE, createSpeechRequest.getInput().getType()); + MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_INPUT_DATA, + createSpeechRequest.getInput().getData()); + MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_INPUT_TYPE, + createSpeechRequest.getInput().getType()); if (createSpeechRequest.getOutputFormat() != null) { - MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_OUTPUT_FORMAT_CODEC, createSpeechRequest.getOutputFormat().getCodec()); - MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_OUTPUT_FORMAT_SAMPLE_RATE, createSpeechRequest.getOutputFormat().getSampleRate()); + MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_OUTPUT_FORMAT_CODEC, + createSpeechRequest.getOutputFormat().getCodec()); + MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_OUTPUT_FORMAT_SAMPLE_RATE, + createSpeechRequest.getOutputFormat().getSampleRate()); + + SpeechMarks speechMarks = createSpeechRequest.getOutputFormat().getSpeechMarks(); + if (speechMarks != null) { + MarshallerHelper.putToMapIfTrue(parameters, GET_PARAM_OUTPUT_FORMAT_SPEECH_MARKS_SENTENCE, + speechMarks.isSentence()); + MarshallerHelper.putToMapIfTrue(parameters, GET_PARAM_OUTPUT_FORMAT_SPEECH_MARKS_SSML, + speechMarks.isSsml()); + MarshallerHelper.putToMapIfTrue(parameters, GET_PARAM_OUTPUT_FORMAT_SPEECH_MARKS_VISEME, + speechMarks.isViseme()); + MarshallerHelper.putToMapIfTrue(parameters, GET_PARAM_OUTPUT_FORMAT_SPEECH_MARKS_WORD, + speechMarks.isWord()); + } } if (createSpeechRequest.getParameters() != null) { - MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_PARAMETERS_RATE, createSpeechRequest.getParameters().getRate()); - MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_PARAMETERS_VOLUME, createSpeechRequest.getParameters().getVolume()); - MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_PARAMETERS_PARAGRAPH_BREAK, createSpeechRequest.getParameters().getParagraphBreak()); - MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_PARAMETERS_SENTENCE_BREAK, createSpeechRequest.getParameters().getSentenceBreak()); + MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_PARAMETERS_RATE, + createSpeechRequest.getParameters().getRate()); + MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_PARAMETERS_VOLUME, + createSpeechRequest.getParameters().getVolume()); + MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_PARAMETERS_PARAGRAPH_BREAK, + createSpeechRequest.getParameters().getParagraphBreak()); + MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_PARAMETERS_SENTENCE_BREAK, + createSpeechRequest.getParameters().getSentenceBreak()); + } + + if (createSpeechRequest.getLexiconNames() != null) { + MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_LEXICONS, + createSpeechRequest.getLexiconNames()); } if (createSpeechRequest.getVoice() != null) { - MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_VOICE_NAME, createSpeechRequest.getVoice().getName()); - MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_VOICE_LANGUAGE, createSpeechRequest.getVoice().getLanguage()); - MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_VOICE_GENDER, createSpeechRequest.getVoice().getGender()); + MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_VOICE_NAME, + createSpeechRequest.getVoice().getName()); + MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_VOICE_LANGUAGE, + createSpeechRequest.getVoice().getLanguage()); + MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_VOICE_GENDER, + createSpeechRequest.getVoice().getGender()); } request.setParameters(parameters); diff --git a/src/main/java/com/ivona/services/tts/model/transform/createspeech/CreateSpeechPostRequestMarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/createspeech/CreateSpeechPostRequestMarshaller.java index 465528a..e8118a5 100644 --- a/src/main/java/com/ivona/services/tts/model/transform/createspeech/CreateSpeechPostRequestMarshaller.java +++ b/src/main/java/com/ivona/services/tts/model/transform/createspeech/CreateSpeechPostRequestMarshaller.java @@ -18,15 +18,21 @@ import com.amazonaws.http.HttpMethodName; import com.amazonaws.transform.Marshaller; import com.amazonaws.util.StringInputStream; +import com.amazonaws.util.json.JSONException; import com.amazonaws.util.json.JSONWriter; import com.ivona.services.tts.IvonaSpeechCloudClient; import com.ivona.services.tts.model.CreateSpeechRequest; import com.ivona.services.tts.model.Input; import com.ivona.services.tts.model.OutputFormat; import com.ivona.services.tts.model.Parameters; +import com.ivona.services.tts.model.SpeechMarks; import com.ivona.services.tts.model.Voice; import java.io.StringWriter; +import java.io.UnsupportedEncodingException; +import java.util.List; + +import static java.nio.charset.StandardCharsets.UTF_8; /** * CreateSpeechRequest Marshaller - transforms CreateSpeechRequest class into Json POST request @@ -42,7 +48,13 @@ public class CreateSpeechPostRequestMarshaller implements Marshaller marshall(CreateSpeechRequest createSpeechRequest) { if (createSpeechRequest == null) { @@ -101,6 +111,26 @@ private void setRequestPayload(Request request, CreateSpeec if (outputFormat.getSampleRate() != null && outputFormat.getSampleRate() > 0) { jsonWriter.key(JSON_KEY_OUTPUT_FORMAT_SAMPLE_RATE).value((long) outputFormat.getSampleRate()); } + if (outputFormat.getSpeechMarks() != null) { + jsonWriter.key(JSON_KEY_OUTPUT_FORMAT_SPEECHMARKS); + jsonWriter.object(); + SpeechMarks speechMarks = outputFormat.getSpeechMarks(); + if (speechMarks != null) { + if (speechMarks.isSentence()) { + jsonWriter.key(JSON_KEY_OUTPUT_FORMAT_SPEECHMARKS_SENTENCE).value(true); + } + if (speechMarks.isSsml()) { + jsonWriter.key(JSON_KEY_OUTPUT_FORMAT_SPEECHMARKS_SSML).value(true); + } + if (speechMarks.isViseme()) { + jsonWriter.key(JSON_KEY_OUTPUT_FORMAT_SPEECHMARKS_VISEME).value(true); + } + if (speechMarks.isWord()) { + jsonWriter.key(JSON_KEY_OUTPUT_FORMAT_SPEECHMARKS_WORD).value(true); + } + } + jsonWriter.endObject(); + } jsonWriter.endObject(); } @@ -124,6 +154,11 @@ private void setRequestPayload(Request request, CreateSpeec jsonWriter.endObject(); } + if (createSpeechRequest.getLexiconNames() != null) { + List names = createSpeechRequest.getLexiconNames(); + jsonWriter.key(JSON_KEY_LEXICONS).value(names); + } + if (createSpeechRequest.getVoice() != null) { Voice voice = createSpeechRequest.getVoice(); @@ -143,10 +178,12 @@ private void setRequestPayload(Request request, CreateSpeec jsonWriter.endObject(); String snippet = stringWriter.toString(); - byte[] content = snippet.getBytes(CHARSET); + byte[] content = snippet.getBytes(UTF_8); request.setContent(new StringInputStream(snippet)); request.addHeader("Content-Length", Integer.toString(content.length)); - } catch (Exception e) { + } catch (JSONException e) { + throw new AmazonClientException("Unable to marshall request to JSON", e); + } catch (UnsupportedEncodingException e) { throw new AmazonClientException("Unable to marshall request to JSON", e); } } diff --git a/src/main/java/com/ivona/services/tts/model/transform/lexicons/DeleteLexiconPostRequestMarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/lexicons/DeleteLexiconPostRequestMarshaller.java new file mode 100644 index 0000000..3b7dddf --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/transform/lexicons/DeleteLexiconPostRequestMarshaller.java @@ -0,0 +1,79 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model.transform.lexicons; + +import com.amazonaws.AmazonClientException; +import com.amazonaws.DefaultRequest; +import com.amazonaws.Request; +import com.amazonaws.http.HttpMethodName; +import com.amazonaws.transform.Marshaller; +import com.amazonaws.util.StringInputStream; +import com.amazonaws.util.json.JSONException; +import com.amazonaws.util.json.JSONWriter; +import com.ivona.services.tts.IvonaSpeechCloudClient; +import com.ivona.services.tts.model.DeleteLexiconRequest; +import com.ivona.services.tts.model.transform.MarshallerHelper; + +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; + +import static java.nio.charset.StandardCharsets.UTF_8; + +/** + * DeleteLexiconRequest Marshaller - transforms DeleteLexiconRequest class into Json POST request + */ +public class DeleteLexiconPostRequestMarshaller implements Marshaller, + DeleteLexiconRequest>, DeleteLexiconRequestMarshaller { + + protected final static String RESOURCE_PATH = "DeleteLexicon"; + + public Request marshall(DeleteLexiconRequest deleteLexiconRequest) { + if (deleteLexiconRequest == null) { + throw new AmazonClientException("null deleteLexiconRequest passed to marshall(...)"); + } + + Request request = new DefaultRequest(deleteLexiconRequest, + IvonaSpeechCloudClient.SERVICE_NAME); + request.setHttpMethod(HttpMethodName.POST); + setRequestPayload(request, deleteLexiconRequest); + request.setResourcePath(RESOURCE_PATH); + + return request; + } + + private void setRequestPayload(Request request, DeleteLexiconRequest deleteLexiconRequest) { + StringWriter stringWriter = new StringWriter(); + JSONWriter jsonWriter = new JSONWriter(stringWriter); + + try { + jsonWriter.object(); + + if (MarshallerHelper.stringIsNotBlank(deleteLexiconRequest.getLexiconName())) { + jsonWriter.key("Name").value(deleteLexiconRequest.getLexiconName()); + } else { + throw new AmazonClientException("null or empty lexicon name passed to marshall(...)"); + } + + jsonWriter.endObject(); + + String snippet = stringWriter.toString(); + byte[] content = snippet.getBytes(UTF_8); + request.setContent(new StringInputStream(snippet)); + request.addHeader("Content-Length", Integer.toString(content.length)); + } catch (JSONException e) { + throw new AmazonClientException("Unable to marshall request to JSON", e); + } catch (UnsupportedEncodingException e) { + throw new AmazonClientException("Unable to marshall request to JSON", e); + } + } +} diff --git a/src/main/java/com/ivona/services/tts/model/transform/lexicons/DeleteLexiconRequestMarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/lexicons/DeleteLexiconRequestMarshaller.java new file mode 100644 index 0000000..67ebc35 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/transform/lexicons/DeleteLexiconRequestMarshaller.java @@ -0,0 +1,23 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model.transform.lexicons; + +import com.amazonaws.Request; +import com.ivona.services.tts.model.DeleteLexiconRequest; + +/** + * An interface for DeleteLexiconRequest Marshallers. + */ +public interface DeleteLexiconRequestMarshaller { + public Request marshall(DeleteLexiconRequest deleteLexiconRequest); +} diff --git a/src/main/java/com/ivona/services/tts/model/transform/lexicons/GetLexiconPostRequestMarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/lexicons/GetLexiconPostRequestMarshaller.java new file mode 100644 index 0000000..38d55a2 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/transform/lexicons/GetLexiconPostRequestMarshaller.java @@ -0,0 +1,79 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model.transform.lexicons; + +import com.amazonaws.AmazonClientException; +import com.amazonaws.DefaultRequest; +import com.amazonaws.Request; +import com.amazonaws.http.HttpMethodName; +import com.amazonaws.transform.Marshaller; +import com.amazonaws.util.StringInputStream; +import com.amazonaws.util.json.JSONException; +import com.amazonaws.util.json.JSONWriter; +import com.ivona.services.tts.IvonaSpeechCloudClient; +import com.ivona.services.tts.model.GetLexiconRequest; +import com.ivona.services.tts.model.transform.MarshallerHelper; + +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; + +import static java.nio.charset.StandardCharsets.UTF_8; + +/** + * GetLexiconRequest Marshaller - transforms GetLexiconRequest class into Json POST request + */ +public class GetLexiconPostRequestMarshaller implements Marshaller, GetLexiconRequest>, + GetLexiconRequestMarshaller { + + protected final static String RESOURCE_PATH = "GetLexicon"; + + public Request marshall(GetLexiconRequest getLexiconRequest) { + if (getLexiconRequest == null) { + throw new AmazonClientException("null getLexiconRequest passed to marshall(...)"); + } + + Request request = new DefaultRequest(getLexiconRequest, + IvonaSpeechCloudClient.SERVICE_NAME); + request.setHttpMethod(HttpMethodName.POST); + setRequestPayload(request, getLexiconRequest); + request.setResourcePath(RESOURCE_PATH); + + return request; + } + + private void setRequestPayload(Request request, GetLexiconRequest getLexiconRequest) { + StringWriter stringWriter = new StringWriter(); + JSONWriter jsonWriter = new JSONWriter(stringWriter); + + try { + jsonWriter.object(); + + if (MarshallerHelper.stringIsNotBlank(getLexiconRequest.getLexiconName())) { + jsonWriter.key("Name").value(getLexiconRequest.getLexiconName()); + } else { + throw new AmazonClientException("null or empty lexicon name passed to marshall(...)"); + } + + jsonWriter.endObject(); + + String snippet = stringWriter.toString(); + byte[] content = snippet.getBytes(UTF_8); + request.setContent(new StringInputStream(snippet)); + request.addHeader("Content-Length", Integer.toString(content.length)); + } catch (JSONException e) { + throw new AmazonClientException("Unable to marshall request to JSON", e); + } catch (UnsupportedEncodingException e) { + throw new AmazonClientException("Unable to marshall request to JSON", e); + } + } +} diff --git a/src/main/java/com/ivona/services/tts/model/transform/lexicons/GetLexiconRequestMarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/lexicons/GetLexiconRequestMarshaller.java new file mode 100644 index 0000000..c9391a4 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/transform/lexicons/GetLexiconRequestMarshaller.java @@ -0,0 +1,23 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model.transform.lexicons; + +import com.amazonaws.Request; +import com.ivona.services.tts.model.GetLexiconRequest; + +/** + * An interface for GetLexiconRequest Marshallers. + */ +public interface GetLexiconRequestMarshaller { + public Request marshall(GetLexiconRequest getLexiconRequest); +} diff --git a/src/main/java/com/ivona/services/tts/model/transform/lexicons/GetLexiconResultJsonUnmarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/lexicons/GetLexiconResultJsonUnmarshaller.java new file mode 100644 index 0000000..baa66d2 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/transform/lexicons/GetLexiconResultJsonUnmarshaller.java @@ -0,0 +1,71 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model.transform.lexicons; + +import com.amazonaws.transform.JsonUnmarshallerContext; +import com.amazonaws.transform.Unmarshaller; +import com.fasterxml.jackson.core.JsonToken; +import com.ivona.services.tts.model.GetLexiconResult; + +import static com.fasterxml.jackson.core.JsonToken.END_ARRAY; +import static com.fasterxml.jackson.core.JsonToken.END_OBJECT; +import static com.fasterxml.jackson.core.JsonToken.FIELD_NAME; +import static com.fasterxml.jackson.core.JsonToken.START_OBJECT; +import static com.fasterxml.jackson.core.JsonToken.VALUE_NULL; + +/** + * GetLexiconResult Unmarshaller - transforms Json server response into GetLexiconResult + */ +public class GetLexiconResultJsonUnmarshaller implements Unmarshaller { + protected final static String JSON_KEY_LEXICON = "Lexicon"; + + public GetLexiconResult unmarshall(JsonUnmarshallerContext context) throws Exception { + GetLexiconResult getLexiconResult = new GetLexiconResult(); + + int originalDepth = context.getCurrentDepth(); + String currentParentElement = context.getCurrentParentElement(); + int targetDepth = originalDepth + 1; + + JsonToken token = context.getCurrentToken(); + if (token == null) { + token = context.nextToken(); + } + if (token == VALUE_NULL) { + return null; + } + + while (true) { + if (token == null) { + break; + } + + if (token == FIELD_NAME || token == START_OBJECT) { + if (context.testExpression(JSON_KEY_LEXICON, targetDepth)) { + context.nextToken(); + getLexiconResult.setLexicon(LexiconJsonUnmarshaller.getInstance().unmarshall(context)); + } + } else if (token == END_ARRAY || token == END_OBJECT) { + if (context.getLastParsedParentElement() == null + || context.getLastParsedParentElement().equals(currentParentElement)) { + if (context.getCurrentDepth() <= originalDepth) { + break; + } + } + } + + token = context.nextToken(); + } + + return getLexiconResult; + } +} diff --git a/src/main/java/com/ivona/services/tts/model/transform/lexicons/LexiconJsonUnmarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/lexicons/LexiconJsonUnmarshaller.java new file mode 100644 index 0000000..25a3152 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/transform/lexicons/LexiconJsonUnmarshaller.java @@ -0,0 +1,82 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model.transform.lexicons; + +import com.amazonaws.transform.JsonUnmarshallerContext; +import com.amazonaws.transform.SimpleTypeJsonUnmarshallers; +import com.amazonaws.transform.Unmarshaller; +import com.fasterxml.jackson.core.JsonToken; +import com.ivona.services.tts.model.Lexicon; + +import static com.fasterxml.jackson.core.JsonToken.END_ARRAY; +import static com.fasterxml.jackson.core.JsonToken.END_OBJECT; +import static com.fasterxml.jackson.core.JsonToken.FIELD_NAME; +import static com.fasterxml.jackson.core.JsonToken.START_OBJECT; +import static com.fasterxml.jackson.core.JsonToken.VALUE_NULL; + +public class LexiconJsonUnmarshaller implements Unmarshaller { + private static LexiconJsonUnmarshaller instance = new LexiconJsonUnmarshaller(); + + protected final static String JSON_KEY_NAME = "Name"; + protected final static String JSON_KEY_CONTENTS = "Contents"; + + public Lexicon unmarshall(JsonUnmarshallerContext context) throws Exception { + Lexicon lexicon = new Lexicon(); + + int originalDepth = context.getCurrentDepth(); + String currentParentElement = context.getCurrentParentElement(); + int targetDepth = originalDepth + 1; + + JsonToken token = context.getCurrentToken(); + if (token == null) { + token = context.nextToken(); + } + if (token == VALUE_NULL) { + return null; + } + + while (true) { + if (token == null) { + break; + } + + if (token == FIELD_NAME || token == START_OBJECT) { + if (context.testExpression(JSON_KEY_NAME, targetDepth)) { + context.nextToken(); + lexicon.setName( + SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); + } + if (context.testExpression(JSON_KEY_CONTENTS, targetDepth)) { + context.nextToken(); + lexicon.setContents( + SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); + } + } else if (token == END_ARRAY || token == END_OBJECT) { + if (context.getLastParsedParentElement() == null + || context.getLastParsedParentElement().equals(currentParentElement)) { + if (context.getCurrentDepth() <= originalDepth) { + break; + } + } + } + + token = context.nextToken(); + } + + return lexicon; + } + + public static LexiconJsonUnmarshaller getInstance() { + return instance; + } +} diff --git a/src/main/java/com/ivona/services/tts/model/transform/lexicons/ListLexiconsPostRequestMarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/lexicons/ListLexiconsPostRequestMarshaller.java new file mode 100644 index 0000000..98a4ec5 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/transform/lexicons/ListLexiconsPostRequestMarshaller.java @@ -0,0 +1,71 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model.transform.lexicons; + +import com.amazonaws.AmazonClientException; +import com.amazonaws.DefaultRequest; +import com.amazonaws.Request; +import com.amazonaws.http.HttpMethodName; +import com.amazonaws.transform.Marshaller; +import com.amazonaws.util.StringInputStream; +import com.amazonaws.util.json.JSONException; +import com.amazonaws.util.json.JSONWriter; +import com.ivona.services.tts.IvonaSpeechCloudClient; +import com.ivona.services.tts.model.ListLexiconsRequest; + +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; + +import static java.nio.charset.StandardCharsets.UTF_8; + +/** + * ListLexiconsRequest Marshaller - transforms ListLexiconsRequest class into Json POST request + */ +public class ListLexiconsPostRequestMarshaller implements Marshaller, ListLexiconsRequest>, + ListLexiconsRequestMarshaller { + + protected final static String RESOURCE_PATH = "ListLexicons"; + + public Request marshall(ListLexiconsRequest listLexiconsRequest) { + if (listLexiconsRequest == null) { + throw new AmazonClientException("null listLexiconsRequest passed to marshall(...)"); + } + + Request request = new DefaultRequest(listLexiconsRequest, + IvonaSpeechCloudClient.SERVICE_NAME); + request.setHttpMethod(HttpMethodName.POST); + setRequestPayload(request, listLexiconsRequest); + request.setResourcePath(RESOURCE_PATH); + + return request; + } + + private void setRequestPayload(Request request, ListLexiconsRequest listLexiconsRequest) { + StringWriter stringWriter = new StringWriter(); + JSONWriter jsonWriter = new JSONWriter(stringWriter); + + try { + jsonWriter.object(); + jsonWriter.endObject(); + + String snippet = stringWriter.toString(); + byte[] content = snippet.getBytes(UTF_8); + request.setContent(new StringInputStream(snippet)); + request.addHeader("Content-Length", Integer.toString(content.length)); + } catch (JSONException e) { + throw new AmazonClientException("Unable to marshall request to JSON", e); + } catch (UnsupportedEncodingException e) { + throw new AmazonClientException("Unable to marshall request to JSON", e); + } + } +} diff --git a/src/main/java/com/ivona/services/tts/model/transform/lexicons/ListLexiconsRequestMarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/lexicons/ListLexiconsRequestMarshaller.java new file mode 100644 index 0000000..13ad64a --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/transform/lexicons/ListLexiconsRequestMarshaller.java @@ -0,0 +1,23 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model.transform.lexicons; + +import com.amazonaws.Request; +import com.ivona.services.tts.model.ListLexiconsRequest; + +/** + * An interface for ListLexiconsRequest Marshallers. + */ +public interface ListLexiconsRequestMarshaller { + public Request marshall(ListLexiconsRequest listLexiconsRequest); +} diff --git a/src/main/java/com/ivona/services/tts/model/transform/lexicons/ListLexiconsResultJsonUnmarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/lexicons/ListLexiconsResultJsonUnmarshaller.java new file mode 100644 index 0000000..7bd038e --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/transform/lexicons/ListLexiconsResultJsonUnmarshaller.java @@ -0,0 +1,73 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model.transform.lexicons; + +import static com.fasterxml.jackson.core.JsonToken.END_ARRAY; +import static com.fasterxml.jackson.core.JsonToken.END_OBJECT; +import static com.fasterxml.jackson.core.JsonToken.FIELD_NAME; +import static com.fasterxml.jackson.core.JsonToken.START_OBJECT; +import static com.fasterxml.jackson.core.JsonToken.VALUE_NULL; + +import com.amazonaws.transform.JsonUnmarshallerContext; +import com.amazonaws.transform.ListUnmarshaller; +import com.amazonaws.transform.SimpleTypeJsonUnmarshallers; +import com.amazonaws.transform.Unmarshaller; +import com.fasterxml.jackson.core.JsonToken; +import com.ivona.services.tts.model.ListLexiconsResult; + +/** + * ListLexiconsResult Unmarshaller - transforms Json server response into ListLexiconsResult + */ +public class ListLexiconsResultJsonUnmarshaller implements Unmarshaller { + protected final static String JSON_KEY_LEXICONS = "LexiconNames"; + + public ListLexiconsResult unmarshall(JsonUnmarshallerContext context) throws Exception { + ListLexiconsResult listLexiconsResult = new ListLexiconsResult(); + + int originalDepth = context.getCurrentDepth(); + String currentParentElement = context.getCurrentParentElement(); + int targetDepth = originalDepth + 1; + + JsonToken token = context.getCurrentToken(); + if (token == null) { + token = context.nextToken(); + } + if (token == VALUE_NULL) { + return null; + } + + while (true) { + if (token == null) { + break; + } + + if (token == FIELD_NAME || token == START_OBJECT) { + if (context.testExpression(JSON_KEY_LEXICONS, targetDepth)) { + listLexiconsResult.setLexiconNames(new ListUnmarshaller( + SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance()).unmarshall(context)); + } + } else if (token == END_ARRAY || token == END_OBJECT) { + if (context.getLastParsedParentElement() == null + || context.getLastParsedParentElement().equals(currentParentElement)) { + if (context.getCurrentDepth() <= originalDepth) { + break; + } + } + } + + token = context.nextToken(); + } + + return listLexiconsResult; + } +} diff --git a/src/main/java/com/ivona/services/tts/model/transform/lexicons/PutLexiconPostRequestMarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/lexicons/PutLexiconPostRequestMarshaller.java new file mode 100644 index 0000000..eb15e67 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/transform/lexicons/PutLexiconPostRequestMarshaller.java @@ -0,0 +1,97 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model.transform.lexicons; + +import com.amazonaws.AmazonClientException; +import com.amazonaws.DefaultRequest; +import com.amazonaws.Request; +import com.amazonaws.http.HttpMethodName; +import com.amazonaws.transform.Marshaller; +import com.amazonaws.util.StringInputStream; +import com.amazonaws.util.json.JSONException; +import com.amazonaws.util.json.JSONWriter; +import com.ivona.services.tts.IvonaSpeechCloudClient; +import com.ivona.services.tts.model.Lexicon; +import com.ivona.services.tts.model.PutLexiconRequest; +import com.ivona.services.tts.model.transform.MarshallerHelper; + +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; + +import static java.nio.charset.StandardCharsets.UTF_8; + +/** + * PutLexiconRequest Marshaller - transforms PutLexiconRequest class into Json POST request + */ +public class PutLexiconPostRequestMarshaller implements Marshaller, PutLexiconRequest>, + PutLexiconRequestMarshaller { + + protected final static String RESOURCE_PATH = "PutLexicon"; + protected final static String JSON_KEY_LEXICON = "Lexicon"; + protected final static String JSON_KEY_NAME = "Name"; + protected final static String JSON_KEY_CONTENTS = "Contents"; + + public Request marshall(PutLexiconRequest putLexiconRequest) { + if (putLexiconRequest == null) { + throw new AmazonClientException("null putLexiconRequest passed to marshall(...)"); + } + + Request request = new DefaultRequest(putLexiconRequest, + IvonaSpeechCloudClient.SERVICE_NAME); + request.setHttpMethod(HttpMethodName.POST); + setRequestPayload(request, putLexiconRequest); + request.setResourcePath(RESOURCE_PATH); + + return request; + } + + private void setRequestPayload(Request request, PutLexiconRequest putLexiconRequest) { + StringWriter stringWriter = new StringWriter(); + JSONWriter jsonWriter = new JSONWriter(stringWriter); + + try { + jsonWriter.object(); + Lexicon lexicon = putLexiconRequest.getLexicon(); + if (lexicon != null) { + jsonWriter.key(JSON_KEY_LEXICON); + jsonWriter.object(); + + if (MarshallerHelper.stringIsNotBlank(lexicon.getName())) { + jsonWriter.key(JSON_KEY_NAME).value(lexicon.getName()); + } else { + throw new AmazonClientException("null or empty lexicon name passed to marshall(...)"); + } + + if (MarshallerHelper.stringIsNotBlank(lexicon.getContents())) { + jsonWriter.key(JSON_KEY_CONTENTS).value(lexicon.getContents()); + } else { + throw new AmazonClientException("null or empty lexicon contents passed to marshall(...)"); + } + + jsonWriter.endObject(); + } else { + throw new AmazonClientException("null lexicon object passed to marshall(...)"); + } + jsonWriter.endObject(); + + String snippet = stringWriter.toString(); + byte[] content = snippet.getBytes(UTF_8); + request.setContent(new StringInputStream(snippet)); + request.addHeader("Content-Length", Integer.toString(content.length)); + } catch (JSONException e) { + throw new AmazonClientException("Unable to marshall request to JSON", e); + } catch (UnsupportedEncodingException e) { + throw new AmazonClientException("Unable to marshall request to JSON", e); + } + } +} diff --git a/src/main/java/com/ivona/services/tts/model/transform/lexicons/PutLexiconRequestMarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/lexicons/PutLexiconRequestMarshaller.java new file mode 100644 index 0000000..fb70ab8 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/transform/lexicons/PutLexiconRequestMarshaller.java @@ -0,0 +1,23 @@ +/* + * Copyright 2015 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. + */ +package com.ivona.services.tts.model.transform.lexicons; + +import com.amazonaws.Request; +import com.ivona.services.tts.model.PutLexiconRequest; + +/** + * An interface for PutLexiconRequest Marshallers. + */ +public interface PutLexiconRequestMarshaller { + public Request marshall(PutLexiconRequest putLexiconRequest); +} diff --git a/src/main/java/com/ivona/services/tts/model/transform/lexicons/package-info.java b/src/main/java/com/ivona/services/tts/model/transform/lexicons/package-info.java new file mode 100644 index 0000000..23371b8 --- /dev/null +++ b/src/main/java/com/ivona/services/tts/model/transform/lexicons/package-info.java @@ -0,0 +1,5 @@ +/** + * The classes contained in this package and sub-packages are implementation classes and are not meant to be directly + * referenced by users of the API. + */ +package com.ivona.services.tts.model.transform.lexicons; diff --git a/src/main/java/com/ivona/services/tts/model/transform/listvoices/ListVoicesGetRequestMarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/listvoices/ListVoicesGetRequestMarshaller.java index 8736769..7732946 100644 --- a/src/main/java/com/ivona/services/tts/model/transform/listvoices/ListVoicesGetRequestMarshaller.java +++ b/src/main/java/com/ivona/services/tts/model/transform/listvoices/ListVoicesGetRequestMarshaller.java @@ -22,6 +22,7 @@ import com.ivona.services.tts.model.transform.MarshallerHelper; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -53,12 +54,15 @@ public Request marshall(ListVoicesRequest listVoicesRequest) } protected void setRequestParameters(Request request, ListVoicesRequest listVoicesRequest) { - Map parameters = new HashMap(); + Map> parameters = new HashMap>(); if (listVoicesRequest.getVoice() != null) { - MarshallerHelper.putToMapIfNotNull(parameters, PARAM_VOICE_NAME, listVoicesRequest.getVoice().getName()); - MarshallerHelper.putToMapIfNotNull(parameters, PARAM_VOICE_LANGUAGE, listVoicesRequest.getVoice().getLanguage()); - MarshallerHelper.putToMapIfNotNull(parameters, PARAM_VOICE_GENDER, listVoicesRequest.getVoice().getGender()); + MarshallerHelper.putToMapIfNotNull(parameters, PARAM_VOICE_NAME, + listVoicesRequest.getVoice().getName()); + MarshallerHelper.putToMapIfNotNull(parameters, PARAM_VOICE_LANGUAGE, + listVoicesRequest.getVoice().getLanguage()); + MarshallerHelper.putToMapIfNotNull(parameters, PARAM_VOICE_GENDER, + listVoicesRequest.getVoice().getGender()); } request.setParameters(parameters); diff --git a/src/main/java/com/ivona/services/tts/model/transform/listvoices/ListVoicesPostRequestMarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/listvoices/ListVoicesPostRequestMarshaller.java index 68598df..3717d07 100644 --- a/src/main/java/com/ivona/services/tts/model/transform/listvoices/ListVoicesPostRequestMarshaller.java +++ b/src/main/java/com/ivona/services/tts/model/transform/listvoices/ListVoicesPostRequestMarshaller.java @@ -25,6 +25,8 @@ import java.io.StringWriter; +import static java.nio.charset.StandardCharsets.UTF_8; + /** * ListVoicesRequest Marshaller - transforms ListVoicesRequest into Json request */ @@ -32,7 +34,6 @@ public class ListVoicesPostRequestMarshaller implements Marshaller request, ListVoicesReq jsonWriter.endObject(); String snippet = stringWriter.toString(); - byte[] content = snippet.getBytes(CHARSET); + byte[] content = snippet.getBytes(UTF_8); request.setContent(new StringInputStream(snippet)); request.addHeader("Content-Length", Integer.toString(content.length)); } catch (Throwable t) { diff --git a/src/main/java/com/ivona/services/tts/model/transform/listvoices/VoiceJsonUnmarshaller.java b/src/main/java/com/ivona/services/tts/model/transform/listvoices/VoiceJsonUnmarshaller.java index 7529514..23cbdf3 100644 --- a/src/main/java/com/ivona/services/tts/model/transform/listvoices/VoiceJsonUnmarshaller.java +++ b/src/main/java/com/ivona/services/tts/model/transform/listvoices/VoiceJsonUnmarshaller.java @@ -25,7 +25,7 @@ import static com.fasterxml.jackson.core.JsonToken.VALUE_NULL; public class VoiceJsonUnmarshaller implements Unmarshaller { - private static VoiceJsonUnmarshaller instance; + private static VoiceJsonUnmarshaller instance = new VoiceJsonUnmarshaller(); protected final static String JSON_KEY_NAME = "Name"; protected final static String JSON_KEY_LANGUAGE = "Language"; @@ -55,15 +55,18 @@ public Voice unmarshall(JsonUnmarshallerContext context) throws Exception { if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression(JSON_KEY_NAME, targetDepth)) { context.nextToken(); - voice.setName(SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); + voice.setName( + SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); } if (context.testExpression(JSON_KEY_LANGUAGE, targetDepth)) { context.nextToken(); - voice.setLanguage(SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); + voice.setLanguage( + SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); } if (context.testExpression(JSON_KEY_GENDER, targetDepth)) { context.nextToken(); - voice.setGender(SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); + voice.setGender( + SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null @@ -81,9 +84,6 @@ public Voice unmarshall(JsonUnmarshallerContext context) throws Exception { } public static VoiceJsonUnmarshaller getInstance() { - if (instance == null) { - instance = new VoiceJsonUnmarshaller(); - } return instance; } } diff --git a/src/samples/IvonaSpeechCloudLexicons/SampleIvonaSpeechCloudDeleteLexicon.java b/src/samples/IvonaSpeechCloudLexicons/SampleIvonaSpeechCloudDeleteLexicon.java new file mode 100644 index 0000000..29e90e9 --- /dev/null +++ b/src/samples/IvonaSpeechCloudLexicons/SampleIvonaSpeechCloudDeleteLexicon.java @@ -0,0 +1,41 @@ +/* + * Copyright 2015 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. + */ +package IvonaSpeechCloudLexicons; + +import com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider; +import com.ivona.services.tts.IvonaSpeechCloudClient; +import com.ivona.services.tts.model.DeleteLexiconRequest; + +/** + * Class with sample delete lexicon usage. + * Shows how to delete the lexicon. + */ +public class SampleIvonaSpeechCloudDeleteLexicon { + + static IvonaSpeechCloudClient speechCloud; + + private final static String LEXICON_NAME = "LexiconToDelete"; + + private static void init() { + speechCloud = new IvonaSpeechCloudClient( + new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties")); + speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com"); + } + + public static void main(String[] args) { + init(); + DeleteLexiconRequest deleteLexiconRequest = new DeleteLexiconRequest().withLexiconName(LEXICON_NAME); + speechCloud.deleteLexicon(deleteLexiconRequest); + } + +} diff --git a/src/samples/IvonaSpeechCloudLexicons/SampleIvonaSpeechCloudGetLexicon.java b/src/samples/IvonaSpeechCloudLexicons/SampleIvonaSpeechCloudGetLexicon.java new file mode 100644 index 0000000..b33c1ab --- /dev/null +++ b/src/samples/IvonaSpeechCloudLexicons/SampleIvonaSpeechCloudGetLexicon.java @@ -0,0 +1,42 @@ +/* + * Copyright 2015 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. + */ +package IvonaSpeechCloudLexicons; + +import com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider; +import com.ivona.services.tts.IvonaSpeechCloudClient; +import com.ivona.services.tts.model.GetLexiconRequest; +import com.ivona.services.tts.model.GetLexiconResult; + +/** + * Class with sample get lexicon usage. + * Shows how to get the lexicon. + */ +public class SampleIvonaSpeechCloudGetLexicon { + + static IvonaSpeechCloudClient speechCloud; + + private final static String LEXICON_NAME = "LexiconToGet"; + + private static void init() { + speechCloud = new IvonaSpeechCloudClient( + new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties")); + speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com"); + } + + public static void main(String[] args) { + init(); + GetLexiconRequest getLexiconRequest = new GetLexiconRequest().withLexiconName(LEXICON_NAME); + GetLexiconResult getLexiconResult = speechCloud.getLexicon(getLexiconRequest); + System.out.println("Lexicon: " + getLexiconResult.getLexicon()); + } +} diff --git a/src/samples/IvonaSpeechCloudLexicons/SampleIvonaSpeechCloudListLexicons.java b/src/samples/IvonaSpeechCloudLexicons/SampleIvonaSpeechCloudListLexicons.java new file mode 100644 index 0000000..ef4b6c5 --- /dev/null +++ b/src/samples/IvonaSpeechCloudLexicons/SampleIvonaSpeechCloudListLexicons.java @@ -0,0 +1,38 @@ +/* + * Copyright 2015 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. + */ +package IvonaSpeechCloudLexicons; + +import com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider; +import com.ivona.services.tts.IvonaSpeechCloudClient; +import com.ivona.services.tts.model.ListLexiconsResult; + +/** + * Class with sample list lexicons usage. + * Shows how to get the list of lexicons. + */ +public class SampleIvonaSpeechCloudListLexicons { + + static IvonaSpeechCloudClient speechCloud; + + private static void init() { + speechCloud = new IvonaSpeechCloudClient( + new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties")); + speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com"); + } + + public static void main(String[] args) { + init(); + ListLexiconsResult listLexiconsResult = speechCloud.listLexicons(); + System.out.println("List of lexicons: " + listLexiconsResult); + } +} diff --git a/src/samples/IvonaSpeechCloudLexicons/SampleIvonaSpeechCloudPutLexicon.java b/src/samples/IvonaSpeechCloudLexicons/SampleIvonaSpeechCloudPutLexicon.java new file mode 100644 index 0000000..0320606 --- /dev/null +++ b/src/samples/IvonaSpeechCloudLexicons/SampleIvonaSpeechCloudPutLexicon.java @@ -0,0 +1,47 @@ +/* + * Copyright 2015 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. + */ +package IvonaSpeechCloudLexicons; + +import com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider; +import com.ivona.services.tts.IvonaSpeechCloudClient; +import com.ivona.services.tts.model.PutLexiconRequest; + +/** + * Class with sample put lexicon usage. + * Shows how to put the lexicon. + */ +public class SampleIvonaSpeechCloudPutLexicon { + + static IvonaSpeechCloudClient speechCloud; + + private final static String LEXICON_NAME = "LexiconToPut"; + private static final String LEXICON_CONTENTS = "" + + "" + + "test1test2" + + ""; + + private static void init() { + speechCloud = new IvonaSpeechCloudClient( + new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties")); + speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com"); + } + + public static void main(String[] args) { + init(); + Lexicon lexicon = new Lexicon().withName(LEXICON_NAME).withContents(LEXICON_CONTENTS); + PutLexiconRequest putLexiconRequest = new PutLexiconRequest().withLexicon(lexicon); + speechCloud.putLexicon(putLexiconRequest); + } +}