talks 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +11 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +2 -0
- data/README.md +34 -6
- data/Rakefile +29 -0
- data/lib/talks.rb +19 -7
- data/lib/talks/configuration.rb +42 -12
- data/lib/talks/hooks.rb +2 -14
- data/lib/talks/runner.rb +3 -1
- data/lib/talks/version.rb +1 -1
- data/spec/talks/basic_spec.rb +76 -0
- data/spec/test_data/talksrc +5 -0
- data/talks.gemspec +3 -3
- metadata +11 -7
- data/spec/talks.rb +0 -25
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.8.7
|
4
|
+
- 1.9.2
|
5
|
+
- 1.9.3
|
6
|
+
- jruby-18mode # JRuby in 1.8 mode
|
7
|
+
- jruby-19mode # JRuby in 1.9 mode
|
8
|
+
- rbx-18mode
|
9
|
+
- rbx-19mode
|
10
|
+
# uncomment this line if your project needs to run something other than `rake`:
|
11
|
+
# script: bundle exec rspec spec
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
# Talks gem — now your ruby can talk with you
|
1
|
+
# Talks gem — now your ruby and command-line tools can talk with you
|
2
2
|
|
3
|
-
###
|
3
|
+
### This is beta now.
|
4
4
|
|
5
|
-
###
|
5
|
+
### Build Status ![http://travis-ci.org/ruby-talks/talks](https://secure.travis-ci.org/ruby-talks/talks.png)
|
6
6
|
|
7
|
-
If you want to HEAR some response from your code, just use this gem.
|
7
|
+
If you want to HEAR some response from your code or command-line tools, just use this gem.
|
8
|
+
|
9
|
+
You can use this gem on MacOS X and on other linux/unix systems with installed [espeak](http://espeak.sourceforge.net).
|
8
10
|
|
9
11
|
Sponsored by Evil Martians <http://evilmartians.com>
|
10
12
|
|
@@ -13,7 +15,7 @@ Sponsored by Evil Martians <http://evilmartians.com>
|
|
13
15
|
For example - some really long task and you just get some coffee, read book or surf internet
|
14
16
|
and you want to know when this task will ends, but don't want to check your mac or terminal each minute -
|
15
17
|
you can just add small hook in the end of your code and when it will ends - you will hear it with voice that you
|
16
|
-
choose from MacOS X `say` function collection.
|
18
|
+
choose from MacOS X `say` function collection or from `espeak` collection.
|
17
19
|
|
18
20
|
You can find some examples of `talks` usage in organization [ruby-talks](https://github.com/ruby-talks):
|
19
21
|
|
@@ -23,7 +25,10 @@ You can find some examples of `talks` usage in organization [ruby-talks](https:/
|
|
23
25
|
|
24
26
|
## How?
|
25
27
|
|
26
|
-
|
28
|
+
On MacOS X this gem just using native MacOS X `say` command line tool.
|
29
|
+
On linix/unix this gem using espeak speech synthesis.
|
30
|
+
|
31
|
+
### In all examples below I used MacOS X voice types. For espeak you can read section [Using talks with espeak](https://github.com/ruby-talks/talks#using-talks-with-espeak)
|
27
32
|
|
28
33
|
### Configuration
|
29
34
|
|
@@ -32,6 +37,7 @@ You can configure default voices and messages for `talks` with `~/.talksrc` file
|
|
32
37
|
`~/.talksrc`
|
33
38
|
```yml
|
34
39
|
default_voice: 'whisper'
|
40
|
+
engine: 'say'
|
35
41
|
voices:
|
36
42
|
info: 'pipe'
|
37
43
|
messages:
|
@@ -122,6 +128,28 @@ VOICES = %w(
|
|
122
128
|
)
|
123
129
|
```
|
124
130
|
|
131
|
+
### Using talks with espeak
|
132
|
+
|
133
|
+
You can configure your `talks` usage even on MacOS X for using [espeak](http://espeak.sourceforge.net):
|
134
|
+
|
135
|
+
`~/.talksrc`
|
136
|
+
```yml
|
137
|
+
engine: 'espeak'
|
138
|
+
```
|
139
|
+
|
140
|
+
Otherwise `talks` will set engine by default to `say` on MacOS X and to `espeak` on all other OS if command `which espeak` returns something than empty string.
|
141
|
+
|
142
|
+
For espeak you have different set of voices and many languages (which this gem not support yet). Voices for espeak:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
Talks.voices[:espeak]
|
146
|
+
# =>
|
147
|
+
[
|
148
|
+
'en+m1', 'en+m2', 'en+m3', 'en+m4', 'en+m5', 'en+m6', 'en+m7',
|
149
|
+
'en+f1', 'en+f2', 'en+f3', 'en+f4', 'en+f5', 'en+f6', 'en+f7'
|
150
|
+
]
|
151
|
+
```
|
152
|
+
|
125
153
|
## Who?
|
126
154
|
|
127
155
|
I did it by myself
|
data/Rakefile
CHANGED
@@ -7,3 +7,32 @@ desc 'Run all tests by default'
|
|
7
7
|
task :default do
|
8
8
|
system("rspec spec")
|
9
9
|
end
|
10
|
+
|
11
|
+
desc 'Run if you want to hear all types of Talks.say'
|
12
|
+
task :all do
|
13
|
+
require File.expand_path('../lib/talks.rb', __FILE__)
|
14
|
+
|
15
|
+
Talks.voices.each do |v|
|
16
|
+
p v
|
17
|
+
Talks.say 'Tests start', :voice => v
|
18
|
+
end
|
19
|
+
|
20
|
+
p 'say `say`'
|
21
|
+
Talks.say 'say'
|
22
|
+
p 'info `say again`'
|
23
|
+
Talks.info 'say again'
|
24
|
+
p 'warn `I warn you`'
|
25
|
+
Talks.warn 'I warn you'
|
26
|
+
p 'error `This is how error sounds`'
|
27
|
+
Talks.error 'This is how error sounds'
|
28
|
+
p 'success `This is success!`'
|
29
|
+
Talks.success 'This is success!'
|
30
|
+
p 'info `default`'
|
31
|
+
Talks.info
|
32
|
+
p 'warn `default`'
|
33
|
+
Talks.warn
|
34
|
+
p 'warn `error`'
|
35
|
+
Talks.error
|
36
|
+
p 'warn `success`'
|
37
|
+
Talks.success
|
38
|
+
end
|
data/lib/talks.rb
CHANGED
@@ -4,11 +4,16 @@ require File.expand_path('../talks/hooks.rb', __FILE__)
|
|
4
4
|
module Talks
|
5
5
|
class << self
|
6
6
|
|
7
|
-
VOICES =
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
VOICES = {
|
8
|
+
:say => %w(
|
9
|
+
agnes albert alex bad bahh bells boing bruce bubbles cellos
|
10
|
+
deranged fred good hysterical junior kathy pipe princess ralph
|
11
|
+
trinoids vicki victoria whisper zarvox
|
12
|
+
),
|
13
|
+
:espeak => %w(en+m1 en+m2 en+m3 en+m4 en+m5 en+m6 en+m7
|
14
|
+
en+f1 en+f2 en+f3 en+f4 en+f5 en+f6 en+f7
|
15
|
+
)
|
16
|
+
}
|
12
17
|
|
13
18
|
TYPES = [:info, :warn, :success, :error]
|
14
19
|
|
@@ -24,7 +29,14 @@ module Talks
|
|
24
29
|
|
25
30
|
def say(message, options = {})
|
26
31
|
type = options[:type] || :default
|
27
|
-
|
32
|
+
case config.engine
|
33
|
+
when 'say'
|
34
|
+
`say -v #{say_voice(type, options)} '#{message}'`
|
35
|
+
when 'espeak'
|
36
|
+
`espeak -v #{say_voice(type, options)} '#{message}'`
|
37
|
+
else
|
38
|
+
abort "Don't know that engine now: #{config.engine}"
|
39
|
+
end
|
28
40
|
end
|
29
41
|
|
30
42
|
def add_hooks(command)
|
@@ -41,7 +53,7 @@ module Talks
|
|
41
53
|
private
|
42
54
|
|
43
55
|
def say_voice(type, options)
|
44
|
-
if options[:voice] and VOICES.include?(options[:voice].to_s)
|
56
|
+
if options[:voice] and VOICES[config.engine.to_sym].include?(options[:voice].to_s)
|
45
57
|
options[:voice]
|
46
58
|
elsif TYPES.include? type
|
47
59
|
config.voice type
|
data/lib/talks/configuration.rb
CHANGED
@@ -4,26 +4,35 @@ module Talks
|
|
4
4
|
class Configuration
|
5
5
|
|
6
6
|
DEFAULT_VOICES = {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
:say => {
|
8
|
+
:info => 'vicki',
|
9
|
+
:warn => 'whisper',
|
10
|
+
:success => 'vicki',
|
11
|
+
:error => 'bad'
|
12
|
+
},
|
13
|
+
:espeak => {
|
14
|
+
:info => 'english',
|
15
|
+
:warn => 'english',
|
16
|
+
:success => 'english',
|
17
|
+
:error => 'english'
|
18
|
+
}
|
11
19
|
}
|
12
20
|
|
13
21
|
DEFAULT_MESSAGES = {
|
14
|
-
info
|
15
|
-
warn
|
16
|
-
success
|
17
|
-
error
|
22
|
+
:info => 'Information note',
|
23
|
+
:warn => 'Warning',
|
24
|
+
:success => 'Success',
|
25
|
+
:error => 'Error'
|
18
26
|
}
|
19
27
|
|
20
|
-
attr_accessor :voices, :messages, :default_voice, :options
|
28
|
+
attr_accessor :voices, :messages, :default_voice, :options, :engine
|
21
29
|
|
22
30
|
def initialize(opts)
|
23
31
|
@options = symbolize_hash_keys(opts)
|
24
|
-
@
|
25
|
-
@
|
26
|
-
|
32
|
+
@engine = options[:engine] || default_engine_for_os
|
33
|
+
@default_voice = options[:default_voice] || default_voice_for(engine)
|
34
|
+
@voices = options[:voices] && DEFAULT_VOICES[engine.to_sym].merge(options[:voices]) ||
|
35
|
+
DEFAULT_VOICES[engine.to_sym]
|
27
36
|
@messages = options[:messages] && DEFAULT_MESSAGES.merge(options[:messages]) ||
|
28
37
|
DEFAULT_MESSAGES
|
29
38
|
end
|
@@ -58,6 +67,27 @@ module Talks
|
|
58
67
|
|
59
68
|
private
|
60
69
|
|
70
|
+
def default_voice_for(talks_engine)
|
71
|
+
case talks_engine
|
72
|
+
when 'say'
|
73
|
+
'vicki'
|
74
|
+
when 'espeak'
|
75
|
+
'en+f3'
|
76
|
+
else
|
77
|
+
abort "Don't know this engine now: #{talks_engine}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def default_engine_for_os
|
82
|
+
if RUBY_PLATFORM =~ /darwin/i
|
83
|
+
'say'
|
84
|
+
elsif !(`which espeak`.empty?)
|
85
|
+
'espeak'
|
86
|
+
else
|
87
|
+
abort 'Now talks can work only on MacOS X, you can help with support other OS'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
61
91
|
def symbolize_hash_keys(opts)
|
62
92
|
sym_opts = {}
|
63
93
|
opts.each do |key, value|
|
data/lib/talks/hooks.rb
CHANGED
@@ -3,7 +3,7 @@ module Talks
|
|
3
3
|
class << self
|
4
4
|
|
5
5
|
def create(args)
|
6
|
-
engine =
|
6
|
+
engine = Talks.config.engine
|
7
7
|
options, args = shift_options(args.dup)
|
8
8
|
command_name = command args
|
9
9
|
voice, before_message, after_message = parse options, command_name
|
@@ -37,14 +37,6 @@ module Talks
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def check_engine
|
41
|
-
if RUBY_PLATFORM =~ /darwin/i
|
42
|
-
'say'
|
43
|
-
else
|
44
|
-
abort 'Now talks can work only on MacOS X, you can help with support other OS'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
40
|
def parse(options, command_name)
|
49
41
|
voice = options['-v'] || options['--voice'] ||
|
50
42
|
Talks.config.voice_for(command_name.to_sym) ||
|
@@ -62,11 +54,7 @@ module Talks
|
|
62
54
|
end
|
63
55
|
|
64
56
|
def hook(engine, voice, message)
|
65
|
-
|
66
|
-
"say #{message} -v #{voice}"
|
67
|
-
else
|
68
|
-
abort 'Now you can use talks gem only on mac with say'
|
69
|
-
end
|
57
|
+
"#{engine} -v #{voice} '#{message}'"
|
70
58
|
end
|
71
59
|
|
72
60
|
end
|
data/lib/talks/runner.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# What file is used for talks startup configuration.
|
2
2
|
initfile = if File.exists?('./.talksrc')
|
3
3
|
'./.talksrc'
|
4
|
-
elsif
|
4
|
+
elsif defined?(OPTS_INITFILE)
|
5
|
+
OPTS_INITFILE
|
6
|
+
else
|
5
7
|
if RUBY_PLATFORM =~ /mswin/
|
6
8
|
# Of course MS Windows has to be different
|
7
9
|
OPTS_INITFILE = 'talks.ini'
|
data/lib/talks/version.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
OPTS_INITFILE = 'spec/test_data/talksrc'
|
2
|
+
require 'talks'
|
3
|
+
|
4
|
+
describe Talks do
|
5
|
+
|
6
|
+
it 'should have default methods' do
|
7
|
+
[:add_hooks, :info, :error, :success, :warn, :say, :config].each do |method|
|
8
|
+
Talks.methods.include?(method).should be_true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#config' do
|
13
|
+
|
14
|
+
it 'should load initfile' do
|
15
|
+
Talks.config.options.should_not be_empty
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should load default values from initfile' do
|
19
|
+
Talks.config.default_voice.should == 'agnes'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should contain default values for voices and messages' do
|
23
|
+
Talks.config.voices.keys.should_not be_empty
|
24
|
+
Talks.config.messages.keys.should_not be_empty
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should return voice for type' do
|
28
|
+
Talks.config.voice(:info).should == 'vicki'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should return message for type' do
|
32
|
+
Talks.config.message(:info).should == 'Information note'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return message for command if it is in .talksrc' do
|
36
|
+
Talks.config.message_for(:bundle, :before).should == 'Bundle before message'
|
37
|
+
Talks.config.message_for(:bundle, :after).should == 'Bundle after message'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return voice for command if it is in .talksrc' do
|
41
|
+
Talks.config.voice_for(:bundle).should == 'bad'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should return default message for command' do
|
45
|
+
Talks.config.default_message_for(:bundle, :before).should == 'bundle task started'
|
46
|
+
Talks.config.default_message_for(:bundle, :after).should == 'bundle task ended'
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'hooks' do
|
52
|
+
|
53
|
+
it 'should create hooks for any command by default' do
|
54
|
+
Talks.add_hooks(['ls']).should == "say -v agnes 'ls task started'; ls; say -v agnes 'ls task ended'"
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should create preconfigured hooks for command from .talksrc' do
|
58
|
+
Talks.add_hooks(['bundle']).should == "say -v bad 'Bundle before message'; bundle; say -v bad 'Bundle after message'"
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should change voice if option sended' do
|
62
|
+
Talks.add_hooks(['-v', 'vicki', 'ls']).should == "say -v vicki 'ls task started'; ls; say -v vicki 'ls task ended'"
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should change messages if option sended' do
|
66
|
+
Talks.add_hooks(['-bm', 'test', 'ls']).should == "say -v agnes 'test'; ls; say -v agnes 'ls task ended'"
|
67
|
+
Talks.add_hooks(['-am', 'test', 'ls']).should == "say -v agnes 'ls task started'; ls; say -v agnes 'test'"
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should create hooks for command inside `bundle exec` by default' do
|
71
|
+
Talks.add_hooks(['bundle', 'exec', 'ls']).should == "say -v agnes 'ls task started'; bundle exec ls; say -v agnes 'ls task ended'"
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/talks.gemspec
CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ['gazay']
|
10
10
|
s.email = ['alex.gaziev@gmail.com']
|
11
|
-
s.homepage = "https://github.com/
|
12
|
-
s.summary = %q{
|
13
|
-
s.description = %q{
|
11
|
+
s.homepage = "https://github.com/ruby-talks/talks"
|
12
|
+
s.summary = %q{Gem for talking ruby code and command-line tools}
|
13
|
+
s.description = %q{This gem can be used for wraping command-lines with `talks` command or for adding hooks in ruby code which would tell you something}
|
14
14
|
|
15
15
|
s.rubyforge_project = "talks"
|
16
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: talks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: This gem can be used for wraping command-lines with `talks` command or
|
15
|
+
for adding hooks in ruby code which would tell you something
|
15
16
|
email:
|
16
17
|
- alex.gaziev@gmail.com
|
17
18
|
executables:
|
@@ -20,6 +21,7 @@ executables:
|
|
20
21
|
extensions: []
|
21
22
|
extra_rdoc_files: []
|
22
23
|
files:
|
24
|
+
- .travis.yml
|
23
25
|
- CHANGELOG.md
|
24
26
|
- Gemfile
|
25
27
|
- README.md
|
@@ -31,9 +33,10 @@ files:
|
|
31
33
|
- lib/talks/hooks.rb
|
32
34
|
- lib/talks/runner.rb
|
33
35
|
- lib/talks/version.rb
|
34
|
-
- spec/talks.rb
|
36
|
+
- spec/talks/basic_spec.rb
|
37
|
+
- spec/test_data/talksrc
|
35
38
|
- talks.gemspec
|
36
|
-
homepage: https://github.com/
|
39
|
+
homepage: https://github.com/ruby-talks/talks
|
37
40
|
licenses: []
|
38
41
|
post_install_message:
|
39
42
|
rdoc_options: []
|
@@ -56,6 +59,7 @@ rubyforge_project: talks
|
|
56
59
|
rubygems_version: 1.8.24
|
57
60
|
signing_key:
|
58
61
|
specification_version: 3
|
59
|
-
summary:
|
62
|
+
summary: Gem for talking ruby code and command-line tools
|
60
63
|
test_files:
|
61
|
-
- spec/talks.rb
|
64
|
+
- spec/talks/basic_spec.rb
|
65
|
+
- spec/test_data/talksrc
|
data/spec/talks.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.expand_path('../../lib/talks.rb', __FILE__)
|
2
|
-
|
3
|
-
Talks.voices.each do |v|
|
4
|
-
p v
|
5
|
-
Talks.say 'Tests start', voice: v
|
6
|
-
end
|
7
|
-
|
8
|
-
p 'say `say`'
|
9
|
-
Talks.say 'say'
|
10
|
-
p 'info `say again`'
|
11
|
-
Talks.info 'say again'
|
12
|
-
p 'warn `I warn you`'
|
13
|
-
Talks.warn 'I warn you'
|
14
|
-
p 'error `This is how error sounds`'
|
15
|
-
Talks.error 'This is how error sounds'
|
16
|
-
p 'success `This is success!`'
|
17
|
-
Talks.success 'This is success!'
|
18
|
-
p 'info `default`'
|
19
|
-
Talks.info
|
20
|
-
p 'warn `default`'
|
21
|
-
Talks.warn
|
22
|
-
p 'warn `error`'
|
23
|
-
Talks.error
|
24
|
-
p 'warn `success`'
|
25
|
-
Talks.success
|