aozora-polly 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a497fd6d817b2f368f97232a5bc4783c85eee9a
4
+ data.tar.gz: 132a4ae801948530762e268f86854f760f3738ec
5
+ SHA512:
6
+ metadata.gz: 5ce14ba688d2cc3bac8181986467371f6f15e7947b62bd8d7631c70188323d83dc23fb8ac430944958cb1712cc6fb6788a3c3b9303e970bef981d7cf997ea229
7
+ data.tar.gz: 84deb371a7c8db39ccd71f4b8ecb3b34a38e913b28f7afdb29209387b92d50a3b7f86292def86775feddf9413d3b5edef59bc882c98e73edd408d51009cf316e
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.10
5
+ - 2.2.6
6
+ - 2.3.3
7
+ - 2.4.0
8
+ before_install: gem install bundler -v 1.13.7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aozora-ssml.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 hogelog
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # AozoraPolly
2
+ [![Build Status](https://travis-ci.org/hogelog/aozora-polly.svg?branch=master)](https://travis-ci.org/hogelog/aozora-polly)
3
+ [![Gem Version](https://badge.fury.io/rb/aozora-polly.svg)](http://badge.fury.io/rb/aozora-polly)
4
+
5
+
6
+ Aozora Bunko XHTML to mp3 converter powered by [Amazon Polly](https://aws.amazon.com/polly/).
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'aozora-polly'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install aozora-polly
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ AozoraPolly.html2ssml(html) # => ssml string
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hogelog/aozora-polly.
33
+
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
38
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aozora_polly/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aozora-polly"
8
+ spec.version = AozoraPolly::VERSION
9
+ spec.authors = ["hogelog"]
10
+ spec.email = ["konbu.komuro@gmail.com"]
11
+
12
+ spec.summary = %q{aozora bunko}
13
+ spec.homepage = "https://github.com/hogelog/aozora-polly"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "sanitize", "~> 4.4"
24
+ spec.add_dependency "nokogiri", ">= 1.6"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.13"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "pry"
30
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "aozora/ssml"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'aozora-polly'
5
+ require 'open-uri'
6
+ require 'pry'
7
+
8
+ if ARGV.size == 0
9
+ puts "#$0 url mp3"
10
+ exit
11
+ end
12
+
13
+ aozora_url, ssml_path = ARGV
14
+
15
+ ssml = AozoraPolly.url2ssml(aozora_url)
16
+ File.write(ssml_path, ssml)
17
+ puts "Generated: #{ssml_path}"
@@ -0,0 +1,17 @@
1
+ require "aozora_polly/version"
2
+ require "aozora_polly/builder"
3
+ require "aozora_polly/document"
4
+
5
+ module AozoraPolly
6
+ def self.builder
7
+ @builder ||= ::AozoraPolly::Builder.new
8
+ end
9
+
10
+ def self.url2ssml(*args)
11
+ builder.url2ssml(*args)
12
+ end
13
+
14
+ def self.html2ssml(*args)
15
+ builder.html2ssml(*args)
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ require "sanitize"
2
+ require "net/http"
3
+
4
+ module AozoraPolly
5
+ class Builder
6
+ def url2ssml(aozora_url)
7
+ uri = URI.parse(aozora_url)
8
+ html = Net::HTTP.get(uri).force_encoding("cp932")
9
+ html2ssml(html)
10
+ end
11
+
12
+ def html2ssml(html)
13
+ doc = ::AozoraPolly::Document.parse(html.encode("utf-8"))
14
+
15
+ main_ssml = html2ssml_fragment(doc.main_text)
16
+ bib_ssml = html2ssml_fragment(doc.bibliography)
17
+ create_ssml(doc, main_ssml + bib_ssml)
18
+ end
19
+
20
+ def html2ssml_fragment(fragment)
21
+ Sanitize.
22
+ fragment(fragment, elements: %w(br ruby rb rp rt div h1 h2 h3 h4 h5)).
23
+ gsub(%r(<br\s*/?>), '<break />').
24
+ gsub(%r(<(?:h\d|div)[^>]*>), '<p>').
25
+ gsub(%r(</(?:h\d|div)>), '</p>').
26
+ gsub(%r(</?ruby>), '').
27
+ gsub(%r(<rb>[^<]+</rb>), '').
28
+ gsub(%r(<rp>[^<]+</rp>), '').
29
+ gsub(%r(</?rt>), '')
30
+ end
31
+
32
+ def create_ssml(doc, ssml_body)
33
+ <<-XML
34
+ <?xml version="1.0"?>
35
+ <speak version="1.1" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="ja">
36
+ <p>#{doc.title}</p>
37
+ <p>#{doc.author}</p>
38
+
39
+ #{ssml_body}
40
+ </speak>
41
+ XML
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ require "nokogiri"
2
+
3
+ module AozoraPolly
4
+ class Document
5
+ attr_reader :title, :author, :main_text, :bibliography
6
+
7
+ def self.parse(html)
8
+ doc = Nokogiri::HTML.parse(html)
9
+ title = doc.xpath('//h1').text
10
+ author = doc.xpath('//h2').text
11
+ main_text = doc.xpath('//div[@class="main_text"]').to_html
12
+ bibliography = doc.xpath('//div[@class="bibliographical_information"]').to_html
13
+ new(title, author, main_text, bibliography)
14
+ end
15
+
16
+ def initialize(title, author, main_text, bibliography)
17
+ @title = title
18
+ @author = author
19
+ @main_text = main_text
20
+ @bibliography = bibliography
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module AozoraPolly
2
+ VERSION = "0.2.0"
3
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aozora-polly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - hogelog
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sanitize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - konbu.komuro@gmail.com
100
+ executables:
101
+ - aozora2ssml
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - aozora-polly.gemspec
113
+ - bin/console
114
+ - bin/setup
115
+ - exe/aozora2ssml
116
+ - lib/aozora-polly.rb
117
+ - lib/aozora_polly/builder.rb
118
+ - lib/aozora_polly/document.rb
119
+ - lib/aozora_polly/version.rb
120
+ - tmp/.keep
121
+ homepage: https://github.com/hogelog/aozora-polly
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.6.8
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: aozora bunko
145
+ test_files: []