├── .gitignore
├── example
└── index.js
├── docs
└── natural-rules.md
├── CONTRIBUTING.md
├── package.json
├── LICENSE
├── README.md
├── index.js
└── CODE_OF_CONDUCT.md
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | package-*
3 |
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 | const PollyMolly = require('pollymolly')
2 |
3 | // Text -> SSML
4 | console.log(PollyMolly.text2ssml('Hello World'))
5 |
6 | // SSML -> Text
7 | console.log(PollyMolly.ssml2text('Hello World'))
8 |
9 | // Download File
10 | PollyMolly.download({ 'Text': 'Hello World' }, 'media/hello.mp3', function() {
11 | console.log('File Saved!')
12 | })
13 |
--------------------------------------------------------------------------------
/docs/natural-rules.md:
--------------------------------------------------------------------------------
1 | # Natural Language Rules
2 |
3 | ## Pauses
4 | Before
5 | ```
6 | The curator painted the dinosaur orange - a color hated by everyone.
7 | ```
8 | [Before .mp3](https://s3.amazonaws.com/pollymolly-demo/pause-dash-before.mp3)
9 |
10 | After
11 | ```
12 | The curator painted the dinosaur orange a color hated by everyone.
13 | ```
14 | [After .mp3](https://s3.amazonaws.com/pollymolly-demo/pause-dash.mp3)
15 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | You decided to contribute to this project? Great, thanks a lot!
2 |
3 | ## Pull Requests
4 | Make sure that your coding style match the project
5 |
6 | 1. `npm install` to install dependencies
7 |
8 | If you get strange compilation errors, try to remove all `node_modules` in the project.
9 |
10 | ## Issues
11 |
12 | When filing an issue please make sure, that you give all information needed.
13 |
14 | This includes:
15 |
16 | - description of what you're trying to do
17 | - package.json
18 | - log of the terminal output
19 | - node version
20 | - npm version
21 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "pollymolly",
3 | "version": "0.2.0",
4 | "description": "PollyMolly is a AWS Polly node.js wrapper with a better speech synthesis algorithm to provided a more natural sounding voice.",
5 | "main": "index.js",
6 | "homepage": "https://github.com/terrillo/PollyMolly",
7 | "author": "Terrillo Walls ",
8 | "contributors": [],
9 | "scripts": {
10 | "test": "echo \"Error: no test specified\" && exit 1"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "https://github.com/terrillo/PollyMolly.git"
15 | },
16 | "bugs": {
17 | "url": "https://github.com/terrillo/PollyMolly/issues"
18 | },
19 | "engines": {
20 | "node": "*"
21 | },
22 | "keywords": [
23 | "aws",
24 | "aws-sdk",
25 | "aws-polly",
26 | "speech-synthesis",
27 | "SSML"
28 | ],
29 | "license": "MIT",
30 | "dependencies": {
31 | "aws-sdk": "^2.77.0"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Terrillo Walls
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PollyMolly
2 | PollyMolly is a AWS Polly node.js wrapper with a better speech synthesis algorithm to provided a more natural sounding voice. The base of the project uses the Speech Synthesis Markup Language (SSML). [https://www.w3.org/TR/speech-synthesis/](https://www.w3.org/TR/speech-synthesis/)
3 |
4 | ## Install
5 | `npm install pollymolly`
6 |
7 | ## Features
8 | - Convert Text to SSML
9 | - Convert SSML to Text
10 | - Download mp3 from AWS Polly
11 |
12 | ## Other docs
13 | - [Natural Language Rules](docs/natural-rules.md)
14 |
15 | ## Todo
16 | - [x] Download mp3s from AWS Polly
17 | - [ ] Large file download
18 | - [ ] "Natural Pause" Algorithm
19 | - [ ] Improved Pronunciation
20 | - [x] Change Voice
21 | - [ ] Change region
22 |
23 | ## Usage
24 | ```
25 | const PollyMolly = require('pollymolly')
26 | ```
27 |
28 | ### Text -> SSML `text2ssml()`
29 | Convert a plain text string to the Speech Synthesis Markup Language
30 | ```
31 | PollyMolly.text2ssml('Hello World')
32 | > Hello World
33 | ```
34 |
35 | ### SSML -> Text `ssml2text()`
36 | Convert Speech Synthesis Markup Language to plain text
37 | ```
38 | PollyMolly.ssml2text('Hello World')
39 | > Hello World
40 | ```
41 |
42 | ### is SSML `isSSML()`
43 | Check to see if string is SSML
44 | ```
45 | PollyMolly.isSSML('Hello World')
46 | > true
47 | ```
48 |
49 | ### is Text `isText()`
50 | Check to see if string is not SSML
51 | ```
52 | PollyMolly.isSSML('Hello World')
53 | > false
54 | ```
55 |
56 | ### Natural `natural()`
57 | Convert a string to a more natural speaking SSML
58 | ```
59 | PollyMolly.natural('The curator painted the dinosaur orange - a color hated by everyone.')
60 | > The curator painted the dinosaur orange a color hated by everyone.
61 | ```
62 |
63 | ### Download File `download()`
64 | Download .mp3 from AWS Polly
65 | ```
66 | PollyMolly.download({ 'Text': 'Hello World' }, 'sound.mp3', function() {
67 | console.log('DONE')
68 | })
69 | ```
70 |
71 | ## Changelog
72 | **0.1v**
73 | - `text2ssml()`
74 | - `ssml2text()`
75 | - `download()`
76 |
77 | **0.2v**
78 | - `isSSML()`
79 | - `isText()`
80 | - `natural()`
81 | - `download()` now supports the full AWS download params. [http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Polly.html](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Polly.html)
82 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const AWS = require('aws-sdk')
4 | const Fs = require('fs')
5 |
6 | const Polly = new AWS.Polly({
7 | signatureVersion: 'v4',
8 | region: 'us-east-1'
9 | })
10 |
11 | const PollyMolly = {
12 |
13 | /**
14 | * is Text
15 | * @param {string} string
16 | * @return {boolean}
17 | */
18 | isText: function(string) {
19 | const SSMLtag = /<[^>]+>/ig;
20 | if (SSMLtag.exec(string) == null) { //!arg1
21 | return true
22 | }
23 | else {
24 | return false
25 | }
26 | },
27 |
28 | /**
29 | * is SSML
30 | * @param {string} string
31 | * @return {boolean}
32 | */
33 | isSSML: function(string) {
34 | const SSMLtag = /<[^>]+>/ig;
35 | if (SSMLtag.exec(string) !== null) { //!arg1
36 | return true
37 | }
38 | else {
39 | return false
40 | }
41 | },
42 |
43 | /**
44 | * Text -> SSML
45 | * @param {string} string - Plain text
46 | * @return {string}
47 | */
48 | ssml2text: function(string) {
49 | return (string).replace(/<[^>]+>/ig,''); //!arg1
50 | },
51 |
52 | /**
53 | * SSML -> Text
54 | * @param {string} string - SSML string
55 | * @return {string}
56 | */
57 | text2ssml: function(string) {
58 | if (PollyMolly.isText(string)) {
59 | string = PollyMolly.ssml2text(string) //!arg1
60 | }
61 | return `${string}`;
62 | },
63 |
64 | /**
65 | * Download .mp3 from AWS Polly
66 | * @param {object} params - Text, OutputFormat, & VoiceId
67 | * @param {string} file - Path to file including .mp3 extension
68 | * @param {function} fn - Callback function
69 | * @return {string}
70 | */
71 | download: function(params, file, fn) {
72 | const defaultParams = {
73 | 'Text': 'Hello World',
74 | 'OutputFormat': 'mp3',
75 | 'VoiceId': 'Joanna'
76 | }
77 | const requestParams = Object.assign({}, defaultParams, params); //!arg1
78 | Polly.synthesizeSpeech(requestParams, (err, data) => {
79 | if (err) {
80 | console.log(err)
81 | } else if (data) {
82 | if (data.AudioStream instanceof Buffer) {
83 | Fs.writeFile(file, data.AudioStream, function(err) { //!arg2
84 | if (err) {
85 | return console.log(err)
86 | }
87 | if (fn) {
88 | fn(file)
89 | }
90 | })
91 | }
92 | }
93 | })
94 | },
95 |
96 | /**
97 | * Convert a string to a more natural speaking SSML
98 | * @param {string} string
99 | * @return {string} - SSML
100 | */
101 | natural: function(string) {
102 | if (PollyMolly.isText(string)) {
103 | string = PollyMolly.text2ssml(string) //!arg1
104 | }
105 |
106 | // Natural Pauses
107 | string = string.replace('-', '')
108 |
109 | // Done
110 | return string
111 | }
112 |
113 | }
114 |
115 | module.exports = PollyMolly
116 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at terrillo@terrillo.me. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------