txt2speech 0.5 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c40146f701737a59b26858ab5b3c182e6ba1754
4
- data.tar.gz: 0c1a11ee5ad703f43ce661ff74011bc12d38ab2b
3
+ metadata.gz: 0ce8d7e048b1003c3d8f94aa85984a180b68f63f
4
+ data.tar.gz: e27c25c110173405d91b89bda9a3a92beeb1503e
5
5
  SHA512:
6
- metadata.gz: 0f3d4e27f81e74aaeb595992dcfd2c687f34934551a47258e726ebb76365e4c030b57fb573ca36ee91adba0e0d0500c7c41feb20f9464e184e7e0f220e71d39b
7
- data.tar.gz: 15b8190faa7d946ecee9f95e3ec437ad82d60862c9c73de215c0b48b36efdff40c60d661f0440c680d909261a1aa2d73510d1cebe669c2c2bea26aef7779c3e2
6
+ metadata.gz: 1842088ccd9542de7a369b07ee74e3c331ce36ebb0992ab60da85b70f001077fbc4d2b374f5f6947f5a2d9cf158e41b993906caf912a3ab3e7c44b0fea1c7c82
7
+ data.tar.gz: 44b558edc9cd828ac08c55e4269675dc275777d64f1301ecfc30f3e6e00a6e7a5f2990fab586762591a2a51d3c7ab4616fd96a4c6ce3ee0af66cbc36116ac798
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 2.1
5
+ - 2.2
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'bundle'
4
+ gem 'rake'
5
+ gem 'rspec', :require => 'spec'
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ bundle (0.0.1)
5
+ bundler
6
+ diff-lcs (1.2.5)
7
+ rake (10.4.2)
8
+ rspec (3.3.0)
9
+ rspec-core (~> 3.3.0)
10
+ rspec-expectations (~> 3.3.0)
11
+ rspec-mocks (~> 3.3.0)
12
+ rspec-core (3.3.1)
13
+ rspec-support (~> 3.3.0)
14
+ rspec-expectations (3.3.0)
15
+ diff-lcs (>= 1.2.0, < 2.0)
16
+ rspec-support (~> 3.3.0)
17
+ rspec-mocks (3.3.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.3.0)
20
+ rspec-support (3.3.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundle
27
+ rake
28
+ rspec
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
+ [![Build Status](https://travis-ci.org/rudkovsky/txt2speech.svg)](https://travis-ci.org/rudkovsky/txt2speech)
2
+
1
3
  txt2Speech lifehack of using Google Translate. Allow you to convert text into speech.
2
4
 
3
5
  ```
4
- bin/txt2speech -r README.md -f -o example.mp3
6
+ bin/txt2speech -r README.md -f -o example.mpg
5
7
  ```
6
8
 
7
9
  to change language to read
@@ -16,16 +18,16 @@ bin/txt2speech -r examples/de.txt -f -l de
16
18
  2.1.2 :001 > require 'txt2speech'
17
19
  => true
18
20
  2.1.2 :010 > f = Txt2Speech::Speech.new "Hello I am Google robot! Nice to meet you, hope you'll enjoy this script and will fork it"
19
- => #<Txt2Speech:0x000000029a3290 @text="Hello I am Google robot! Nice to meet you, hope you'll enjoy this script and will fork it", @lang="en">
20
- 2.1.2 :011 > f.save('out.mp3')
21
+ => #<Txt2Speech::Speech:0x000000022314f8 @text="Hello I am Google robot! Nice to meet you, hope you'll enjoy this script and will fork it", @lang="en">
22
+ 2.1.2 :011 > f.save('out.mpg')
21
23
  ```
22
24
 
23
25
  or you can load a text file to read it
24
26
 
25
27
  ```
26
28
  2.1.2 :006 > f = Txt2Speech::Speech.load "README.md"
27
- => #<Txt2Speech:0x00000002ef8b00 @text="txt2Speech is a simple ruby script that convert text to speech by using Google Translate.\r\n\r\n```\r\n2.1.2 :001 > require './txt2speech.rb'\r\n => true\r\n2.1.2 :002 > f = Txt2Speech.new \"Hello I am google! Nice to meet you\"\r\n => #<Txt2Speech:0x000000018aafd8 @text=\"Hello I am google! Nice to meet you\", @lang=\"en\">\r\n2.1.2 :003 > f.save(\"out.mp3\")\r\n => \"out.mp3\"\r\n```\r\n\r\nor you can load a text file to read it\r\n\r\n```\r\nt = Txt2Speech.load \"\#{Dir.home}/text.txt\"\r\nt.save(\"out.mp3\")\r\n```", @lang="en">
28
- 2.1.2 :007 > f.save("out.mp3")
29
+ => #<Txt2Speech::Speech:0x000000022314f8 @text="txt2Speech is a simple ruby script that convert text to speech by using Google Translate.\r\n\r\n```\r\n2.1.2 :001 > require './txt2speech.rb'\r\n => true\r\n2.1.2 :002 > f = Txt2Speech.new \"Hello I am google! Nice to meet you\"\r\n => #<Txt2Speech:0x000000018aafd8 @text=\"Hello I am google! Nice to meet you\", @lang=\"en\">\r\n2.1.2 :003 > f.save(\"out.mpg\")\r\n => \"out.mpg\"\r\n```\r\n\r\nor you can load a text file to read it\r\n\r\n```\r\nt = Txt2Speech.load \"\#{Dir.home}/text.txt\"\r\nt.save(\"out.mpg\")\r\n```", @lang="en">
30
+ 2.1.2 :007 > f.save("out.mpg")
29
31
  ```
30
32
 
31
33
  Supplemental publishing:
@@ -33,7 +35,7 @@ Supplemental publishing:
33
35
 
34
36
  The MIT License (MIT)
35
37
 
36
- Copyright (c) 2014 Jared Levitz <jared.levitz@gmail.com>
38
+ Copyright (c) 2014 Viacheslav Rudkovskyi <rrubyist@gmail.com>
37
39
 
38
40
  Permission is hereby granted, free of charge, to any person obtaining a copy
39
41
  of this software and associated documentation files (the "Software"), to deal
@@ -51,4 +53,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
51
53
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
52
54
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
53
55
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
54
- THE SOFTWARE.
56
+ THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ require 'rspec/core/rake_task'
2
+ RSpec::Core::RakeTask.new(:spec)
3
+ task :default => :spec
@@ -2,4 +2,4 @@
2
2
 
3
3
  require_relative "../lib/txt2speech/application"
4
4
 
5
- Txt2Speech::Application.new
5
+ Txt2Speech::Application.new
@@ -0,0 +1,7 @@
1
+ require_relative '../lib/txt2speech'
2
+ require 'rss'
3
+
4
+ rss = RSS::Parser.parse('http://techcrunch.com/feed/', false)
5
+
6
+ f = Txt2Speech::Speech.new(rss.items.map{|item| item.title}.join('.'))
7
+ f.save("rss_reader.mpg")
File without changes
File without changes
@@ -4,30 +4,30 @@ require_relative 'speech'
4
4
  require_relative 'version'
5
5
 
6
6
  module Txt2Speech
7
- class Application
8
- def initialize
9
- options = {}
10
- OptionParser.new do |opts|
11
- opts.banner = "Usage: txt2speech [options]"
7
+ class Application
8
+ def initialize
9
+ options = {}
10
+ OptionParser.new do |opts|
11
+ opts.banner = "Usage: txt2speech [options]"
12
12
 
13
- opts.on("-o", "--output [String]", String, "Output file") {|o| options[:out] = o }
14
- opts.on("-r", "--read [String]", String, "Read text") {|o| options[:read] = o}
15
- opts.on("-f", "--file", "From file") {|o| options[:file] = o }
16
- opts.on("-l", "--lang [String]", String, "Language of text") {|o| options[:lang] = o }
17
- opts.on("-v", "--version", "Show version") {|o| options[:version] = Txt2Speech::VERSION }
18
- end.parse!
13
+ opts.on("-o", "--output [String]", String, "Output file") {|o| options[:out] = o }
14
+ opts.on("-r", "--read [String]", String, "Read text") {|o| options[:read] = o}
15
+ opts.on("-f", "--file", "From file") {|o| options[:file] = o }
16
+ opts.on("-l", "--lang [String]", String, "Language of text") {|o| options[:lang] = o }
17
+ opts.on("-v", "--version", "Show version") {|o| options[:version] = Txt2Speech::VERSION }
18
+ end.parse!
19
19
 
20
- if options[:version]
21
- puts options[:version]
22
- else
23
- out = options[:out].to_s.length > 0 ? options[:out] : "out.mp3"
20
+ if options[:version]
21
+ puts options[:version]
22
+ else
23
+ out = options[:out].to_s.length > 0 ? options[:out] : "out.mpg"
24
24
 
25
- attrs = [options[:read], options[:lang] || "en"]
26
- attrs.unshift(options[:file] ? :load : :new)
25
+ attrs = [options[:read], options[:lang] || "en"]
26
+ attrs.unshift(options[:file] ? :load : :new)
27
27
 
28
- f = Txt2Speech::Speech.send(*attrs)
29
- f.save(out)
30
- end
31
- end
32
- end
33
- end
28
+ f = Txt2Speech::Speech.send(*attrs)
29
+ f.save(out)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -3,61 +3,61 @@
3
3
  require 'net/http'
4
4
 
5
5
  module Txt2Speech
6
- class Speech
7
- GOOGLE_TRANSLATE_URL = 'http://translate.google.com/translate_tts'
8
-
9
- attr_accessor :text, :lang
10
-
11
- def initialize(text, lang = 'en')
12
- @text = text
13
- @lang = lang
14
- end
15
-
16
- def self.load(file_path, lang = 'en')
17
- f = File.open(file_path)
18
- self.new f.read.encode("UTF-16be", :invalid=>:replace, :replace=>"?").encode('UTF-8'), lang
19
- end
20
-
21
- def save(file_path)
22
- uri = URI(GOOGLE_TRANSLATE_URL)
23
-
24
- response = []
25
- ar = text.split(/[,.\r\n]/i)
26
- ar.reject! {|t| t.empty? }
27
- ar.map! {|t| divide(t) }.flatten!
28
- ar.map! {|t| t.strip }
29
-
30
- puts ar.inspect
31
-
32
- ar.each_with_index do |q, idx|
33
- uri.query = URI.encode_www_form({ ie: 'UTF-8', q: q, tl: lang, total: ar.length, idx: idx+1, textlen: q.length, prev: 'input' })
34
- res = Net::HTTP.get_response(uri)
35
-
36
- response << res.body.force_encoding(Encoding::UTF_8) if res.is_a?(Net::HTTPSuccess)
37
- end
38
-
39
- File.open(file_path, 'wb') do |f|
40
- f.write response.join
41
- return f.path
42
- end
43
- end
44
-
45
- private
46
-
47
- def divide(text)
48
- return text if text.length < 99
49
-
50
- attempts = text.length / 99.0
51
- starts = 0
52
- ar = []
53
-
54
- attempts.ceil.times do
55
- ends = starts + 99
56
- ar << text[starts...ends]
57
- starts = ends
58
- end
59
-
60
- ar
61
- end
62
- end
63
- end
6
+ class Speech
7
+ GOOGLE_TRANSLATE_URL = 'http://translate.google.com/translate_tts'
8
+
9
+ attr_accessor :text, :lang
10
+
11
+ def initialize(text, lang = 'en')
12
+ @text = text
13
+ @lang = lang
14
+ end
15
+
16
+ def self.load(file_path, lang = 'en')
17
+ f = File.open(file_path)
18
+ self.new f.read.encode("UTF-16be", :invalid=>:replace, :replace=>"?").encode('UTF-8'), lang
19
+ end
20
+
21
+ def save(file_path)
22
+ uri = URI(GOOGLE_TRANSLATE_URL)
23
+
24
+ response = []
25
+ ar = text.split(/[,.\r\n]/i)
26
+ ar.reject! {|t| t.empty? }
27
+ ar.map! {|t| divide(t) }.flatten!
28
+ ar.map! {|t| t.strip }
29
+
30
+ puts ar.inspect
31
+
32
+ ar.each_with_index do |q, idx|
33
+ uri.query = URI.encode_www_form({ ie: 'UTF-8', q: q, tl: lang, total: ar.length, idx: 0, textlen: q.length, client: 't', prev: 'input' })
34
+ res = Net::HTTP.get_response(uri)
35
+
36
+ response << res.body.force_encoding(Encoding::UTF_8) if res.is_a?(Net::HTTPSuccess)
37
+ end
38
+
39
+ File.open(file_path, 'wb') do |f|
40
+ f.write response.join
41
+ return f.path
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def divide(text)
48
+ return text if text.length < 150
49
+
50
+ attempts = text.length / 150.0
51
+ starts = 0
52
+ ar = []
53
+
54
+ attempts.ceil.times do
55
+ ends = starts + 150
56
+ ar << text[starts...ends]
57
+ starts = ends
58
+ end
59
+
60
+ ar
61
+ end
62
+ end
63
+ end
@@ -1,3 +1,3 @@
1
1
  module Txt2Speech
2
- VERSION = '0.5'
3
- end
2
+ VERSION = '0.7'
3
+ end
@@ -0,0 +1,96 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Allows RSpec to persist some state between runs in order to support
54
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
55
+ # you configure your source control system to ignore this file.
56
+ config.example_status_persistence_file_path = "spec/examples.txt"
57
+
58
+ # Limits the available syntax to the non-monkey patched syntax that is
59
+ # recommended. For more details, see:
60
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
63
+ config.disable_monkey_patching!
64
+
65
+ # This setting enables warnings. It's recommended, but in some cases may
66
+ # be too noisy due to issues in dependencies.
67
+ config.warnings = true
68
+
69
+ # Many RSpec users commonly either run the entire suite or an individual
70
+ # file, and it's useful to allow more verbose output when running an
71
+ # individual spec file.
72
+ if config.files_to_run.one?
73
+ # Use the documentation formatter for detailed output,
74
+ # unless a formatter has already been configured
75
+ # (e.g. via a command-line flag).
76
+ config.default_formatter = 'doc'
77
+ end
78
+
79
+ # Print the 10 slowest examples and example groups at the
80
+ # end of the spec run, to help surface which specs are running
81
+ # particularly slow.
82
+ config.profile_examples = 10
83
+
84
+ # Run specs in random order to surface order dependencies. If you find an
85
+ # order dependency and want to debug it, you can fix the order by providing
86
+ # the seed, which is printed after each run.
87
+ # --seed 1234
88
+ config.order = :random
89
+
90
+ # Seed global randomization in this process using the `--seed` CLI option.
91
+ # Setting this allows you to use `--seed` to deterministically reproduce
92
+ # test failures related to randomization by passing the same `--seed` value
93
+ # as the one that triggered the failure.
94
+ Kernel.srand config.seed
95
+ =end
96
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+ require './lib/txt2speech'
4
+
5
+ RSpec.describe Txt2Speech::Speech, '#new' do
6
+ context 'with english text' do
7
+ let!(:output_path) { "/tmp/txt2speech.mp4" }
8
+
9
+ it 'converts string to the audio file' do
10
+ @speech = Txt2Speech::Speech.new("Hello World")
11
+ end
12
+
13
+ it 'load a file and save it to audio file' do
14
+ File.open("/tmp/txt2speech.txt", "w+") do |f|
15
+ f.write("Hello World from file")
16
+ end
17
+ @speech = Txt2Speech::Speech.load("/tmp/txt2speech.txt")
18
+ end
19
+
20
+ after(:each) do
21
+ @speech.save(output_path)
22
+ expect(File.exists?(output_path)).to eq(true)
23
+ [output_path, "/tmp/txt2speech.txt"].each do |f|
24
+ FileUtils.rm(f) if File.exists?(f)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -8,10 +8,10 @@ Gem::Specification.new do |s|
8
8
  s.date = '2014-12-17'
9
9
  s.summary = "txt2speech"
10
10
  s.description = "txt2Speech lifehack of using Google Translate. Allow you to convert text into speech."
11
- s.authors = ["Jared Levitz"]
12
- s.email = 'jared.levitz@gmail.com'
11
+ s.authors = ["Viacheslav Rudkovskyi"]
12
+ s.email = 'rrubyist@gmail.com'
13
13
  s.files = `git ls-files`.split("\n")
14
14
  s.executables = ['txt2speech']
15
15
  s.homepage = 'http://github.com/rudkovsky/txt2speech'
16
16
  s.license = 'MIT'
17
- end
17
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: txt2speech
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.7'
5
5
  platform: ruby
6
6
  authors:
7
- - Jared Levitz
7
+ - Viacheslav Rudkovskyi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -12,21 +12,29 @@ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: txt2Speech lifehack of using Google Translate. Allow you to convert text
14
14
  into speech.
15
- email: jared.levitz@gmail.com
15
+ email: rrubyist@gmail.com
16
16
  executables:
17
17
  - txt2speech
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - Gemfile
24
+ - Gemfile.lock
21
25
  - README.md
26
+ - Rakefile
22
27
  - bin/txt2speech
23
28
  - examples/de.txt
24
29
  - examples/en.txt
30
+ - examples/rss_reader.rb
25
31
  - examples/ru.txt
26
32
  - lib/txt2speech.rb
27
33
  - lib/txt2speech/application.rb
28
34
  - lib/txt2speech/speech.rb
29
35
  - lib/txt2speech/version.rb
36
+ - spec/spec_helper.rb
37
+ - spec/speech_spec.rb
30
38
  - txt2speech.gemspec
31
39
  homepage: http://github.com/rudkovsky/txt2speech
32
40
  licenses: