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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21b132ef0982c2114fd73b8ae7028d87596cc4db
4
- data.tar.gz: 06c9cdcbacffb669c363c867997ec31359e09038
3
+ metadata.gz: 83b70099048b552d3a45008515ee1530f3bf47da
4
+ data.tar.gz: e1f589ee09a28cf1c9b7994fd7bd7e2594cfa987
5
5
  SHA512:
6
- metadata.gz: '09d24955dd856ed0dd0c8f718333bce810c185f901fa2ad11cd75d271104539ec152dc5f61c477d8bd6efe88efcec75b48757b93bc3136530d397158d1870649'
7
- data.tar.gz: e512530da283d805911df4d955e8cb42a24bbaa196762fc821d1033a50d24ad93a55fd4738708d64a7dc032d256d49b5ddab5eee0fbc5c7496167106fd11da64
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ssml2mp3`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
26
-
27
- ## Development
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/[USERNAME]/ssml2mp3.
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hogelog/ssml2mp3.
36
32
 
37
33
 
38
34
  ## License
@@ -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
- def split_ssml_(elements, buffer, results)
95
- if elements.empty?
96
- return buffer.size > 0 ? results << buffer : results
97
- end
88
+ results = []
89
+ buffer = ""
98
90
 
99
- element = elements.shift
91
+ while elements.size > 0 do
92
+ element = elements.shift
100
93
 
101
- case element
102
- when Nokogiri::XML::Text
103
- text = @htmlentities.encode(element.text)
104
- when String
105
- text = @htmlentities.encode(element)
106
- else
107
- return split_ssml_(elements, buffer + element.to_s, results)
108
- end
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
- if text_size(text) > POLLY_TEXT_LENGTH_LIMIT
111
- split_texts = text.chars.each_slice(POLLY_TEXT_LENGTH_LIMIT).map(&:join)
112
- elements = split_texts + elements
113
- return split_ssml_(split_texts + elements, buffer, results)
114
- end
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
- if text_size(buffer + text) > POLLY_TEXT_LENGTH_LIMIT
117
- results << buffer
118
- buffer = ""
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
- split_ssml_(elements, buffer + text, results)
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(/</, "&lt;").gsub(/>/, "&gt;")
139
+ end
135
140
  end
136
141
  end
@@ -1,3 +1,3 @@
1
1
  module Ssml2mp3
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-17 00:00:00.000000000 Z
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