tts 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +1 -3
- data/README.rdoc +8 -0
- data/Rakefile +0 -8
- data/VERSION +1 -1
- data/lib/tts.rb +19 -6
- data/spec/tts_spec.rb +31 -15
- data/tts.gemspec +6 -9
- metadata +11 -42
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -8,7 +8,6 @@ GEM
|
|
8
8
|
git (>= 1.2.5)
|
9
9
|
rake
|
10
10
|
rake (0.9.2)
|
11
|
-
rcov (0.9.9)
|
12
11
|
rspec (2.6.0)
|
13
12
|
rspec-core (~> 2.6.0)
|
14
13
|
rspec-expectations (~> 2.6.0)
|
@@ -22,7 +21,6 @@ PLATFORMS
|
|
22
21
|
ruby
|
23
22
|
|
24
23
|
DEPENDENCIES
|
25
|
-
bundler (
|
24
|
+
bundler (>= 1.0.0)
|
26
25
|
jeweler (~> 1.6.2)
|
27
|
-
rcov
|
28
26
|
rspec (~> 2.6)
|
data/README.rdoc
CHANGED
@@ -18,6 +18,14 @@ Using the Google Translate service as the speech engine, this gem generates a .m
|
|
18
18
|
text = "People living on the east coast of England have been warned to stay away from their homes because of further high tides expected later. The tidal surge that hit the UK is said to have been the worst for 60 years, with thousands abandoning their homes."
|
19
19
|
text.to_file "en"
|
20
20
|
|
21
|
+
#Direct playback (require mpg123 installed and in PATH with a POSIX system)
|
22
|
+
"Established in 1853, the University of Melbourne is a public-spirited institution that makes distinctive contributions to society in research, learning and teaching and engagement.".play
|
23
|
+
|
24
|
+
== Versions
|
25
|
+
|
26
|
+
0.4 fixed issue that long text unable to generated.
|
27
|
+
0.5 added all supported languages, added direct playback feature fixed some broken rspec.
|
28
|
+
|
21
29
|
== Copyright
|
22
30
|
|
23
31
|
Copyright (c) 2011 Yiling Cao / Charlie Revett. Check LICENSE.txt
|
data/Rakefile
CHANGED
@@ -34,14 +34,6 @@ RSpec::Core::RakeTask.new(:spec) do |t|
|
|
34
34
|
t.rspec_opts = '--format progress -c'
|
35
35
|
end
|
36
36
|
|
37
|
-
require 'rcov/rcovtask'
|
38
|
-
Rcov::RcovTask.new do |test|
|
39
|
-
test.libs << 'test'
|
40
|
-
test.pattern = 'test/**/test_*.rb'
|
41
|
-
test.verbose = true
|
42
|
-
test.rcov_opts << '--exclude "gems/*"'
|
43
|
-
end
|
44
|
-
|
45
37
|
require 'rake/rdoctask'
|
46
38
|
Rake::RDocTask.new do |rdoc|
|
47
39
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/lib/tts.rb
CHANGED
@@ -13,7 +13,7 @@ module Tts
|
|
13
13
|
|
14
14
|
def to_file lang, file_name=nil
|
15
15
|
parts = validate_text_length(self)
|
16
|
-
file_name =
|
16
|
+
file_name = self[0..20].generate_file_name if file_name.nil?
|
17
17
|
parts.each do |part|
|
18
18
|
url = part.to_url(lang)
|
19
19
|
fetch_mp3(url, file_name)
|
@@ -46,16 +46,16 @@ module Tts
|
|
46
46
|
text.gsub(/\s+/m, ' ').strip.split(" ")
|
47
47
|
end
|
48
48
|
|
49
|
-
def generate_file_name
|
50
|
-
to_valid_fn
|
49
|
+
def generate_file_name
|
50
|
+
to_valid_fn + ".mp3"
|
51
51
|
end
|
52
52
|
|
53
|
-
def to_valid_fn
|
54
|
-
|
53
|
+
def to_valid_fn
|
54
|
+
gsub(/[\x00\/\\:\*\?\"<>\|]/, '_')
|
55
55
|
end
|
56
56
|
|
57
57
|
def to_url lang
|
58
|
-
langs = [
|
58
|
+
langs = ['af', 'ar', 'az', 'be', 'bg', 'bn', 'ca', 'cs', 'cy', 'da', 'de', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fa', 'fi', 'fr', 'ga', 'gl', 'gu', 'hi', 'hr', 'ht', 'hu', 'id', 'is', 'it', 'iw', 'ja', 'ka', 'kn', 'ko', 'la', 'lt', 'lv', 'mk', 'ms', 'mt', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'sq', 'sr', 'sv', 'sw', 'ta', 'te', 'th', 'tl', 'tr', 'uk', 'ur', 'vi', 'yi', 'zh', 'zh-CN', 'zh-TW']
|
59
59
|
raise "Not accepted language, accpeted are #{langs * ","}" unless langs.include? lang
|
60
60
|
base = "#{Tts.server_url}?tl=#{lang}&q=#{URI.escape self}"
|
61
61
|
end
|
@@ -78,6 +78,19 @@ module Tts
|
|
78
78
|
`cat temp.mp3 >> "#{file_name}" && rm temp.mp3`
|
79
79
|
end
|
80
80
|
|
81
|
+
def play lang="en", times=1, pause_gap = 1
|
82
|
+
#test if mpg123 exists?
|
83
|
+
`which mpg123`
|
84
|
+
if $?.to_i != 0
|
85
|
+
puts "mpg123 executable NOT found. This function only work with POSIX systems.\n Install mpg123 with `brew install mpg123` or `apt-get install mpg123`"
|
86
|
+
exit 1
|
87
|
+
end
|
88
|
+
fn = "tts_playonce"
|
89
|
+
self.to_file(lang, fn)
|
90
|
+
times.times{|i| `mpg123 -q #{fn}`}
|
91
|
+
File.delete(fn)
|
92
|
+
end
|
93
|
+
|
81
94
|
end
|
82
95
|
|
83
96
|
class String
|
data/spec/tts_spec.rb
CHANGED
@@ -3,32 +3,30 @@ require File.expand_path("../../lib/tts", __FILE__)
|
|
3
3
|
require "rspec"
|
4
4
|
|
5
5
|
describe "to_valid_fn method" do
|
6
|
-
# Tts.server_url "http://127.0.0.1:3001/translate_tts"
|
7
|
-
|
8
6
|
# fn.gsub(/[\x00\/\\:\*\?\"<>\|]/, '_')
|
9
7
|
it "should replace * with _" do
|
10
|
-
|
11
|
-
|
8
|
+
"hello*nice".to_valid_fn.should == "hello_nice"
|
9
|
+
"hello*nice*hello".to_valid_fn.should == "hello_nice_hello"
|
12
10
|
end
|
13
11
|
|
14
12
|
it "should replace / with _" do
|
15
|
-
|
16
|
-
|
13
|
+
"hello/nice".to_valid_fn.should == "hello_nice"
|
14
|
+
"hello/nice/hello".to_valid_fn.should == "hello_nice_hello"
|
17
15
|
end
|
18
16
|
|
19
17
|
it "should replace / with _" do
|
20
|
-
|
21
|
-
|
18
|
+
"hello:nice".to_valid_fn.should == "hello_nice"
|
19
|
+
"hello:nice:hello".to_valid_fn.should == "hello_nice_hello"
|
22
20
|
end
|
23
21
|
|
24
22
|
it "should replace / with _" do
|
25
|
-
|
26
|
-
|
23
|
+
"hello?nice".to_valid_fn.should == "hello_nice"
|
24
|
+
"hello?nice?hello".to_valid_fn.should == "hello_nice_hello"
|
27
25
|
end
|
28
26
|
|
29
27
|
it "should replace / with _" do
|
30
|
-
|
31
|
-
|
28
|
+
"hello|nice".to_valid_fn.should == "hello_nice"
|
29
|
+
"hello|nice?hello".to_valid_fn.should == "hello_nice_hello"
|
32
30
|
end
|
33
31
|
|
34
32
|
end
|
@@ -63,6 +61,27 @@ describe 'to_file method' do
|
|
63
61
|
File.delete("人民广场到了.mp3")
|
64
62
|
end
|
65
63
|
|
64
|
+
it "to_file should generate a mp3 file for a correct simplified chinese string" do
|
65
|
+
"人民广场马上到了".to_file("zh-CN")
|
66
|
+
File.exist?("人民广场马上到了.mp3").should be_true
|
67
|
+
File.delete("人民广场马上到了.mp3")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "to_file should fail a non-exist language" do
|
71
|
+
expect{"人民广场马上到了".to_file("dummy")}.should raise_error(RuntimeError)
|
72
|
+
File.exist?("人民广场马上到了.mp3").should be_false
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'generate a correct mp3 file with long text and play via mpg123' do
|
78
|
+
it "should playback a correct test mp3 file" do
|
79
|
+
"Testing sound with the ruby gem TTS... if you hear the sound correctly, This single test is passed. Thank you very much for you patience...".play
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should playback a correct Chinese test mp3 file" do
|
83
|
+
"谢谢测试。测试通过".play("zh")
|
84
|
+
end
|
66
85
|
end
|
67
86
|
|
68
87
|
describe 'set a server url' do
|
@@ -73,7 +92,4 @@ describe 'set a server url' do
|
|
73
92
|
it "to_url should return a correct string" do
|
74
93
|
"hello".to_url("en").should == "http://127.0.0.1:3001/translate_tts?tl=en&q=hello"
|
75
94
|
end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
95
|
end
|
data/tts.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "tts"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Yiling Cao"]
|
12
|
-
s.date = "2014-
|
12
|
+
s.date = "2014-05-09"
|
13
13
|
s.description = "easy way to generate a voice file based on text prvoided."
|
14
14
|
s.email = "yiling.cao@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.homepage = "http://github.com/c2h2/tts"
|
31
31
|
s.licenses = ["MIT"]
|
32
32
|
s.require_paths = ["lib"]
|
33
|
-
s.rubygems_version = "1.8.
|
33
|
+
s.rubygems_version = "1.8.11"
|
34
34
|
s.summary = "a text to speech file tool"
|
35
35
|
|
36
36
|
if s.respond_to? :specification_version then
|
@@ -38,20 +38,17 @@ Gem::Specification.new do |s|
|
|
38
38
|
|
39
39
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
40
|
s.add_development_dependency(%q<rspec>, ["~> 2.6"])
|
41
|
-
s.add_development_dependency(%q<bundler>, ["
|
41
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
42
42
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
43
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
44
43
|
else
|
45
44
|
s.add_dependency(%q<rspec>, ["~> 2.6"])
|
46
|
-
s.add_dependency(%q<bundler>, ["
|
45
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
47
46
|
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
48
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
49
47
|
end
|
50
48
|
else
|
51
49
|
s.add_dependency(%q<rspec>, ["~> 2.6"])
|
52
|
-
s.add_dependency(%q<bundler>, ["
|
50
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
53
51
|
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
54
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
55
52
|
end
|
56
53
|
end
|
57
54
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &18654720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,60 +21,29 @@ dependencies:
|
|
21
21
|
version: '2.6'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '2.6'
|
24
|
+
version_requirements: *18654720
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: bundler
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &18654180 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
|
-
- -
|
30
|
+
- - ! '>='
|
36
31
|
- !ruby/object:Gem::Version
|
37
32
|
version: 1.0.0
|
38
33
|
type: :development
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.0.0
|
35
|
+
version_requirements: *18654180
|
46
36
|
- !ruby/object:Gem::Dependency
|
47
37
|
name: jeweler
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 1.6.2
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &18653660 !ruby/object:Gem::Requirement
|
57
39
|
none: false
|
58
40
|
requirements:
|
59
41
|
- - ~>
|
60
42
|
- !ruby/object:Gem::Version
|
61
43
|
version: 1.6.2
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: rcov
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
44
|
type: :development
|
71
45
|
prerelease: false
|
72
|
-
version_requirements:
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
46
|
+
version_requirements: *18653660
|
78
47
|
description: easy way to generate a voice file based on text prvoided.
|
79
48
|
email: yiling.cao@gmail.com
|
80
49
|
executables: []
|
@@ -107,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
76
|
version: '0'
|
108
77
|
segments:
|
109
78
|
- 0
|
110
|
-
hash:
|
79
|
+
hash: 398776537257557662
|
111
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
81
|
none: false
|
113
82
|
requirements:
|
@@ -116,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
85
|
version: '0'
|
117
86
|
requirements: []
|
118
87
|
rubyforge_project:
|
119
|
-
rubygems_version: 1.8.
|
88
|
+
rubygems_version: 1.8.11
|
120
89
|
signing_key:
|
121
90
|
specification_version: 3
|
122
91
|
summary: a text to speech file tool
|