ncode-syosetu-polly 0.2.1 → 0.2.2

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: 9e4ff3806326fef794399435bbf177031e40ad78
4
- data.tar.gz: e60e6e5cecbf57f22be4d0fc76b2a24f590e7a30
3
+ metadata.gz: 07b6ac5d9bc4b8df8b12b2511e2f7b0f75abaf1e
4
+ data.tar.gz: 2bcd10de8e21838143005136d35762b9bd1d039f
5
5
  SHA512:
6
- metadata.gz: bd35ec825273a73a36399d663d797a54bc2f1060960e9bb8ebe4297f02c5540f8ee8b1b81891ba84c34af2d7c05842c1baee4d7f489079833680d45cd4290c32
7
- data.tar.gz: 1a06cf7c207a7e92a0ad84e12047ac70b815403f12693d3bda215e6f2a191300a7016684b2f7ef1bf83b7369c07a5bdf8256a5056601ace8e4e4efae9820a448
6
+ metadata.gz: 508384495e2635f45a26ed40b8f27d7632b2ed9c040c4f3ba4dfced45a8a950defaf3fb79953a16c82723655c8c1dd014a3e64e38793f8a631c42fc2880b29d7
7
+ data.tar.gz: c337d14dca9d9adef7c54fc249f0c87d5a784a334efaa09c991f0ac172d0c30bc58a483b7945e0e3e48a4e86f78c12ccdb251be3df06ba8d8069c1bba64875d0
@@ -3,11 +3,12 @@ require "sanitize"
3
3
  require "nokogiri"
4
4
  require "expeditor"
5
5
  require "concurrent"
6
+ require "htmlentities"
6
7
 
7
8
  module NcodeSyosetu
8
9
  module Builder
9
10
  class Polly
10
- POLLY_TEXT_LENGTH_LIMIT = 1500
11
+ POLLY_TEXT_LENGTH_LIMIT = 1000
11
12
 
12
13
  attr_reader :sample_rate, :client, :logger, :service
13
14
 
@@ -15,11 +16,13 @@ module NcodeSyosetu
15
16
  options[:region] ||= "us-west-2"
16
17
  @logger = options.delete(:logger)
17
18
  @sample_rate = options.delete(:sample_rate) || "16000"
19
+ @max_threads = options.delete(:max_threads) || 10
18
20
  @client = Aws::Polly::Client.new(options)
21
+ @htmlentities = HTMLEntities.new
19
22
  @service = Expeditor::Service.new(
20
23
  executor: Concurrent::ThreadPoolExecutor.new(
21
24
  min_threads: 0,
22
- max_threads: 10,
25
+ max_threads: @max_threads,
23
26
  )
24
27
  )
25
28
  end
@@ -33,22 +36,28 @@ module NcodeSyosetu
33
36
  dirname = File.dirname(path)
34
37
  basename = File.basename(path, ".mp3")
35
38
  tmpdir = File.join(dirname, basename)
36
- FileUtils.mkdir(tmpdir)
39
+ FileUtils.mkdir_p(tmpdir)
37
40
 
38
41
  ssmls.each_with_index do |ssml, i|
39
-
40
- File.write(File.join(tmpdir, "#{basename}-#{i}.ssml"), ssml)
42
+ tmp_ssml_path = File.join(tmpdir, "#{basename}-#{i}.ssml")
43
+ File.write(tmp_ssml_path, ssml)
41
44
  tmp_path = File.join(tmpdir, "#{basename}-#{i}.mp3")
42
45
  command = Expeditor::Command.new(service: service) do
43
46
  logger.info("#{tmp_path}...") if logger
44
- client.synthesize_speech(
45
- response_target: tmp_path,
46
- output_format: "mp3",
47
- sample_rate: sample_rate,
48
- text: ssml,
49
- text_type: "ssml",
50
- voice_id: "Mizuki",
51
- )
47
+ begin
48
+ client.synthesize_speech(
49
+ response_target: tmp_path,
50
+ output_format: "mp3",
51
+ sample_rate: sample_rate,
52
+ text: ssml,
53
+ text_type: "ssml",
54
+ voice_id: "Mizuki",
55
+ )
56
+ rescue => e
57
+ logger.error("#{e.message}\n#{ssml}")
58
+ logger.error("#{e.message}: #{tmp_ssml_path}\n#{ssml}")
59
+ raise e
60
+ end
52
61
  end
53
62
  command.start
54
63
  commands << command
@@ -86,13 +95,16 @@ module NcodeSyosetu
86
95
  while elements.size > 0 do
87
96
  element = elements.shift
88
97
 
89
- unless element.is_a?(Nokogiri::XML::Text) || element.is_a?(String)
90
- buffer.print(element.to_s)
91
- next
98
+ case element
99
+ when Nokogiri::XML::Text
100
+ text = @htmlentities.encode(element.text)
101
+ when String
102
+ text = @htmlentities.encode(element)
103
+ else
104
+ buffer.print(element.to_s)
105
+ next
92
106
  end
93
107
 
94
- text = element.to_s
95
-
96
108
  if text.size > POLLY_TEXT_LENGTH_LIMIT
97
109
  elements = text.chars.each_slice(POLLY_TEXT_LENGTH_LIMIT).map(&:join) + elements
98
110
  next
@@ -103,7 +115,7 @@ module NcodeSyosetu
103
115
  buffer = StringIO.new
104
116
  text_count = 0
105
117
  end
106
- buffer.print(element.to_s)
118
+ buffer.print(text)
107
119
  text_count += text.size
108
120
  end
109
121
  results << buffer.string if buffer.size > 0
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "sanitize", "~> 4.4"
25
25
  spec.add_dependency "nokogiri", ">= 1.6"
26
26
  spec.add_dependency "expeditor", "~> 0.5.0"
27
+ spec.add_dependency "htmlentities"
27
28
 
28
29
  spec.add_development_dependency "bundler", "~> 1.13"
29
30
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncode-syosetu-polly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
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-08 00:00:00.000000000 Z
11
+ date: 2017-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ncode-syosetu-core
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.1
19
+ version: 0.2.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.1
26
+ version: 0.2.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ncode-syosetu-ssml
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.1
33
+ version: 0.2.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.1
40
+ version: 0.2.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: aws-sdk-polly
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.5.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: htmlentities
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: bundler
99
113
  requirement: !ruby/object:Gem::Requirement