tts 0.7.1 → 0.8.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1530e939b223c3b743f013ba42423450126d30a8
4
- data.tar.gz: b81c2d8e4b90446d314bdc21e26f1789482f99ae
3
+ metadata.gz: af37e331b198df603972e4c07d19daa4ccc7d55a
4
+ data.tar.gz: 66f98e3464b6225dd47952d761a68d70997cdfae
5
5
  SHA512:
6
- metadata.gz: 4dd0e163824977df01b76aba20caa94852211322237792963df8585ac693ad0e22c352595a167d106c2843810701de31b18f37e58427baa87ec50f5ff4b4c4f3
7
- data.tar.gz: b3418c549a820f704497a8ee5f9fd8e66337e8554840950188f713fed26581bfb5c79cd3e2fee246f861b517efa73d93e565dd4fb9209c5ba05ff3659ac78e92
6
+ metadata.gz: 0fdc70780ba7e6192dac717c8b1a100a8725505c7b926fb23b57ad61e3388e1fb8b01db7f4b059c4d6e2b646c4269d9b2f6d96747f1169b0e9902f1bbba95c0e
7
+ data.tar.gz: 926c6d1505b967c7de629e198d4ece847729fc5ccdb1711e5d4f955198421ec907e223eab6d5aa4baa89c83682795bef1cd0e18cb0fa3d8b74292c67598d677d
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  group :development do
4
- gem "rspec", "~> 2.6"
5
- gem "bundler", ">= 1.0.0"
6
- gem "jeweler", "~> 1.6.2"
4
+ gem "rspec"
5
+ gem "bundler", "~> 2.0"
6
+ gem "jeweler"
7
7
  # gem "rcov", ">= 0"
8
8
  end
@@ -1,26 +1,75 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- diff-lcs (1.1.2)
5
- git (1.2.5)
6
- jeweler (1.6.2)
7
- bundler (~> 1.0)
4
+ addressable (2.4.0)
5
+ builder (3.2.3)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
8
+ diff-lcs (1.3)
9
+ faraday (0.9.2)
10
+ multipart-post (>= 1.2, < 3)
11
+ git (1.5.0)
12
+ github_api (0.16.0)
13
+ addressable (~> 2.4.0)
14
+ descendants_tracker (~> 0.0.4)
15
+ faraday (~> 0.8, < 0.10)
16
+ hashie (>= 3.4)
17
+ mime-types (>= 1.16, < 3.0)
18
+ oauth2 (~> 1.0)
19
+ hashie (3.6.0)
20
+ highline (2.0.2)
21
+ jeweler (2.3.9)
22
+ builder
23
+ bundler
8
24
  git (>= 1.2.5)
25
+ github_api (~> 0.16.0)
26
+ highline (>= 1.6.15)
27
+ nokogiri (>= 1.5.10)
28
+ psych
9
29
  rake
10
- rake (0.9.2)
11
- rspec (2.6.0)
12
- rspec-core (~> 2.6.0)
13
- rspec-expectations (~> 2.6.0)
14
- rspec-mocks (~> 2.6.0)
15
- rspec-core (2.6.4)
16
- rspec-expectations (2.6.0)
17
- diff-lcs (~> 1.1.2)
18
- rspec-mocks (2.6.0)
30
+ rdoc
31
+ semver2
32
+ jwt (2.1.0)
33
+ mime-types (2.99.3)
34
+ mini_portile2 (2.4.0)
35
+ multi_json (1.13.1)
36
+ multi_xml (0.6.0)
37
+ multipart-post (2.1.0)
38
+ nokogiri (1.10.3)
39
+ mini_portile2 (~> 2.4.0)
40
+ oauth2 (1.4.1)
41
+ faraday (>= 0.8, < 0.16.0)
42
+ jwt (>= 1.0, < 3.0)
43
+ multi_json (~> 1.3)
44
+ multi_xml (~> 0.5)
45
+ rack (>= 1.2, < 3)
46
+ psych (3.1.0)
47
+ rack (2.0.7)
48
+ rake (12.3.2)
49
+ rdoc (6.1.1)
50
+ rspec (3.8.0)
51
+ rspec-core (~> 3.8.0)
52
+ rspec-expectations (~> 3.8.0)
53
+ rspec-mocks (~> 3.8.0)
54
+ rspec-core (3.8.0)
55
+ rspec-support (~> 3.8.0)
56
+ rspec-expectations (3.8.3)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.8.0)
59
+ rspec-mocks (3.8.0)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.8.0)
62
+ rspec-support (3.8.0)
63
+ semver2 (3.4.2)
64
+ thread_safe (0.3.6)
19
65
 
20
66
  PLATFORMS
21
67
  ruby
22
68
 
23
69
  DEPENDENCIES
24
- bundler (>= 1.0.0)
25
- jeweler (~> 1.6.2)
26
- rspec (~> 2.6)
70
+ bundler (~> 2.0)
71
+ jeweler
72
+ rspec
73
+
74
+ BUNDLED WITH
75
+ 2.0.1
@@ -41,10 +41,10 @@ You need to install `mpg123`
41
41
 
42
42
  == Versions
43
43
 
44
- 0.4 fixed issue that long text unable to generated.
45
- 0.5 added all supported languages, added direct playback feature fixed some broken rspec.
46
- 0.7 added CLI support
47
- 0.7.1 fixed new google API
44
+ * 0.4 fixed issue that long text unable to generated.
45
+ * 0.5 added all supported languages, added direct playback feature fixed some broken rspec.
46
+ * 0.7 added CLI support
47
+ * 0.7.1 fixed new google API
48
48
 
49
49
  == Copyright
50
50
 
data/Rakefile CHANGED
@@ -34,8 +34,8 @@ RSpec::Core::RakeTask.new(:spec) do |t|
34
34
  t.rspec_opts = '--format progress -c'
35
35
  end
36
36
 
37
- require 'rake/rdoctask'
38
- Rake::RDocTask.new do |rdoc|
37
+ require 'rdoc/task'
38
+ RDoc::Task.new do |rdoc|
39
39
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
40
 
41
41
  rdoc.rdoc_dir = 'rdoc'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.1
data/lib/tts.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  # encoding: utf-8
2
2
  require 'open-uri'
3
3
  require 'uri'
4
+ require 'tempfile'
4
5
 
5
6
  module Tts
6
7
  @@default_url = "http://translate.google.com/translate_tts"
7
- @@user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24"
8
+ @@user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24"
8
9
  @@referer = "http://translate.google.com/"
9
10
 
10
11
  def self.server_url url=nil
@@ -17,14 +18,14 @@ module Tts
17
18
  file_name = self[0..20].generate_file_name if file_name.nil?
18
19
  parts.each do |part|
19
20
  url = part.to_url(lang)
20
- fetch_mp3(url, file_name)
21
+ fetch_mp3(url, file_name)
21
22
  end
22
23
  end
23
-
24
+
24
25
  def validate_text_length text
25
26
  if text.length > 100
26
27
  chunk_text(text)
27
- else
28
+ else
28
29
  [text]
29
30
  end
30
31
  end
@@ -51,7 +52,7 @@ module Tts
51
52
  to_valid_fn + ".mp3"
52
53
  end
53
54
 
54
- def to_valid_fn
55
+ def to_valid_fn
55
56
  gsub(/[\x00\/\\:\*\?\"<>\|]/, '_')
56
57
  end
57
58
 
@@ -62,10 +63,10 @@ module Tts
62
63
  end
63
64
 
64
65
  def fetch_mp3 url, file_name
65
- begin
66
+ begin
66
67
  content = open(url, "User-Agent" => @@user_agent, "Referer" => @@referer).read
67
-
68
- File.open("temp.mp3", "wb") do |f|
68
+
69
+ File.open(temp_file_name, "wb") do |f|
69
70
  f.puts content
70
71
  end
71
72
  merge_mp3_file(file_name)
@@ -75,11 +76,15 @@ module Tts
75
76
  end
76
77
  end
77
78
 
79
+ def temp_file_name
80
+ @@temp_file ||= Tempfile.new.path
81
+ end
82
+
78
83
  def merge_mp3_file file_name
79
- `cat temp.mp3 >> "#{file_name}" && rm temp.mp3`
84
+ `cat #{temp_file_name} >> "#{file_name}" && rm #{temp_file_name}`
80
85
  end
81
86
 
82
- def play lang="en", times=1, pause_gap = 1
87
+ def play lang="en", times=1, pause_gap = 1
83
88
  #test if mpg123 exists?
84
89
  `which mpg123`
85
90
  if $?.to_i != 0
@@ -88,7 +93,7 @@ module Tts
88
93
  end
89
94
  fn = "tts_playonce"
90
95
  self.to_file(lang, fn)
91
- times.times{|i| `mpg123 -q #{fn}`}
96
+ times.times{|i| `mpg123 --no-control -q #{fn}`}
92
97
  File.delete(fn)
93
98
  end
94
99
 
@@ -5,39 +5,39 @@ require "rspec"
5
5
  describe "to_valid_fn method" do
6
6
  # fn.gsub(/[\x00\/\\:\*\?\"<>\|]/, '_')
7
7
  it "should replace * with _" do
8
- "hello*nice".to_valid_fn.should == "hello_nice"
9
- "hello*nice*hello".to_valid_fn.should == "hello_nice_hello"
8
+ expect("hello*nice".to_valid_fn).to eq "hello_nice"
9
+ expect("hello*nice*hello".to_valid_fn).to eq "hello_nice_hello"
10
10
  end
11
11
 
12
12
  it "should replace / with _" do
13
- "hello/nice".to_valid_fn.should == "hello_nice"
14
- "hello/nice/hello".to_valid_fn.should == "hello_nice_hello"
13
+ expect("hello/nice".to_valid_fn).to eq "hello_nice"
14
+ expect("hello/nice/hello".to_valid_fn).to eq "hello_nice_hello"
15
15
  end
16
16
 
17
17
  it "should replace / with _" do
18
- "hello:nice".to_valid_fn.should == "hello_nice"
19
- "hello:nice:hello".to_valid_fn.should == "hello_nice_hello"
18
+ expect("hello:nice".to_valid_fn).to eq "hello_nice"
19
+ expect("hello:nice:hello".to_valid_fn).to eq "hello_nice_hello"
20
20
  end
21
21
 
22
22
  it "should replace / with _" do
23
- "hello?nice".to_valid_fn.should == "hello_nice"
24
- "hello?nice?hello".to_valid_fn.should == "hello_nice_hello"
23
+ expect("hello?nice".to_valid_fn).to eq "hello_nice"
24
+ expect("hello?nice?hello".to_valid_fn).to eq "hello_nice_hello"
25
25
  end
26
26
 
27
27
  it "should replace / with _" do
28
- "hello|nice".to_valid_fn.should == "hello_nice"
29
- "hello|nice?hello".to_valid_fn.should == "hello_nice_hello"
28
+ expect("hello|nice".to_valid_fn).to eq "hello_nice"
29
+ expect("hello|nice?hello".to_valid_fn).to eq "hello_nice_hello"
30
30
  end
31
31
 
32
32
  end
33
33
 
34
34
  describe 'to_url method' do
35
35
  it "to_url should return a correct string" do
36
- "hello".to_url("en").should == "http://translate.google.com/translate_tts?tl=en&ie=UTF-8&client=tw-ob&q=hello"
36
+ expect("hello".to_url("en")).to eq "http://translate.google.com/translate_tts?tl=en&ie=UTF-8&client=tw-ob&q=hello"
37
37
  end
38
38
 
39
39
  it "to_url should return a correct string with chinese char" do
40
- "人民广场".to_url("zh").should == "http://translate.google.com/translate_tts?tl=zh&ie=UTF-8&client=tw-ob&q=%E4%BA%BA%E6%B0%91%E5%B9%BF%E5%9C%BA"
40
+ expect("人民广场".to_url("zh")).to eq "http://translate.google.com/translate_tts?tl=zh&ie=UTF-8&client=tw-ob&q=%E4%BA%BA%E6%B0%91%E5%B9%BF%E5%9C%BA"
41
41
  end
42
42
 
43
43
  end
@@ -45,31 +45,31 @@ end
45
45
  describe 'to_file method' do
46
46
  it "to_file should generate a mp3 file for a correct string" do
47
47
  "hello".to_file("en")
48
- File.exist?("hello.mp3").should be_true
48
+ expect(File.exist?("hello.mp3")).to be true
49
49
  File.delete("hello.mp3")
50
50
  end
51
51
 
52
52
  it "to_file should generate a mp3 file with given name for a correct string" do
53
53
  "hello".to_file("en", "my_hello.mp3")
54
- File.exist?("my_hello.mp3").should be_true
54
+ expect(File.exist?("my_hello.mp3")).to be true
55
55
  File.delete("my_hello.mp3")
56
56
  end
57
57
 
58
58
  it "to_file should generate a mp3 file for a correct chinese string" do
59
59
  "人民广场到了".to_file("zh")
60
- File.exist?("人民广场到了.mp3").should be_true
60
+ expect(File.exist?("人民广场到了.mp3")).to be true
61
61
  File.delete("人民广场到了.mp3")
62
62
  end
63
63
 
64
64
  it "to_file should generate a mp3 file for a correct simplified chinese string" do
65
65
  "人民广场马上到了".to_file("zh-CN")
66
- File.exist?("人民广场马上到了.mp3").should be_true
66
+ expect(File.exist?("人民广场马上到了.mp3")).to be true
67
67
  File.delete("人民广场马上到了.mp3")
68
68
  end
69
69
 
70
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
71
+ expect{"人民广场马上到了".to_file("dummy")}.to raise_error(RuntimeError)
72
+ expect(File.exist?("人民广场马上到了.mp3")).to be false
73
73
  end
74
74
 
75
75
  end
@@ -90,6 +90,6 @@ describe 'set a server url' do
90
90
  end
91
91
 
92
92
  it "to_url should return a correct string" do
93
- "hello".to_url("en").should == "http://127.0.0.1:3001/translate_tts?tl=en&ie=UTF-8&client=tw-ob&q=hello"
93
+ expect("hello".to_url("en")).to eq "http://127.0.0.1:3001/translate_tts?tl=en&ie=UTF-8&client=tw-ob&q=hello"
94
94
  end
95
95
  end
@@ -2,42 +2,59 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: tts 0.6.0 ruby lib
5
+ # stub: tts 0.7.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = "tts"
9
- s.version = "0.7.1"
8
+ s.name = "tts".freeze
9
+ s.version = "0.8.1"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Yiling Cao"]
14
- s.date = "2015-08-18"
15
- s.description = "easy way to generate a voice file based on text prvoided."
16
- s.summary = "a text to speech file tool"
17
- s.email = "yiling.cao@gmail.com"
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Yiling Cao".freeze]
14
+ s.date = "2019-05-11"
15
+ s.description = "(tts) Text -> Mp3 made easy.".freeze
16
+ s.email = "yiling.cao@gmail.com".freeze
17
+ s.executables = ["text2mp3".freeze, "tts".freeze]
18
18
  s.extra_rdoc_files = [
19
19
  "LICENSE.txt",
20
20
  "README.rdoc"
21
21
  ]
22
-
23
- s.executables = ["tts", "text2mp3"]
24
- s.files = `git ls-files`.split($/)
25
-
26
- s.homepage = "http://github.com/c2h2/tts"
27
- s.licenses = ["MIT"]
28
- s.rubygems_version = "2.4.8"
22
+ s.files = [
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/text2mp3",
30
+ "bin/tts",
31
+ "example/gen_hello_world_en.rb",
32
+ "example/play_hello_world_en.rb",
33
+ "lib/tts.rb",
34
+ "spec/tts_spec.rb",
35
+ "tts.gemspec"
36
+ ]
37
+ s.homepage = "http://github.com/c2h2/tts".freeze
38
+ s.licenses = ["MIT".freeze]
39
+ s.rubygems_version = "3.0.3".freeze
40
+ s.summary = "Ruby convert text to mp3".freeze
29
41
 
30
42
  if s.respond_to? :specification_version then
31
43
  s.specification_version = 4
32
44
 
33
45
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
34
- s.add_development_dependency(%q<rspec>, ["~> 2.6"])
46
+ s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
47
+ s.add_development_dependency(%q<bundler>.freeze, ["~> 2.0"])
48
+ s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
35
49
  else
36
- s.add_dependency(%q<rspec>, ["~> 2.6"])
50
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
51
+ s.add_dependency(%q<bundler>.freeze, ["~> 2.0"])
52
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
37
53
  end
38
54
  else
39
- s.add_dependency(%q<rspec>, ["~> 2.6"])
40
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
55
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
56
+ s.add_dependency(%q<bundler>.freeze, ["~> 2.0"])
57
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
41
58
  end
42
59
  end
43
60
 
metadata CHANGED
@@ -1,40 +1,67 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yiling Cao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-18 00:00:00.000000000 Z
11
+ date: 2019-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '2.6'
33
+ version: '2.0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '2.6'
27
- description: easy way to generate a voice file based on text prvoided.
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jeweler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: "(tts) Text -> Mp3 made easy."
28
56
  email: yiling.cao@gmail.com
29
57
  executables:
30
- - tts
31
58
  - text2mp3
59
+ - tts
32
60
  extensions: []
33
61
  extra_rdoc_files:
34
62
  - LICENSE.txt
35
63
  - README.rdoc
36
64
  files:
37
- - ".gitignore"
38
65
  - Gemfile
39
66
  - Gemfile.lock
40
67
  - LICENSE.txt
@@ -68,8 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
95
  version: '0'
69
96
  requirements: []
70
97
  rubyforge_project:
71
- rubygems_version: 2.4.8
98
+ rubygems_version: 2.6.12
72
99
  signing_key:
73
100
  specification_version: 4
74
- summary: a text to speech file tool
101
+ summary: Ruby convert text to mp3
75
102
  test_files: []
data/.gitignore DELETED
@@ -1,48 +0,0 @@
1
- # rcov generated
2
- coverage
3
-
4
- # rdoc generated
5
- rdoc
6
-
7
- # yard generated
8
- doc
9
- .yardoc
10
-
11
- # bundler
12
- .bundle
13
-
14
- # jeweler generated
15
- pkg
16
-
17
- # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
- #
19
- # * Create a file at ~/.gitignore
20
- # * Include files you want ignored
21
- # * Run: git config --global core.excludesfile ~/.gitignore
22
- #
23
- # After doing this, these files will be ignored in all your git projects,
24
- # saving you from having to 'pollute' every project you touch with them
25
- #
26
- # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
- #
28
- # For MacOS:
29
- #
30
- #.DS_Store
31
-
32
- # For TextMate
33
- #*.tmproj
34
- #tmtags
35
-
36
- # For emacs:
37
- #*~
38
- #\#*
39
- #.\#*
40
-
41
- # For vim:
42
- #*.swp
43
-
44
- # For redcar:
45
- #.redcar
46
-
47
- # For rubinius:
48
- #*.rbc