Synthesize more than 1500 characters using AWS Polly?

4.2k views Asked by At

My idea was to use AWS Polly to read aloud some news from an RSS feed. As per this link I understand that Polly is very flexible in terms of characters to be converted as one of the examples is "Adventures of Huckelberry Finn" by Mark Twain ~600k characters The problem is that when I try to convert my articles to speech I am getting the following error:

An error occurred (TextLengthExceededException) when calling the SynthesizeSpeech operation: Maximum text length has been exceeded

The text I was trying to convert was about 5000 characters.

Is there any way (with or without the API) to convert long strings of text with Polly without having to cut them into million different pieces?

Any tip in the right direction will be appreciated,

Thanks

4

There are 4 answers

6
Michael - sqlbot On BEST ANSWER

The size of the input text can be up to 1500 billed characters (3000 total characters). SSML tags are not counted as billed characters.

http://docs.aws.amazon.com/polly/latest/dg/limits.html

The pricing examples seem to be intended to give a sense of the relatively low cost of voicing a large work, but the work would actually need to be divided into groups of sentences and submitted to the API, which is the only interface -- the SDKs and CLI call the same SynthesizeSpeech API.

1
user3072843 On

How to create long audio files is described in the docs: https://docs.aws.amazon.com/polly/latest/dg/longer-cli.html

An aws-CLI call might look like this:

aws polly start-speech-synthesis-task \
--region eu-central-1 \
--endpoint-url "https://polly.eu-central-1.amazonaws.com/" \
--output-format mp3 \
--output-s3-bucket-name your-bucket-name \
--output-s3-key-prefix optional/prefix/path/file \
--voice-id Hans \
--text-type ssml \
--text file://output.xml \
--speech-mark-types='["sentence", "word", "ssml"]' \

As you can see you will need an S3-bucket for (temporay) storage.

0
Jonathan Banon On

I have no special tip without breaking a text in pieces, but i wrote an article with the way to do it in NodeJS. If you don't have any other alternative, feel free to review and comment it !

How to handle more than 1500 characters with AWS Polly text-to-speech

0
Aaron_Best On

I'm sure you have already found an answer to this or moved on by now. But I want to help anyone in the future with this problem.

I had the same issue using AWS Polly not letting me send more than 1500 chars at a time. So I wrote some javascript to help break the text into 230 word chunks then send to the API one after another then stitch all the mp3 files together before I buffered it and played it.

Here is my Github for it: https://github.com/Aaronbest94/Polly-Character-Limitations

Its not the most elegant Javascript be it does work and I hope it will help anyone reading this in the future.