use std::error::Error;
use std::fmt;
#[allow(warnings)]
use futures::future;
use futures::Future;
use rusoto_core::credential::ProvideAwsCredentials;
use rusoto_core::region;
use rusoto_core::request::{BufferedHttpResponse, DispatchSignedRequest};
use rusoto_core::{Client, RusotoError, RusotoFuture};
use rusoto_core::param::{Params, ServiceParams};
use rusoto_core::proto;
use rusoto_core::signature::SignedRequest;
use serde_json;
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DeleteLexiconInput {
#[serde(rename = "Name")]
pub name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DeleteLexiconOutput {}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeVoicesInput {
#[serde(rename = "IncludeAdditionalLanguageCodes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub include_additional_language_codes: Option<bool>,
#[serde(rename = "LanguageCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DescribeVoicesOutput {
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "Voices")]
#[serde(skip_serializing_if = "Option::is_none")]
pub voices: Option<Vec<Voice>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct GetLexiconInput {
#[serde(rename = "Name")]
pub name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct GetLexiconOutput {
#[serde(rename = "Lexicon")]
#[serde(skip_serializing_if = "Option::is_none")]
pub lexicon: Option<Lexicon>,
#[serde(rename = "LexiconAttributes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub lexicon_attributes: Option<LexiconAttributes>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct GetSpeechSynthesisTaskInput {
#[serde(rename = "TaskId")]
pub task_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct GetSpeechSynthesisTaskOutput {
#[serde(rename = "SynthesisTask")]
#[serde(skip_serializing_if = "Option::is_none")]
pub synthesis_task: Option<SynthesisTask>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Lexicon {
#[serde(rename = "Content")]
#[serde(skip_serializing_if = "Option::is_none")]
pub content: Option<String>,
#[serde(rename = "Name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct LexiconAttributes {
#[serde(rename = "Alphabet")]
#[serde(skip_serializing_if = "Option::is_none")]
pub alphabet: Option<String>,
#[serde(rename = "LanguageCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(rename = "LastModified")]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_modified: Option<f64>,
#[serde(rename = "LexemesCount")]
#[serde(skip_serializing_if = "Option::is_none")]
pub lexemes_count: Option<i64>,
#[serde(rename = "LexiconArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub lexicon_arn: Option<String>,
#[serde(rename = "Size")]
#[serde(skip_serializing_if = "Option::is_none")]
pub size: Option<i64>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct LexiconDescription {
#[serde(rename = "Attributes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub attributes: Option<LexiconAttributes>,
#[serde(rename = "Name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListLexiconsInput {
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ListLexiconsOutput {
#[serde(rename = "Lexicons")]
#[serde(skip_serializing_if = "Option::is_none")]
pub lexicons: Option<Vec<LexiconDescription>>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListSpeechSynthesisTasksInput {
#[serde(rename = "MaxResults")]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_results: Option<i64>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "Status")]
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ListSpeechSynthesisTasksOutput {
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "SynthesisTasks")]
#[serde(skip_serializing_if = "Option::is_none")]
pub synthesis_tasks: Option<Vec<SynthesisTask>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct PutLexiconInput {
#[serde(rename = "Content")]
pub content: String,
#[serde(rename = "Name")]
pub name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct PutLexiconOutput {}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct StartSpeechSynthesisTaskInput {
#[serde(rename = "LanguageCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(rename = "LexiconNames")]
#[serde(skip_serializing_if = "Option::is_none")]
pub lexicon_names: Option<Vec<String>>,
#[serde(rename = "OutputFormat")]
pub output_format: String,
#[serde(rename = "OutputS3BucketName")]
pub output_s3_bucket_name: String,
#[serde(rename = "OutputS3KeyPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub output_s3_key_prefix: Option<String>,
#[serde(rename = "SampleRate")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sample_rate: Option<String>,
#[serde(rename = "SnsTopicArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sns_topic_arn: Option<String>,
#[serde(rename = "SpeechMarkTypes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub speech_mark_types: Option<Vec<String>>,
#[serde(rename = "Text")]
pub text: String,
#[serde(rename = "TextType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub text_type: Option<String>,
#[serde(rename = "VoiceId")]
pub voice_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct StartSpeechSynthesisTaskOutput {
#[serde(rename = "SynthesisTask")]
#[serde(skip_serializing_if = "Option::is_none")]
pub synthesis_task: Option<SynthesisTask>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct SynthesisTask {
#[serde(rename = "CreationTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub creation_time: Option<f64>,
#[serde(rename = "LanguageCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(rename = "LexiconNames")]
#[serde(skip_serializing_if = "Option::is_none")]
pub lexicon_names: Option<Vec<String>>,
#[serde(rename = "OutputFormat")]
#[serde(skip_serializing_if = "Option::is_none")]
pub output_format: Option<String>,
#[serde(rename = "OutputUri")]
#[serde(skip_serializing_if = "Option::is_none")]
pub output_uri: Option<String>,
#[serde(rename = "RequestCharacters")]
#[serde(skip_serializing_if = "Option::is_none")]
pub request_characters: Option<i64>,
#[serde(rename = "SampleRate")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sample_rate: Option<String>,
#[serde(rename = "SnsTopicArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sns_topic_arn: Option<String>,
#[serde(rename = "SpeechMarkTypes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub speech_mark_types: Option<Vec<String>>,
#[serde(rename = "TaskId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub task_id: Option<String>,
#[serde(rename = "TaskStatus")]
#[serde(skip_serializing_if = "Option::is_none")]
pub task_status: Option<String>,
#[serde(rename = "TaskStatusReason")]
#[serde(skip_serializing_if = "Option::is_none")]
pub task_status_reason: Option<String>,
#[serde(rename = "TextType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub text_type: Option<String>,
#[serde(rename = "VoiceId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub voice_id: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct SynthesizeSpeechInput {
#[serde(rename = "LanguageCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(rename = "LexiconNames")]
#[serde(skip_serializing_if = "Option::is_none")]
pub lexicon_names: Option<Vec<String>>,
#[serde(rename = "OutputFormat")]
pub output_format: String,
#[serde(rename = "SampleRate")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sample_rate: Option<String>,
#[serde(rename = "SpeechMarkTypes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub speech_mark_types: Option<Vec<String>>,
#[serde(rename = "Text")]
pub text: String,
#[serde(rename = "TextType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub text_type: Option<String>,
#[serde(rename = "VoiceId")]
pub voice_id: String,
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct SynthesizeSpeechOutput {
pub audio_stream: Option<bytes::Bytes>,
pub content_type: Option<String>,
pub request_characters: Option<i64>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Voice {
#[serde(rename = "AdditionalLanguageCodes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub additional_language_codes: Option<Vec<String>>,
#[serde(rename = "Gender")]
#[serde(skip_serializing_if = "Option::is_none")]
pub gender: Option<String>,
#[serde(rename = "Id")]
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "LanguageCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(rename = "LanguageName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub language_name: Option<String>,
#[serde(rename = "Name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
}
#[derive(Debug, PartialEq)]
pub enum DeleteLexiconError {
LexiconNotFound(String),
ServiceFailure(String),
}
impl DeleteLexiconError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<DeleteLexiconError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"LexiconNotFoundException" => {
return RusotoError::Service(DeleteLexiconError::LexiconNotFound(err.msg))
}
"ServiceFailureException" => {
return RusotoError::Service(DeleteLexiconError::ServiceFailure(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for DeleteLexiconError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DeleteLexiconError {
fn description(&self) -> &str {
match *self {
DeleteLexiconError::LexiconNotFound(ref cause) => cause,
DeleteLexiconError::ServiceFailure(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeVoicesError {
InvalidNextToken(String),
ServiceFailure(String),
}
impl DescribeVoicesError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<DescribeVoicesError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"InvalidNextTokenException" => {
return RusotoError::Service(DescribeVoicesError::InvalidNextToken(err.msg))
}
"ServiceFailureException" => {
return RusotoError::Service(DescribeVoicesError::ServiceFailure(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for DescribeVoicesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeVoicesError {
fn description(&self) -> &str {
match *self {
DescribeVoicesError::InvalidNextToken(ref cause) => cause,
DescribeVoicesError::ServiceFailure(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum GetLexiconError {
LexiconNotFound(String),
ServiceFailure(String),
}
impl GetLexiconError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<GetLexiconError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"LexiconNotFoundException" => {
return RusotoError::Service(GetLexiconError::LexiconNotFound(err.msg))
}
"ServiceFailureException" => {
return RusotoError::Service(GetLexiconError::ServiceFailure(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for GetLexiconError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for GetLexiconError {
fn description(&self) -> &str {
match *self {
GetLexiconError::LexiconNotFound(ref cause) => cause,
GetLexiconError::ServiceFailure(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum GetSpeechSynthesisTaskError {
InvalidTaskId(String),
ServiceFailure(String),
SynthesisTaskNotFound(String),
}
impl GetSpeechSynthesisTaskError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<GetSpeechSynthesisTaskError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"InvalidTaskIdException" => {
return RusotoError::Service(GetSpeechSynthesisTaskError::InvalidTaskId(
err.msg,
))
}
"ServiceFailureException" => {
return RusotoError::Service(GetSpeechSynthesisTaskError::ServiceFailure(
err.msg,
))
}
"SynthesisTaskNotFoundException" => {
return RusotoError::Service(
GetSpeechSynthesisTaskError::SynthesisTaskNotFound(err.msg),
)
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for GetSpeechSynthesisTaskError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for GetSpeechSynthesisTaskError {
fn description(&self) -> &str {
match *self {
GetSpeechSynthesisTaskError::InvalidTaskId(ref cause) => cause,
GetSpeechSynthesisTaskError::ServiceFailure(ref cause) => cause,
GetSpeechSynthesisTaskError::SynthesisTaskNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListLexiconsError {
InvalidNextToken(String),
ServiceFailure(String),
}
impl ListLexiconsError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<ListLexiconsError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"InvalidNextTokenException" => {
return RusotoError::Service(ListLexiconsError::InvalidNextToken(err.msg))
}
"ServiceFailureException" => {
return RusotoError::Service(ListLexiconsError::ServiceFailure(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for ListLexiconsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListLexiconsError {
fn description(&self) -> &str {
match *self {
ListLexiconsError::InvalidNextToken(ref cause) => cause,
ListLexiconsError::ServiceFailure(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListSpeechSynthesisTasksError {
InvalidNextToken(String),
ServiceFailure(String),
}
impl ListSpeechSynthesisTasksError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<ListSpeechSynthesisTasksError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"InvalidNextTokenException" => {
return RusotoError::Service(ListSpeechSynthesisTasksError::InvalidNextToken(
err.msg,
))
}
"ServiceFailureException" => {
return RusotoError::Service(ListSpeechSynthesisTasksError::ServiceFailure(
err.msg,
))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for ListSpeechSynthesisTasksError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListSpeechSynthesisTasksError {
fn description(&self) -> &str {
match *self {
ListSpeechSynthesisTasksError::InvalidNextToken(ref cause) => cause,
ListSpeechSynthesisTasksError::ServiceFailure(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum PutLexiconError {
InvalidLexicon(String),
LexiconSizeExceeded(String),
MaxLexemeLengthExceeded(String),
MaxLexiconsNumberExceeded(String),
ServiceFailure(String),
UnsupportedPlsAlphabet(String),
UnsupportedPlsLanguage(String),
}
impl PutLexiconError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<PutLexiconError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"InvalidLexiconException" => {
return RusotoError::Service(PutLexiconError::InvalidLexicon(err.msg))
}
"LexiconSizeExceededException" => {
return RusotoError::Service(PutLexiconError::LexiconSizeExceeded(err.msg))
}
"MaxLexemeLengthExceededException" => {
return RusotoError::Service(PutLexiconError::MaxLexemeLengthExceeded(err.msg))
}
"MaxLexiconsNumberExceededException" => {
return RusotoError::Service(PutLexiconError::MaxLexiconsNumberExceeded(
err.msg,
))
}
"ServiceFailureException" => {
return RusotoError::Service(PutLexiconError::ServiceFailure(err.msg))
}
"UnsupportedPlsAlphabetException" => {
return RusotoError::Service(PutLexiconError::UnsupportedPlsAlphabet(err.msg))
}
"UnsupportedPlsLanguageException" => {
return RusotoError::Service(PutLexiconError::UnsupportedPlsLanguage(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for PutLexiconError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for PutLexiconError {
fn description(&self) -> &str {
match *self {
PutLexiconError::InvalidLexicon(ref cause) => cause,
PutLexiconError::LexiconSizeExceeded(ref cause) => cause,
PutLexiconError::MaxLexemeLengthExceeded(ref cause) => cause,
PutLexiconError::MaxLexiconsNumberExceeded(ref cause) => cause,
PutLexiconError::ServiceFailure(ref cause) => cause,
PutLexiconError::UnsupportedPlsAlphabet(ref cause) => cause,
PutLexiconError::UnsupportedPlsLanguage(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum StartSpeechSynthesisTaskError {
InvalidS3Bucket(String),
InvalidS3Key(String),
InvalidSampleRate(String),
InvalidSnsTopicArn(String),
InvalidSsml(String),
LanguageNotSupported(String),
LexiconNotFound(String),
MarksNotSupportedForFormat(String),
ServiceFailure(String),
SsmlMarksNotSupportedForTextType(String),
TextLengthExceeded(String),
}
impl StartSpeechSynthesisTaskError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<StartSpeechSynthesisTaskError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"InvalidS3BucketException" => {
return RusotoError::Service(StartSpeechSynthesisTaskError::InvalidS3Bucket(
err.msg,
))
}
"InvalidS3KeyException" => {
return RusotoError::Service(StartSpeechSynthesisTaskError::InvalidS3Key(
err.msg,
))
}
"InvalidSampleRateException" => {
return RusotoError::Service(StartSpeechSynthesisTaskError::InvalidSampleRate(
err.msg,
))
}
"InvalidSnsTopicArnException" => {
return RusotoError::Service(StartSpeechSynthesisTaskError::InvalidSnsTopicArn(
err.msg,
))
}
"InvalidSsmlException" => {
return RusotoError::Service(StartSpeechSynthesisTaskError::InvalidSsml(
err.msg,
))
}
"LanguageNotSupportedException" => {
return RusotoError::Service(
StartSpeechSynthesisTaskError::LanguageNotSupported(err.msg),
)
}
"LexiconNotFoundException" => {
return RusotoError::Service(StartSpeechSynthesisTaskError::LexiconNotFound(
err.msg,
))
}
"MarksNotSupportedForFormatException" => {
return RusotoError::Service(
StartSpeechSynthesisTaskError::MarksNotSupportedForFormat(err.msg),
)
}
"ServiceFailureException" => {
return RusotoError::Service(StartSpeechSynthesisTaskError::ServiceFailure(
err.msg,
))
}
"SsmlMarksNotSupportedForTextTypeException" => {
return RusotoError::Service(
StartSpeechSynthesisTaskError::SsmlMarksNotSupportedForTextType(err.msg),
)
}
"TextLengthExceededException" => {
return RusotoError::Service(StartSpeechSynthesisTaskError::TextLengthExceeded(
err.msg,
))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for StartSpeechSynthesisTaskError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for StartSpeechSynthesisTaskError {
fn description(&self) -> &str {
match *self {
StartSpeechSynthesisTaskError::InvalidS3Bucket(ref cause) => cause,
StartSpeechSynthesisTaskError::InvalidS3Key(ref cause) => cause,
StartSpeechSynthesisTaskError::InvalidSampleRate(ref cause) => cause,
StartSpeechSynthesisTaskError::InvalidSnsTopicArn(ref cause) => cause,
StartSpeechSynthesisTaskError::InvalidSsml(ref cause) => cause,
StartSpeechSynthesisTaskError::LanguageNotSupported(ref cause) => cause,
StartSpeechSynthesisTaskError::LexiconNotFound(ref cause) => cause,
StartSpeechSynthesisTaskError::MarksNotSupportedForFormat(ref cause) => cause,
StartSpeechSynthesisTaskError::ServiceFailure(ref cause) => cause,
StartSpeechSynthesisTaskError::SsmlMarksNotSupportedForTextType(ref cause) => cause,
StartSpeechSynthesisTaskError::TextLengthExceeded(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum SynthesizeSpeechError {
InvalidSampleRate(String),
InvalidSsml(String),
LanguageNotSupported(String),
LexiconNotFound(String),
MarksNotSupportedForFormat(String),
ServiceFailure(String),
SsmlMarksNotSupportedForTextType(String),
TextLengthExceeded(String),
}
impl SynthesizeSpeechError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<SynthesizeSpeechError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"InvalidSampleRateException" => {
return RusotoError::Service(SynthesizeSpeechError::InvalidSampleRate(err.msg))
}
"InvalidSsmlException" => {
return RusotoError::Service(SynthesizeSpeechError::InvalidSsml(err.msg))
}
"LanguageNotSupportedException" => {
return RusotoError::Service(SynthesizeSpeechError::LanguageNotSupported(
err.msg,
))
}
"LexiconNotFoundException" => {
return RusotoError::Service(SynthesizeSpeechError::LexiconNotFound(err.msg))
}
"MarksNotSupportedForFormatException" => {
return RusotoError::Service(SynthesizeSpeechError::MarksNotSupportedForFormat(
err.msg,
))
}
"ServiceFailureException" => {
return RusotoError::Service(SynthesizeSpeechError::ServiceFailure(err.msg))
}
"SsmlMarksNotSupportedForTextTypeException" => {
return RusotoError::Service(
SynthesizeSpeechError::SsmlMarksNotSupportedForTextType(err.msg),
)
}
"TextLengthExceededException" => {
return RusotoError::Service(SynthesizeSpeechError::TextLengthExceeded(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for SynthesizeSpeechError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for SynthesizeSpeechError {
fn description(&self) -> &str {
match *self {
SynthesizeSpeechError::InvalidSampleRate(ref cause) => cause,
SynthesizeSpeechError::InvalidSsml(ref cause) => cause,
SynthesizeSpeechError::LanguageNotSupported(ref cause) => cause,
SynthesizeSpeechError::LexiconNotFound(ref cause) => cause,
SynthesizeSpeechError::MarksNotSupportedForFormat(ref cause) => cause,
SynthesizeSpeechError::ServiceFailure(ref cause) => cause,
SynthesizeSpeechError::SsmlMarksNotSupportedForTextType(ref cause) => cause,
SynthesizeSpeechError::TextLengthExceeded(ref cause) => cause,
}
}
}
pub trait Polly {
fn delete_lexicon(
&self,
input: DeleteLexiconInput,
) -> RusotoFuture<DeleteLexiconOutput, DeleteLexiconError>;
fn describe_voices(
&self,
input: DescribeVoicesInput,
) -> RusotoFuture<DescribeVoicesOutput, DescribeVoicesError>;
fn get_lexicon(
&self,
input: GetLexiconInput,
) -> RusotoFuture<GetLexiconOutput, GetLexiconError>;
fn get_speech_synthesis_task(
&self,
input: GetSpeechSynthesisTaskInput,
) -> RusotoFuture<GetSpeechSynthesisTaskOutput, GetSpeechSynthesisTaskError>;
fn list_lexicons(
&self,
input: ListLexiconsInput,
) -> RusotoFuture<ListLexiconsOutput, ListLexiconsError>;
fn list_speech_synthesis_tasks(
&self,
input: ListSpeechSynthesisTasksInput,
) -> RusotoFuture<ListSpeechSynthesisTasksOutput, ListSpeechSynthesisTasksError>;
fn put_lexicon(
&self,
input: PutLexiconInput,
) -> RusotoFuture<PutLexiconOutput, PutLexiconError>;
fn start_speech_synthesis_task(
&self,
input: StartSpeechSynthesisTaskInput,
) -> RusotoFuture<StartSpeechSynthesisTaskOutput, StartSpeechSynthesisTaskError>;
fn synthesize_speech(
&self,
input: SynthesizeSpeechInput,
) -> RusotoFuture<SynthesizeSpeechOutput, SynthesizeSpeechError>;
}
#[derive(Clone)]
pub struct PollyClient {
client: Client,
region: region::Region,
}
impl PollyClient {
pub fn new(region: region::Region) -> PollyClient {
PollyClient {
client: Client::shared(),
region,
}
}
pub fn new_with<P, D>(
request_dispatcher: D,
credentials_provider: P,
region: region::Region,
) -> PollyClient
where
P: ProvideAwsCredentials + Send + Sync + 'static,
P::Future: Send,
D: DispatchSignedRequest + Send + Sync + 'static,
D::Future: Send,
{
PollyClient {
client: Client::new_with(credentials_provider, request_dispatcher),
region,
}
}
}
impl Polly for PollyClient {
fn delete_lexicon(
&self,
input: DeleteLexiconInput,
) -> RusotoFuture<DeleteLexiconOutput, DeleteLexiconError> {
let request_uri = format!("/v1/lexicons/{lexicon_name}", lexicon_name = input.name);
let mut request = SignedRequest::new("DELETE", "polly", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().and_then(|response| {
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<DeleteLexiconOutput, _>()?;
Ok(result)
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DeleteLexiconError::from_response(response))),
)
}
})
}
fn describe_voices(
&self,
input: DescribeVoicesInput,
) -> RusotoFuture<DescribeVoicesOutput, DescribeVoicesError> {
let request_uri = "/v1/voices";
let mut request = SignedRequest::new("GET", "polly", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
let mut params = Params::new();
if let Some(ref x) = input.include_additional_language_codes {
params.put("IncludeAdditionalLanguageCodes", x);
}
if let Some(ref x) = input.language_code {
params.put("LanguageCode", x);
}
if let Some(ref x) = input.next_token {
params.put("NextToken", x);
}
request.set_params(params);
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().and_then(|response| {
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<DescribeVoicesOutput, _>()?;
Ok(result)
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DescribeVoicesError::from_response(response))),
)
}
})
}
fn get_lexicon(
&self,
input: GetLexiconInput,
) -> RusotoFuture<GetLexiconOutput, GetLexiconError> {
let request_uri = format!("/v1/lexicons/{lexicon_name}", lexicon_name = input.name);
let mut request = SignedRequest::new("GET", "polly", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().and_then(|response| {
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<GetLexiconOutput, _>()?;
Ok(result)
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(GetLexiconError::from_response(response))),
)
}
})
}
fn get_speech_synthesis_task(
&self,
input: GetSpeechSynthesisTaskInput,
) -> RusotoFuture<GetSpeechSynthesisTaskOutput, GetSpeechSynthesisTaskError> {
let request_uri = format!("/v1/synthesisTasks/{task_id}", task_id = input.task_id);
let mut request = SignedRequest::new("GET", "polly", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().and_then(|response| {
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<GetSpeechSynthesisTaskOutput, _>()?;
Ok(result)
}))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(GetSpeechSynthesisTaskError::from_response(response))
}),
)
}
})
}
fn list_lexicons(
&self,
input: ListLexiconsInput,
) -> RusotoFuture<ListLexiconsOutput, ListLexiconsError> {
let request_uri = "/v1/lexicons";
let mut request = SignedRequest::new("GET", "polly", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
let mut params = Params::new();
if let Some(ref x) = input.next_token {
params.put("NextToken", x);
}
request.set_params(params);
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().and_then(|response| {
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<ListLexiconsOutput, _>()?;
Ok(result)
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(ListLexiconsError::from_response(response))),
)
}
})
}
fn list_speech_synthesis_tasks(
&self,
input: ListSpeechSynthesisTasksInput,
) -> RusotoFuture<ListSpeechSynthesisTasksOutput, ListSpeechSynthesisTasksError> {
let request_uri = "/v1/synthesisTasks";
let mut request = SignedRequest::new("GET", "polly", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
let mut params = Params::new();
if let Some(ref x) = input.max_results {
params.put("MaxResults", x);
}
if let Some(ref x) = input.next_token {
params.put("NextToken", x);
}
if let Some(ref x) = input.status {
params.put("Status", x);
}
request.set_params(params);
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().and_then(|response| {
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<ListSpeechSynthesisTasksOutput, _>()?;
Ok(result)
}))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(ListSpeechSynthesisTasksError::from_response(response))
}))
}
})
}
fn put_lexicon(
&self,
input: PutLexiconInput,
) -> RusotoFuture<PutLexiconOutput, PutLexiconError> {
let request_uri = format!("/v1/lexicons/{lexicon_name}", lexicon_name = input.name);
let mut request = SignedRequest::new("PUT", "polly", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
let encoded = Some(serde_json::to_vec(&input).unwrap());
request.set_payload(encoded);
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().and_then(|response| {
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<PutLexiconOutput, _>()?;
Ok(result)
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(PutLexiconError::from_response(response))),
)
}
})
}
fn start_speech_synthesis_task(
&self,
input: StartSpeechSynthesisTaskInput,
) -> RusotoFuture<StartSpeechSynthesisTaskOutput, StartSpeechSynthesisTaskError> {
let request_uri = "/v1/synthesisTasks";
let mut request = SignedRequest::new("POST", "polly", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
let encoded = Some(serde_json::to_vec(&input).unwrap());
request.set_payload(encoded);
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().and_then(|response| {
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<StartSpeechSynthesisTaskOutput, _>()?;
Ok(result)
}))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(StartSpeechSynthesisTaskError::from_response(response))
}))
}
})
}
fn synthesize_speech(
&self,
input: SynthesizeSpeechInput,
) -> RusotoFuture<SynthesizeSpeechOutput, SynthesizeSpeechError> {
let request_uri = "/v1/speech";
let mut request = SignedRequest::new("POST", "polly", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
let encoded = Some(serde_json::to_vec(&input).unwrap());
request.set_payload(encoded);
self.client.sign_and_dispatch(request, |response| {
if response.status.as_u16() == 200 {
Box::new(response.buffer().from_err().and_then(|response| {
let mut result = SynthesizeSpeechOutput::default();
result.audio_stream = Some(response.body);
if let Some(content_type) = response.headers.get("Content-Type") {
let value = content_type.to_owned();
result.content_type = Some(value)
};
if let Some(request_characters) =
response.headers.get("x-amzn-RequestCharacters")
{
let value = request_characters.to_owned();
result.request_characters = Some(value.parse::<i64>().unwrap())
};
Ok(result)
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(SynthesizeSpeechError::from_response(response))),
)
}
})
}
}