ncode-syosetu-polly 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/ncode2mp3 +1 -1
- data/lib/ncode_syosetu/builder/polly.rb +35 -14
- data/ncode-syosetu-polly.gemspec +1 -0
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e4ff3806326fef794399435bbf177031e40ad78
|
4
|
+
data.tar.gz: e60e6e5cecbf57f22be4d0fc76b2a24f590e7a30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd35ec825273a73a36399d663d797a54bc2f1060960e9bb8ebe4297f02c5540f8ee8b1b81891ba84c34af2d7c05842c1baee4d7f489079833680d45cd4290c32
|
7
|
+
data.tar.gz: 1a06cf7c207a7e92a0ad84e12047ac70b815403f12693d3bda215e6f2a191300a7016684b2f7ef1bf83b7369c07a5bdf8256a5056601ace8e4e4efae9820a448
|
data/exe/ncode2mp3
CHANGED
@@ -12,5 +12,5 @@ ncode, episode_number = ARGV
|
|
12
12
|
|
13
13
|
episode = NcodeSyosetu.client.get_episode(ncode, "dummy_title", episode_number)
|
14
14
|
|
15
|
-
builder = NcodeSyosetu::Builder::Polly.new
|
15
|
+
builder = NcodeSyosetu::Builder::Polly.new(logger: Logger.new(STDOUT))
|
16
16
|
builder.write_episode(episode, "#{ncode}-#{episode_number}.mp3")
|
@@ -1,40 +1,60 @@
|
|
1
1
|
require "aws-sdk-polly"
|
2
2
|
require "sanitize"
|
3
3
|
require "nokogiri"
|
4
|
+
require "expeditor"
|
5
|
+
require "concurrent"
|
4
6
|
|
5
7
|
module NcodeSyosetu
|
6
8
|
module Builder
|
7
9
|
class Polly
|
8
10
|
POLLY_TEXT_LENGTH_LIMIT = 1500
|
9
11
|
|
10
|
-
attr_reader :sample_rate, :client
|
12
|
+
attr_reader :sample_rate, :client, :logger, :service
|
11
13
|
|
12
14
|
def initialize(options={})
|
13
15
|
options[:region] ||= "us-west-2"
|
16
|
+
@logger = options.delete(:logger)
|
14
17
|
@sample_rate = options.delete(:sample_rate) || "16000"
|
15
18
|
@client = Aws::Polly::Client.new(options)
|
19
|
+
@service = Expeditor::Service.new(
|
20
|
+
executor: Concurrent::ThreadPoolExecutor.new(
|
21
|
+
min_threads: 0,
|
22
|
+
max_threads: 10,
|
23
|
+
)
|
24
|
+
)
|
16
25
|
end
|
17
26
|
|
18
27
|
def write_episode(episode, path)
|
19
28
|
tmp_files = []
|
20
29
|
ssmls = split_ssml(episode.body_ssml.gsub("\n", "")).map{|body_ssml| create_ssml(body_ssml) }
|
21
30
|
|
31
|
+
commands = []
|
32
|
+
|
33
|
+
dirname = File.dirname(path)
|
34
|
+
basename = File.basename(path, ".mp3")
|
35
|
+
tmpdir = File.join(dirname, basename)
|
36
|
+
FileUtils.mkdir(tmpdir)
|
37
|
+
|
22
38
|
ssmls.each_with_index do |ssml, i|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
39
|
+
|
40
|
+
File.write(File.join(tmpdir, "#{basename}-#{i}.ssml"), ssml)
|
41
|
+
tmp_path = File.join(tmpdir, "#{basename}-#{i}.mp3")
|
42
|
+
command = Expeditor::Command.new(service: service) do
|
43
|
+
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
|
+
)
|
52
|
+
end
|
53
|
+
command.start
|
54
|
+
commands << command
|
36
55
|
tmp_files << tmp_path
|
37
56
|
end
|
57
|
+
commands.each{|command| command.get }
|
38
58
|
File.open(path, "wb") do |file|
|
39
59
|
tmp_files.each do |tmp_path|
|
40
60
|
File.open(tmp_path, "rb") do |tmp_file|
|
@@ -43,6 +63,7 @@ module NcodeSyosetu
|
|
43
63
|
end
|
44
64
|
file.flush
|
45
65
|
end
|
66
|
+
logger.info("Generated: #{path}") if logger
|
46
67
|
end
|
47
68
|
|
48
69
|
def create_ssml(body_ssml)
|
data/ncode-syosetu-polly.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency "aws-sdk-polly", "1.0.0.rc2"
|
24
24
|
spec.add_dependency "sanitize", "~> 4.4"
|
25
25
|
spec.add_dependency "nokogiri", ">= 1.6"
|
26
|
+
spec.add_dependency "expeditor", "~> 0.5.0"
|
26
27
|
|
27
28
|
spec.add_development_dependency "bundler", "~> 1.13"
|
28
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ncode-syosetu-polly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hogelog
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2.
|
19
|
+
version: 0.2.1
|
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.
|
26
|
+
version: 0.2.1
|
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.
|
33
|
+
version: 0.2.1
|
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.
|
40
|
+
version: 0.2.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: aws-sdk-polly
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: expeditor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.5.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.5.0
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: bundler
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|