![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
ssml-split
Advanced tools
Splits long texts with SSML tags by batches suitable for working with AWS Polly TTS and Google Cloud Text to Speech.
Splits SSML strings into batches AWS Polly ánd Google's Text to Speech API can consume.
hardLimit
..
, ,
, ;
or space. Can be configured.Based on polly-ssml-split by @oleglegun
Install the package with:
npm install ssml-split --save
Import the package and set the options. Use the .split()
method to split your SSML string. You can tweak the softLimit
to see what works for you. I suggest you keep the hardLimit
at the limitation limit of the respective API:
import SSMLSplit from 'ssml-split';
const ssmlSplit = new SSMLSplit({
// The service you are using: "google" or "aws"
synthesizer: 'google',
// Finds a possible split moment starting from 4000 characters
softLimit: 4000,
// Google Text to Speech limitation
hardLimit: 5000,
// Allow to split large paragraphs, set to false to keep your <p></p> intact
breakParagraphsAboveHardLimit: true
});
const batches = ssmlSplit.split('<speak>your long ssml here</speak>');
Option | Type | Default | Description |
---|---|---|---|
synthesizer | string | aws | Set to which synthesizer you are using. Useful for when you use breakParagraphsAboveHardLimit . It allows the library to determine the correct break length, as that differs per synthesizer service. |
softLimit | number | 1500 | The amount of characters the script will start trying to break-up your SSML in multiple parts. You can tweak this number to see what works for you. |
hardLimit | number | 3000 | The amount of characters the script should stay below for maximum size per SSML part. If any batch size goes above this, the script will error. This hard limit is the character limit of the AWS or Google API you are using. |
breakParagraphsAboveHardLimit | boolean | false | Set to true to allow the script to break up large paragraphs by removing the <p> and replacing the </p> with a <break strength="x-strong" /> (for aws ) or <break strength="x-weak" /> (for google ). Which results in the same pause. Requires option synthesizer to be set. |
extraSplitChars | string | ,;. | Characters that can be used as split markers for plain text. |
By using the option synthesizer: 'google'
the library will include counting SSML tags characters to determine the best possible split moment. This makes the library also work with Google's Text to Speech API.
For example:
<speak><p>some text</p></speak>
The default behaviour would count that as 9 characters, which is fine for AWS Polly, but not for Google's Text to Speech API.
With synthesizer: 'google'
it will be count as 31 characters, just like Google's Text to Speech API counts it.
This should prevent you from seeing this error when using Google's Text to Speech API:
INVALID_ARGUMENT: 5000 characters limit exceeded.
By adding the option breakParagraphsAboveHardLimit: true
you allow the script to break up large paragraphs by removing the <p>
and replacing the </p>
with a <break strength="x-strong" />
for AWS or <break strength="x-weak" />
for Google. Which results in the same pause. This allows the library to properly split large paragraphs.
Using this option will result in 20 more characters, per paragraph, to your usage when using Google's Text to Speech API.
If you work with large paragraphs and you do not use this option, you might run into errors like SSML tag appeared to be too long
.
Using this option is recommended when you have SSML length that goes above the hardLimit
.
new SSMLSplit({
synthesizer: 'aws',
softLimit: 2000,
hardLimit: 3000, // AWS Polly limitation
breakParagraphsAboveHardLimit: true, // optional, but recommended when you have large <p>'s
})
new SSMLSplit({
synthesizer: 'google',
softLimit: 4000,
hardLimit: 5000, // Google Text to Speech API limitation
breakParagraphsAboveHardLimit: true, // optional, but recommended when you have large <p>'s
})
The polly-ssml-split by @oleglegun library already handles splitting of SSML correctly for AWS Polly, but wasn't working properly for Google's Text to Speech. So I just modified the package to fit my needs.
polly-ssml-split
:synthesizer
option to count characters based on the complete SSML tag and not just the included text characters. Which is required if you work with Google's Text to Speech API..configure
method and use the class constructor method for it instead.breakParagraphsAboveHardLimit
options to break up large paragraphs by removing the <p>
and replacing the </p>
with a <break strength="x-strong" />
for AWS or <break strength="x-weak" />
for Google. Which results in the same pause. This allows the library to properly split the paragraph and to send less batches to the text to speech API's.Any contribution is appreciated! Please read our CONTRIBUTING.md on how to contribute.
Use a test-driven approach when developing new features or fixing bugs.
Develop:
$ npm install
$ npm run dev
Run tests on file change:
$ npm test:watch
Build Typescript to Javascript:
$ npm run build
Run all tests:
$ npm test
8 January 2020
FAQs
Splits long texts with SSML tags by batches suitable for working with AWS Polly TTS and Google Cloud Text to Speech.
The npm package ssml-split receives a total of 6 weekly downloads. As such, ssml-split popularity was classified as not popular.
We found that ssml-split demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.