ssml2mp3 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -11
- data/lib/ssml2mp3/builder.rb +33 -28
- data/lib/ssml2mp3/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83b70099048b552d3a45008515ee1530f3bf47da
|
4
|
+
data.tar.gz: e1f589ee09a28cf1c9b7994fd7bd7e2594cfa987
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1123f621f2dc33735202dd510cc8406fad942d1fea6ceea656d09ad4d557d980563337e22ad806071c068275e4fe6a0cbf5912359d3c360e4ac5f3a8370158fd
|
7
|
+
data.tar.gz: 7c1a68c2583802aa9a879a9867c0c95b4be571281e4a69860daa9c6cf887247b632ecdcabfd606a062165843c31dc596bd505e502f4ea49adfcf30281575e3b1
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Ssml2mp3
|
2
|
+
[![Build Status](https://travis-ci.org/hogelog/ssml2mp3.svg?branch=master)](https://travis-ci.org/hogelog/ssml2mp3)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/ssml2mp3.svg)](http://badge.fury.io/rb/ssml2mp3)
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
5
|
+
SSML to mp3 powered by [Amazon Polly](https://aws.amazon.com/polly/)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,17 +22,13 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
25
|
+
```bash
|
26
|
+
$ ssml2mp3 foo.ssml foo.mp3
|
27
|
+
```
|
32
28
|
|
33
29
|
## Contributing
|
34
30
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hogelog/ssml2mp3.
|
36
32
|
|
37
33
|
|
38
34
|
## License
|
data/lib/ssml2mp3/builder.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require "aws-sdk-polly"
|
2
2
|
require "logger"
|
3
3
|
require "nokogiri"
|
4
|
-
require "htmlentities"
|
5
4
|
require "expeditor"
|
6
5
|
require "concurrent"
|
7
6
|
require "tmpdir"
|
@@ -26,7 +25,6 @@ module Ssml2mp3
|
|
26
25
|
max_threads: @max_threads,
|
27
26
|
)
|
28
27
|
)
|
29
|
-
@htmlentities = HTMLEntities.new
|
30
28
|
end
|
31
29
|
|
32
30
|
def synthesize_file(ssml_path, mp3_path)
|
@@ -86,39 +84,42 @@ module Ssml2mp3
|
|
86
84
|
elements = doc.root.children
|
87
85
|
|
88
86
|
header = (%r((.+<speak[^>]+>))m === ssml && $1)
|
89
|
-
split_ssml_(elements, "", []).map do |body_ssml|
|
90
|
-
header + body_ssml + "</speak>"
|
91
|
-
end
|
92
|
-
end
|
93
87
|
|
94
|
-
|
95
|
-
|
96
|
-
return buffer.size > 0 ? results << buffer : results
|
97
|
-
end
|
88
|
+
results = []
|
89
|
+
buffer = ""
|
98
90
|
|
99
|
-
|
91
|
+
while elements.size > 0 do
|
92
|
+
element = elements.shift
|
100
93
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
94
|
+
case element
|
95
|
+
when Nokogiri::XML::Text
|
96
|
+
text = html_encode(element.text)
|
97
|
+
when String
|
98
|
+
text = html_encode(element)
|
99
|
+
else
|
100
|
+
buffer += element.to_s
|
101
|
+
next
|
102
|
+
end
|
109
103
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
104
|
+
if text.size > POLLY_TEXT_LENGTH_LIMIT
|
105
|
+
split_texts = text.chars.each_slice(POLLY_TEXT_LENGTH_LIMIT).map(&:join)
|
106
|
+
elements = split_texts + elements
|
107
|
+
next
|
108
|
+
end
|
115
109
|
|
116
|
-
|
117
|
-
|
118
|
-
|
110
|
+
if text_size(buffer + text) > POLLY_TEXT_LENGTH_LIMIT
|
111
|
+
results << buffer
|
112
|
+
buffer = ""
|
113
|
+
end
|
114
|
+
|
115
|
+
buffer += text
|
119
116
|
end
|
120
117
|
|
121
|
-
|
118
|
+
results << buffer if buffer.size > 0
|
119
|
+
|
120
|
+
results.map do |body_ssml|
|
121
|
+
header + body_ssml + "</speak>"
|
122
|
+
end
|
122
123
|
end
|
123
124
|
|
124
125
|
def text_size(text)
|
@@ -132,5 +133,9 @@ module Ssml2mp3
|
|
132
133
|
gsub("</p>", '<break strength="strong"/>').
|
133
134
|
gsub(/([」】)』])/, '\1<break strength="strong"/>')
|
134
135
|
end
|
136
|
+
|
137
|
+
def html_encode(text)
|
138
|
+
text.gsub(/</, "<").gsub(/>/, ">")
|
139
|
+
end
|
135
140
|
end
|
136
141
|
end
|
data/lib/ssml2mp3/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ssml2mp3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hogelog
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-polly
|