google_tts2 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/README.md +26 -7
- data/google_tts2.gempspec +20 -0
- data/lib/google_tts/parser.rb +10 -0
- data/lib/google_tts.rb +1 -1
- data/spec/lib/google_tts/parser_spec.rb +8 -1
- metadata +3 -2
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,34 @@
|
|
1
1
|
Inspired on another gem - https://github.com/bloomrain/google_tts - this library is a
|
2
2
|
complete refactoring to support large texts.
|
3
3
|
|
4
|
-
#Install
|
5
|
-
|
4
|
+
#Install
|
5
|
+
on Gemfile
|
6
|
+
|
7
|
+
gem 'google_tts2'
|
8
|
+
|
9
|
+
or just
|
10
|
+
|
11
|
+
gem install google_tts2
|
12
|
+
|
13
|
+
|
6
14
|
#Usage
|
7
15
|
require 'google_tts'
|
8
|
-
google_tts = GoogleTts.instantiate
|
9
|
-
google_tts.save
|
16
|
+
google_tts = GoogleTts.instantiate
|
17
|
+
google_tts.save("FileName", "English text")
|
18
|
+
# => "out/FileName.mp3"
|
10
19
|
|
20
|
+
or
|
21
|
+
|
22
|
+
google_tts = GoogleTts.instantiate({:lang => :pt, :output => "tmp/mp3"})
|
23
|
+
google_tts.save("FileName", File.open("big_text_file.txt").read)
|
24
|
+
# => "tmp/mp3/FileName.mp3"
|
25
|
+
|
26
|
+
or
|
27
|
+
|
28
|
+
google_tts = GoogleTts.instantiate({:lang => :pt, :output => "out", :proxy => {:port => 8080, :host => 'localhost' }})
|
29
|
+
google_tts.save("FileName", "Texto em Portugês")
|
30
|
+
# => "out/FileName.mp3"
|
11
31
|
|
12
|
-
#TODO
|
13
|
-
* gemspec
|
14
32
|
|
15
33
|
#Development
|
16
34
|
|
@@ -18,10 +36,11 @@ Just install the bundles:
|
|
18
36
|
|
19
37
|
bundle install
|
20
38
|
|
39
|
+
|
21
40
|
To run the tests
|
22
41
|
|
23
42
|
bundle exec guard
|
24
|
-
|
43
|
+
|
25
44
|
or
|
26
45
|
|
27
46
|
bundle exec rspec spec
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'google_tts'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "google_tts2"
|
8
|
+
gem.version = GoogleTts::VERSION
|
9
|
+
gem.authors = ["Filipe Esperandio"]
|
10
|
+
gem.email = ["filipesperandio@gmail.com"]
|
11
|
+
gem.summary = %q{Google TTS client}
|
12
|
+
gem.description = %q{Google TTS client which accepts large text input, parses and split into multiple requests. Saves a single mp3 matching the input text.}
|
13
|
+
gem.homepage = "http://github.com/filipesperandio/google_tts2"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_development_dependency 'rspec'
|
20
|
+
end
|
data/lib/google_tts/parser.rb
CHANGED
@@ -42,7 +42,17 @@ module GoogleTts
|
|
42
42
|
bad_size?(txt) ? partials.call : txt
|
43
43
|
end
|
44
44
|
|
45
|
+
def splitInHalf(sentence, separator)
|
46
|
+
firstHalf = sentence[0..(sentence.length/2)]
|
47
|
+
firstHalf = firstHalf[0..(firstHalf.rindex(separator)-1)]
|
48
|
+
secondHalf = sentence[(firstHalf.length)..-1]
|
49
|
+
[firstHalf, secondHalf]
|
50
|
+
end
|
51
|
+
|
45
52
|
def accumulate(sentence, separator, &next_step)
|
53
|
+
splitInTwo = splitInHalf(sentence, separator)
|
54
|
+
return splitInTwo if splitInTwo[0].length <= 100 and splitInTwo[1].length <= 100
|
55
|
+
|
46
56
|
partial = []
|
47
57
|
tmp = ''
|
48
58
|
sentence.split(separator).each do |a|
|
data/lib/google_tts.rb
CHANGED
@@ -41,6 +41,14 @@ describe GoogleTts::Parser do
|
|
41
41
|
expect(result_escaped).to eq(original_escaped)
|
42
42
|
end
|
43
43
|
|
44
|
+
it 'should split big sentence in commas but try to keep pieces as big as possible' do
|
45
|
+
text = 'O projeto é de autoria do arquiteto João Batista Giovenale, então professor da Academia de Belas Artes - São Lucas - de Roma, e membro da Comissão de Arte Sacra da Basílica de São Pedro.'
|
46
|
+
result = subject.sentences text
|
47
|
+
result.each do |txt|
|
48
|
+
txt.length.should be > 40
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
44
52
|
it 'should split big sentence in commas or minor pieces' do
|
45
53
|
text = "O projeto é de autoria do arquiteto João Batista Giovenale, então professor da Academia de Belas Artes - São Lucas - de Roma, e membro da Comissão de Arte Sacra da Basílica de São Pedro."
|
46
54
|
result = subject.sentences text
|
@@ -52,7 +60,6 @@ describe GoogleTts::Parser do
|
|
52
60
|
result = subject.sentences 'Ola. tudo bem?'
|
53
61
|
expect(result.length).to eq(1)
|
54
62
|
end
|
55
|
-
|
56
63
|
end
|
57
64
|
|
58
65
|
def readable(t)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_tts2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- LICENSE
|
43
43
|
- README.md
|
44
44
|
- Rakefile
|
45
|
+
- google_tts2.gempspec
|
45
46
|
- lib/google_tts.rb
|
46
47
|
- lib/google_tts/connector.rb
|
47
48
|
- lib/google_tts/mp3writer.rb
|