text2voice 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/lib/text2voice.rb +100 -0
- data/lib/text2voice/version.rb +3 -0
- data/text2voice.gemspec +23 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c466f1634ec854c56f86aed2a54048fdfd9fe2a1
|
4
|
+
data.tar.gz: e72bef896934ab2ff48765dcb1becc3c49286848
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a12014fc82d4b52a4d5dea88a52f451eab7e81d7c1991bd97be8b5e8a9effd6026379861b7b97d6ad2a87585db792c42288a485b7cae7c0e125999a635846212
|
7
|
+
data.tar.gz: a9ce602b8c60e5e1f1f1554f2537a24699118f4d7bb1e0923f13916972d947959d45b3501c0376bcbb2fea6088b6b83cdc2cf493e82433804d5c597775a122de
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 alitaso345
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Text2voice
|
2
|
+
|
3
|
+
This gem is Voice Text Web API(https://cloud.voicetext.jp/webapi/docs/introduction) for Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'text2voice'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install text2voice
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'text2voice'
|
22
|
+
|
23
|
+
voice = TextToVoice.new("Your API key")
|
24
|
+
|
25
|
+
voice.speak("こころぴょんぴょん")
|
26
|
+
.speaker("haruka")
|
27
|
+
.emotion(emotion: :happiness, level: :HIGHT)
|
28
|
+
|
29
|
+
voice.save_as("test.wav")
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it ( http://github.com/<my-github-username>/text2voice/fork )
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/text2voice.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require "text2voice/version"
|
2
|
+
require 'uri'
|
3
|
+
require 'net/https'
|
4
|
+
|
5
|
+
class TextToVoice
|
6
|
+
class BadRequest < StandardError; end
|
7
|
+
class Unauthoeized < StandardError; end
|
8
|
+
|
9
|
+
ENDPOINT = URI('https://api.voicetext.jp/v1/tts')
|
10
|
+
EMOTION_LEVEL = {HIGHT: "2", ROW: "1", NORMAL: nil}
|
11
|
+
|
12
|
+
def initialize(api_key)
|
13
|
+
@api_key = api_key
|
14
|
+
@speaker = "haruka"
|
15
|
+
@pitch = "100"
|
16
|
+
@speed = "100"
|
17
|
+
@volume = "100"
|
18
|
+
end
|
19
|
+
|
20
|
+
def speaker(speaker_name)
|
21
|
+
@speaker = speaker_name
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def emotion(emotion: nil, level: NORMAL)
|
26
|
+
@emotion = emotion.to_s
|
27
|
+
@emotion_level = EMOTION_LEVEL[level]
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def pitch(param)
|
32
|
+
@pitch = param.to_s
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def speed(param)
|
37
|
+
@speed = param.to_s
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def volulme(param)
|
42
|
+
@volume = param.to_s
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def speak(text)
|
47
|
+
@text = text
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
def save_as(filename)
|
52
|
+
res = send_request()
|
53
|
+
|
54
|
+
case res
|
55
|
+
when Net::HTTPOK
|
56
|
+
binary_to_wav(filename, res.body)
|
57
|
+
when Net::HTTPBadRequest
|
58
|
+
raise BadRequest.new(res.body)
|
59
|
+
when Net::HTTPUnauthorized
|
60
|
+
raise Unauthoeized.new(res.body)
|
61
|
+
else
|
62
|
+
raise StandardError.new(res.body)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def create_request(text, speaker, emotion, emotion_level, pitch, speed, volume)
|
68
|
+
req = Net::HTTP::Post.new(ENDPOINT.path)
|
69
|
+
req.basic_auth(@api_key, '')
|
70
|
+
data = "text=#{text}"
|
71
|
+
data << ";speaker=#{speaker}"
|
72
|
+
data << ";emotion=#{emotion}"
|
73
|
+
data << ";emotion_level=#{emotion_level}"
|
74
|
+
data << ";pitch=#{pitch}"
|
75
|
+
data << ";speed=#{speed}"
|
76
|
+
data << ";volume=#{volume}"
|
77
|
+
req.body = data
|
78
|
+
|
79
|
+
return req
|
80
|
+
end
|
81
|
+
|
82
|
+
def send_request
|
83
|
+
res = nil
|
84
|
+
https = Net::HTTP.new(ENDPOINT.host, 443)
|
85
|
+
https.use_ssl = true
|
86
|
+
https.start do |https|
|
87
|
+
req = create_request(@text, @speaker, @emotion, @emotion_level, @pitch, @speed, @volume)
|
88
|
+
res = https.request(req)
|
89
|
+
end
|
90
|
+
|
91
|
+
return res
|
92
|
+
end
|
93
|
+
|
94
|
+
def binary_to_wav(filename, binary)
|
95
|
+
File.open("#{filename}", "w") do |io|
|
96
|
+
io.binmode
|
97
|
+
io.write binary
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/text2voice.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'text2voice/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "text2voice"
|
8
|
+
spec.version = TextToVoice::VERSION
|
9
|
+
spec.authors = ["alitaso345"]
|
10
|
+
spec.email = ["alice.maru345@gmail.com"]
|
11
|
+
spec.summary = %q{VoiceTextAPI}
|
12
|
+
spec.description = %q{This is VoiceTextAPI}
|
13
|
+
spec.homepage = "https://github.com/alice345/text2voice"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: text2voice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- alitaso345
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: This is VoiceTextAPI
|
42
|
+
email:
|
43
|
+
- alice.maru345@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/text2voice.rb
|
54
|
+
- lib/text2voice/version.rb
|
55
|
+
- text2voice.gemspec
|
56
|
+
homepage: https://github.com/alice345/text2voice
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.0
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: VoiceTextAPI
|
80
|
+
test_files: []
|