tts 0.2.3 → 0.3.0
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/README.rdoc +11 -7
- data/VERSION +1 -1
- data/lib/tts.rb +31 -8
- data/spec/tts_spec.rb +58 -2
- data/tts.gemspec +8 -9
- metadata +51 -84
data/README.rdoc
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
= tts
|
2
2
|
|
3
|
-
Google translate
|
3
|
+
Google translate TTS (text to speech) so farhas most available languages and reasonable synthesizer.
|
4
4
|
|
5
|
-
This TTS
|
5
|
+
This TTS is using it as the speech engine. submit your sentance and specified language to google and download the mp3 voice file.
|
6
6
|
|
7
7
|
== install
|
8
8
|
gem install tts
|
9
9
|
|
10
10
|
== usage
|
11
|
-
|
11
|
+
This will download the correspoding files to your excuting directory.
|
12
|
+
"hello world!".to_file "en"
|
12
13
|
|
13
|
-
"人民代表代表人民".to_file "zh"
|
14
|
+
"人民代表代表人民".to_file "zh"
|
14
15
|
|
15
|
-
This will download the correspoding files to your excuting directory.
|
16
16
|
|
17
17
|
You can also save the file with the path/filename you desired:
|
18
18
|
|
19
|
-
"ruby is awesome".to_file "en", "~/rubyyyy.mp3"
|
19
|
+
"ruby is awesome".to_file "en", "~/rubyyyy.mp3"
|
20
|
+
|
21
|
+
=== 0.3.0 new ability to add 3rd party server, to Config server url
|
22
|
+
If you have problem to visit original google tts url, you can set a another tts server url, for example:
|
23
|
+
Tts.server_url "http://www.3rdparty.com/translate_tts"
|
20
24
|
|
21
25
|
== Copyright
|
22
26
|
|
23
|
-
Copyright (c) 2011 Yiling Cao.
|
27
|
+
Copyright (c) 2011 Yiling Cao. Check LICENSE.txt
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/tts.rb
CHANGED
@@ -1,23 +1,46 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
def to_valid_fn fn
|
4
|
+
fn.gsub(/[\x00\/\\:\*\?\"<>\|]/, '_')
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
module Tts
|
9
|
+
@@default_url = "http://translate.google.com/translate_tts"
|
10
|
+
def self.server_url url=nil
|
11
|
+
return @@default_url if url.nil?
|
12
|
+
@@default_url = url
|
13
|
+
end
|
14
|
+
|
2
15
|
def to_url lang
|
3
16
|
require 'uri'
|
4
17
|
langs = ["zh", "en", "it", "fr"]
|
5
18
|
#raise "Not accepted language, accpeted are #{langs * ","}" unless langs.include? lang
|
6
|
-
base = "
|
7
|
-
end
|
19
|
+
base = "#{Tts.server_url}?tl=#{lang}&q=#{URI.escape self}"
|
20
|
+
end
|
8
21
|
|
9
22
|
def to_file lang, file_name=nil
|
10
23
|
require 'open-uri'
|
11
|
-
file_name = self +".mp3" if file_name.nil?
|
24
|
+
file_name = to_valid_fn(self +".mp3") if file_name.nil?
|
12
25
|
url = self.to_url(lang)
|
13
26
|
ua = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24"
|
14
|
-
|
15
|
-
|
16
|
-
|
27
|
+
begin
|
28
|
+
content = open(url, "User-Agent" => ua).read
|
29
|
+
|
30
|
+
File.open(file_name, "wb") do |f|
|
31
|
+
f.puts content
|
32
|
+
end
|
33
|
+
rescue Exception => error
|
34
|
+
$stderr.puts("Internet error! #{error.message}")
|
35
|
+
exit(1)
|
17
36
|
end
|
37
|
+
|
18
38
|
end
|
19
|
-
end
|
39
|
+
end
|
20
40
|
|
21
41
|
class String
|
42
|
+
|
43
|
+
|
44
|
+
|
22
45
|
include Tts
|
23
46
|
end
|
data/spec/tts_spec.rb
CHANGED
@@ -1,10 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require File.expand_path("../../lib/tts", __FILE__)
|
2
3
|
require "rspec"
|
3
4
|
|
5
|
+
describe "to_valid_fn method" do
|
6
|
+
# Tts.server_url "http://127.0.0.1:3001/translate_tts"
|
7
|
+
|
8
|
+
# fn.gsub(/[\x00\/\\:\*\?\"<>\|]/, '_')
|
9
|
+
it "should replace * with _" do
|
10
|
+
to_valid_fn("hello*nice").should == "hello_nice"
|
11
|
+
to_valid_fn("hello*nice*hello").should == "hello_nice_hello"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should replace / with _" do
|
15
|
+
to_valid_fn("hello/nice").should == "hello_nice"
|
16
|
+
to_valid_fn("hello/nice/hello").should == "hello_nice_hello"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should replace / with _" do
|
20
|
+
to_valid_fn("hello:nice").should == "hello_nice"
|
21
|
+
to_valid_fn("hello:nice:hello").should == "hello_nice_hello"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should replace / with _" do
|
25
|
+
to_valid_fn("hello?nice").should == "hello_nice"
|
26
|
+
to_valid_fn("hello?nice?hello").should == "hello_nice_hello"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should replace / with _" do
|
30
|
+
to_valid_fn("hello|nice").should == "hello_nice"
|
31
|
+
to_valid_fn("hello|nice?hello").should == "hello_nice_hello"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
4
36
|
describe 'to_url method' do
|
5
37
|
it "to_url should return a correct string" do
|
6
38
|
"hello".to_url("en").should == "http://translate.google.com/translate_tts?tl=en&q=hello"
|
7
39
|
end
|
40
|
+
|
41
|
+
it "to_url should return a correct string with chinese char" do
|
42
|
+
"人民广场".to_url("zh").should == "http://translate.google.com/translate_tts?tl=zh&q=%E4%BA%BA%E6%B0%91%E5%B9%BF%E5%9C%BA"
|
43
|
+
end
|
44
|
+
|
8
45
|
end
|
9
46
|
|
10
47
|
describe 'to_file method' do
|
@@ -13,11 +50,30 @@ describe 'to_file method' do
|
|
13
50
|
File.exist?("hello.mp3").should be_true
|
14
51
|
File.delete("hello.mp3")
|
15
52
|
end
|
16
|
-
|
53
|
+
|
17
54
|
it "to_file should generate a mp3 file with given name for a correct string" do
|
18
55
|
"hello".to_file("en", "my_hello.mp3")
|
19
56
|
File.exist?("my_hello.mp3").should be_true
|
20
57
|
File.delete("my_hello.mp3")
|
21
58
|
end
|
22
|
-
|
59
|
+
|
60
|
+
it "to_file should generate a mp3 file for a correct chinese string" do
|
61
|
+
"人民广场到了".to_file("zh")
|
62
|
+
File.exist?("人民广场到了.mp3").should be_true
|
63
|
+
File.delete("人民广场到了.mp3")
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'set a server url' do
|
69
|
+
before(:all) do
|
70
|
+
Tts.server_url "http://127.0.0.1:3001/translate_tts"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "to_url should return a correct string" do
|
74
|
+
"hello".to_url("en").should == "http://127.0.0.1:3001/translate_tts?tl=en&q=hello"
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
|
23
79
|
end
|
data/tts.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "tts"
|
8
|
+
s.version = "0.3.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 =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2011-10-31"
|
13
|
+
s.description = "easy way to generate a voice file based on text prvoided."
|
14
|
+
s.email = "yiling.cao@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
17
|
"README.rdoc"
|
@@ -29,14 +29,13 @@ Gem::Specification.new do |s|
|
|
29
29
|
"spec/tts_spec.rb",
|
30
30
|
"tts.gemspec"
|
31
31
|
]
|
32
|
-
s.homepage =
|
32
|
+
s.homepage = "http://github.com/c2h2/tts"
|
33
33
|
s.licenses = ["MIT"]
|
34
34
|
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version =
|
36
|
-
s.summary =
|
35
|
+
s.rubygems_version = "1.8.10"
|
36
|
+
s.summary = "a text to speech file tool"
|
37
37
|
|
38
38
|
if s.respond_to? :specification_version then
|
39
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
39
|
s.specification_version = 3
|
41
40
|
|
42
41
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
metadata
CHANGED
@@ -1,94 +1,68 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: tts
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 3
|
10
|
-
version: 0.2.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Yiling Cao
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2011-10-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &18123600 !ruby/object:Gem::Requirement
|
23
17
|
none: false
|
24
|
-
requirements:
|
18
|
+
requirements:
|
25
19
|
- - ~>
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
segments:
|
29
|
-
- 2
|
30
|
-
- 6
|
31
|
-
version: "2.6"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.6'
|
32
22
|
type: :development
|
33
|
-
name: rspec
|
34
23
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
|
24
|
+
version_requirements: *18123600
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &18122120 !ruby/object:Gem::Requirement
|
38
28
|
none: false
|
39
|
-
requirements:
|
29
|
+
requirements:
|
40
30
|
- - ~>
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
hash: 23
|
43
|
-
segments:
|
44
|
-
- 1
|
45
|
-
- 0
|
46
|
-
- 0
|
31
|
+
- !ruby/object:Gem::Version
|
47
32
|
version: 1.0.0
|
48
33
|
type: :development
|
49
|
-
name: bundler
|
50
34
|
prerelease: false
|
51
|
-
version_requirements: *
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
|
35
|
+
version_requirements: *18122120
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: jeweler
|
38
|
+
requirement: &18119340 !ruby/object:Gem::Requirement
|
54
39
|
none: false
|
55
|
-
requirements:
|
40
|
+
requirements:
|
56
41
|
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
hash: 11
|
59
|
-
segments:
|
60
|
-
- 1
|
61
|
-
- 6
|
62
|
-
- 2
|
42
|
+
- !ruby/object:Gem::Version
|
63
43
|
version: 1.6.2
|
64
44
|
type: :development
|
65
|
-
name: jeweler
|
66
45
|
prerelease: false
|
67
|
-
version_requirements: *
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
|
46
|
+
version_requirements: *18119340
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rcov
|
49
|
+
requirement: &18511900 !ruby/object:Gem::Requirement
|
70
50
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
version: "0"
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
78
55
|
type: :development
|
79
|
-
name: rcov
|
80
56
|
prerelease: false
|
81
|
-
version_requirements: *
|
57
|
+
version_requirements: *18511900
|
82
58
|
description: easy way to generate a voice file based on text prvoided.
|
83
59
|
email: yiling.cao@gmail.com
|
84
60
|
executables: []
|
85
|
-
|
86
61
|
extensions: []
|
87
|
-
|
88
|
-
extra_rdoc_files:
|
62
|
+
extra_rdoc_files:
|
89
63
|
- LICENSE.txt
|
90
64
|
- README.rdoc
|
91
|
-
files:
|
65
|
+
files:
|
92
66
|
- Gemfile
|
93
67
|
- Gemfile.lock
|
94
68
|
- LICENSE.txt
|
@@ -100,39 +74,32 @@ files:
|
|
100
74
|
- pkg/tts-0.0.1.gem
|
101
75
|
- spec/tts_spec.rb
|
102
76
|
- tts.gemspec
|
103
|
-
has_rdoc: true
|
104
77
|
homepage: http://github.com/c2h2/tts
|
105
|
-
licenses:
|
78
|
+
licenses:
|
106
79
|
- MIT
|
107
80
|
post_install_message:
|
108
81
|
rdoc_options: []
|
109
|
-
|
110
|
-
require_paths:
|
82
|
+
require_paths:
|
111
83
|
- lib
|
112
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
85
|
none: false
|
114
|
-
requirements:
|
115
|
-
- -
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
|
118
|
-
segments:
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
segments:
|
119
91
|
- 0
|
120
|
-
|
121
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
hash: 194095336930749900
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
94
|
none: false
|
123
|
-
requirements:
|
124
|
-
- -
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
|
127
|
-
segments:
|
128
|
-
- 0
|
129
|
-
version: "0"
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
130
99
|
requirements: []
|
131
|
-
|
132
100
|
rubyforge_project:
|
133
|
-
rubygems_version: 1.
|
101
|
+
rubygems_version: 1.8.10
|
134
102
|
signing_key:
|
135
103
|
specification_version: 3
|
136
104
|
summary: a text to speech file tool
|
137
105
|
test_files: []
|
138
|
-
|