sbire 0.0.10 → 0.0.11
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 +4 -4
- data/README.md +32 -16
- data/bin/sbire +1 -1
- data/files/config_linux.yml +1 -0
- data/files/config_mac.yml +1 -0
- data/files/config_win.yml +1 -0
- data/lib/sbire.rb +10 -2
- data/lib/sbire/audio_converter.rb +16 -7
- data/lib/sbire/audio_recorder.rb +1 -1
- data/lib/sbire/command.rb +22 -18
- data/lib/sbire/command_manager.rb +0 -2
- data/lib/sbire/notifier.rb +0 -2
- data/lib/sbire/pipe_manager.rb +20 -0
- data/lib/sbire/save_manager.rb +6 -23
- data/lib/sbire/sbire_config.rb +9 -3
- data/lib/sbire/stream_manager.rb +38 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b95928f61c106d66ace43ecd8cb62f90aaa719f
|
4
|
+
data.tar.gz: 3fb14d64359c679e08c4d4369243c4aa603f13d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb710a9f522f51769f9f5e1b9324f7ddf90e0bacc9279d07f6f570575c507f4bd56824dae8d19070a9226b9bec13fe304f4221620af7dcd3e68461c8ec9fa6d4
|
7
|
+
data.tar.gz: 55d2c350688d2339d9758f3b5e8acda7c6d606bd075c863fcad9fb1cf665963bdd0a3e023c1e81529476b43927668cd1294ac2c029be3dfdef47e3bd06d571c6
|
data/README.md
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
# Sbire
|
2
2
|
|
3
|
-
|
3
|
+
"Sbire" is the French word for henchman. Sbire is program which is capable to listen what you said and execute the command associated.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
Linux :
|
8
8
|
|
9
|
-
sudo apt-get install sox notify-osd ruby1.9.1
|
9
|
+
sudo apt-get install sox notify-osd ruby1.9.1 xdotool
|
10
10
|
gem install sbire
|
11
11
|
sbire install
|
12
12
|
|
13
|
-
|
13
|
+
OSX:
|
14
14
|
|
15
15
|
brew install sox
|
16
|
+
sudo port install xdotool
|
16
17
|
gem install sbire
|
17
18
|
sbire install
|
18
19
|
|
19
|
-
|
20
|
+
Windows :
|
20
21
|
|
21
22
|
Install ruby with [RubyInstall](http://rubyinstaller.org/)
|
22
23
|
gem install sbire
|
@@ -24,38 +25,53 @@ On windows :
|
|
24
25
|
|
25
26
|
## Usage
|
26
27
|
|
27
|
-
To
|
28
|
+
To run a command :
|
28
29
|
|
29
30
|
- Open a terminal
|
30
31
|
- Type `sbire start`
|
31
|
-
- Say the command
|
32
|
-
- Type `sbire stop`
|
32
|
+
- Say the command ("Firefox" for example)
|
33
33
|
- The command will be executed
|
34
34
|
|
35
|
+
To write where your cursor is :
|
36
|
+
|
37
|
+
- Open a terminal
|
38
|
+
- Type `sbire pipe`
|
39
|
+
- Say the text ("This project rocks" for example)
|
40
|
+
- It will write the text where your cursor is
|
41
|
+
|
35
42
|
To write a text file :
|
36
43
|
|
37
44
|
- Open a terminal
|
38
|
-
- Type `sbire start`
|
39
|
-
- Say what you want ("This project rocks" for example)
|
40
45
|
- Type `sbire save`
|
46
|
+
- Say the text ("This project rocks" for example)
|
41
47
|
- A file will be created in `~\.sbire\text`
|
42
48
|
|
43
|
-
|
49
|
+
To stop sbire, type `sbire stop`.
|
50
|
+
|
51
|
+
If you want to see what is written in the file in real time, run `tail -f ~\.sbire\text`.
|
44
52
|
|
45
53
|
## Configuration
|
46
54
|
|
47
|
-
By default, the language is en-us. You can change it by changing the
|
55
|
+
By default, the language is en-us. You can change it by changing the value of `lang` by your language. For example, to set it to French, write:
|
56
|
+
```
|
57
|
+
lang: fr-FR`
|
58
|
+
```
|
48
59
|
|
49
60
|
## Bind phrase and commands
|
50
61
|
|
51
|
-
You can bind more complexe phrases with commands by adding a
|
52
|
-
|
62
|
+
You can bind more complexe phrases with commands by adding a `~\.sbire\commands.yml` file and write for example:
|
63
|
+
```
|
53
64
|
"chromium-browser": ["open chrome", "chrome"]
|
54
65
|
"skype": "open skype"
|
66
|
+
```
|
67
|
+
|
68
|
+
## Pipe the text with a custom command
|
69
|
+
|
70
|
+
By default, when you use `sbire pipe`, it will use a command to emulate the keyboard. You can change it by editing the file `~\.sbire\config.yml` and change the value of `pipe_command` by anything you want.
|
55
71
|
|
56
|
-
##
|
72
|
+
## Add a shortcut
|
57
73
|
|
58
|
-
For
|
74
|
+
For some obscure reason, Ubuntu does not run ruby commands binded with a keyboard shortcut. You must install [xbindkeys](http://doc.ubuntu-fr.org/xbindkeys) to make it work.
|
59
75
|
|
60
76
|
## Contributing
|
61
77
|
|
data/bin/sbire
CHANGED
data/files/config_linux.yml
CHANGED
data/files/config_mac.yml
CHANGED
data/files/config_win.yml
CHANGED
data/lib/sbire.rb
CHANGED
@@ -1,10 +1,18 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'thor'
|
3
|
+
require 'json'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'rest_client'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
require_relative 'sbire/sbire_config'
|
1
9
|
require_relative 'sbire/command'
|
2
10
|
require_relative 'sbire/notifier'
|
3
11
|
require_relative 'sbire/audio_converter'
|
4
12
|
require_relative 'sbire/command_manager'
|
5
13
|
require_relative 'sbire/audio_recorder'
|
6
14
|
require_relative 'sbire/save_manager'
|
7
|
-
require_relative 'sbire/
|
15
|
+
require_relative 'sbire/pipe_manager'
|
16
|
+
require_relative 'sbire/stream_manager'
|
8
17
|
require_relative 'sbire/pid_manager'
|
9
18
|
require_relative 'sbire/os'
|
10
|
-
require 'rest_client'
|
@@ -1,7 +1,3 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'rest_client'
|
4
|
-
|
5
1
|
module Sbire
|
6
2
|
class AudioConverter
|
7
3
|
attr_accessor :pid_manager
|
@@ -47,7 +43,12 @@ module Sbire
|
|
47
43
|
response = RestClient.post url,
|
48
44
|
file,
|
49
45
|
content_type: 'audio/x-flac; rate=16000'
|
50
|
-
read_response(response.to_str) if response.code == 200
|
46
|
+
response = read_response(response.to_str) if response.code == 200
|
47
|
+
if response
|
48
|
+
return response
|
49
|
+
else
|
50
|
+
return empty_result
|
51
|
+
end
|
51
52
|
rescue => e
|
52
53
|
puts e
|
53
54
|
return [""]
|
@@ -60,8 +61,16 @@ module Sbire
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def read_response(text)
|
63
|
-
|
64
|
-
|
64
|
+
if text && text.empty?
|
65
|
+
empty_result
|
66
|
+
else
|
67
|
+
data = JSON.parse(text)
|
68
|
+
data['hypotheses'].map {|ut| [ut['utterance'], ut['confidence']] }.first
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def empty_result
|
73
|
+
['', 0]
|
65
74
|
end
|
66
75
|
|
67
76
|
def url
|
data/lib/sbire/audio_recorder.rb
CHANGED
@@ -17,7 +17,7 @@ module Sbire
|
|
17
17
|
|
18
18
|
private
|
19
19
|
def record_audio
|
20
|
-
fork { exec "sox -t alsa -r 22050 default #{path}.flac -q silence -l 1 0
|
20
|
+
fork { exec "sox -t alsa -r 22050 default #{path}.flac -q silence -l 1 0 2% 1 1.0 2% rate 16k : newfile : restart" }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/sbire/command.rb
CHANGED
@@ -1,25 +1,10 @@
|
|
1
1
|
module Sbire
|
2
|
-
class Command
|
2
|
+
class Command < Thor
|
3
|
+
package_name "Sbire"
|
3
4
|
|
4
5
|
attr_accessor :command
|
5
6
|
|
6
|
-
|
7
|
-
self.new(argv).call
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(argv)
|
11
|
-
@command = argv.first
|
12
|
-
end
|
13
|
-
|
14
|
-
def call
|
15
|
-
if ["start", "stop", "save", "install"].include?(command)
|
16
|
-
send(command)
|
17
|
-
else
|
18
|
-
show("Command not found")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
7
|
+
desc "start", "Start to listening your voice and execute associated commands"
|
23
8
|
def start
|
24
9
|
stop
|
25
10
|
show("Sbire is listening your voice")
|
@@ -29,11 +14,13 @@ module Sbire
|
|
29
14
|
end
|
30
15
|
end
|
31
16
|
|
17
|
+
desc "stop", "Stop all dependencies of Sbire"
|
32
18
|
def stop
|
33
19
|
audio_recorder.stop
|
34
20
|
audio_converter.stop
|
35
21
|
end
|
36
22
|
|
23
|
+
desc "save", "Save what you say in ~/.sbire/text. You can customize the path by edition ~/.sbire/config.yml"
|
37
24
|
def save
|
38
25
|
stop
|
39
26
|
show("Sbire is listening your voice")
|
@@ -44,6 +31,17 @@ module Sbire
|
|
44
31
|
end
|
45
32
|
end
|
46
33
|
|
34
|
+
desc "pipe", "Send what you say to another command. You can customize the commd by editing ~/.sbire/config.yml"
|
35
|
+
def pipe
|
36
|
+
stop
|
37
|
+
show("Sbire is listening your voice")
|
38
|
+
audio_recorder.start
|
39
|
+
audio_converter.start do |results, index|
|
40
|
+
pipe_manager.pipe(results, index) if results
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "install", "Install Sbire"
|
47
45
|
def install
|
48
46
|
home = Dir.home
|
49
47
|
config_file = "config_#{OS.familly}.yml"
|
@@ -53,6 +51,8 @@ module Sbire
|
|
53
51
|
FileUtils.copy(path, "#{home}/.sbire/config.yml")
|
54
52
|
end
|
55
53
|
|
54
|
+
private
|
55
|
+
|
56
56
|
def recreate_text_file
|
57
57
|
File.write(SbireConfig.text_file, '')
|
58
58
|
end
|
@@ -73,6 +73,10 @@ module Sbire
|
|
73
73
|
@save_manager ||= SaveManager.new
|
74
74
|
end
|
75
75
|
|
76
|
+
def pipe_manager
|
77
|
+
@pipe_manager ||= PipeManager.new
|
78
|
+
end
|
79
|
+
|
76
80
|
def show(message)
|
77
81
|
Notifier.call(message)
|
78
82
|
end
|
data/lib/sbire/notifier.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Sbire
|
2
|
+
class PipeManager
|
3
|
+
def pipe(hypotheses, index)
|
4
|
+
stream_manager.execute(hypotheses, index) do |result|
|
5
|
+
send_command(result)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def stream_manager
|
12
|
+
@stream_manager ||= StreamManager.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def send_command(text)
|
16
|
+
command = SbireConfig.pipe_command % { text: text }
|
17
|
+
system(command)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/sbire/save_manager.rb
CHANGED
@@ -1,36 +1,19 @@
|
|
1
1
|
module Sbire
|
2
2
|
class SaveManager
|
3
|
-
attr_accessor :last_index, :max_index
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@last_index = 0
|
7
|
-
@max_index = 0
|
8
|
-
end
|
9
|
-
|
10
3
|
def save(hypotheses, index)
|
11
|
-
|
12
|
-
|
13
|
-
unless hypotheses.include?(nil)
|
14
|
-
append_to_file(hypotheses)
|
15
|
-
@last_index = index + 1
|
4
|
+
stream_manager.execute(hypotheses, index) do |result|
|
5
|
+
append_to_file(result)
|
16
6
|
end
|
17
7
|
end
|
18
8
|
|
19
9
|
private
|
20
10
|
|
21
|
-
def
|
22
|
-
@
|
11
|
+
def stream_manager
|
12
|
+
@stream_manager ||= StreamManager.new
|
23
13
|
end
|
24
14
|
|
25
|
-
def
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def append_to_file(hypotheses)
|
30
|
-
text = hypotheses.join(" ") + " "
|
31
|
-
if text != " "
|
32
|
-
File.open(SbireConfig.text_file, 'ab+') {|file| file.write(text)}
|
33
|
-
end
|
15
|
+
def append_to_file(text)
|
16
|
+
File.open(SbireConfig.text_file, 'ab+') {|file| file.write(text)}
|
34
17
|
end
|
35
18
|
end
|
36
19
|
end
|
data/lib/sbire/sbire_config.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
1
|
module Sbire
|
4
2
|
class SbireConfig
|
5
3
|
def self.config_path
|
@@ -7,7 +5,11 @@ module Sbire
|
|
7
5
|
end
|
8
6
|
|
9
7
|
def self.base_directory
|
10
|
-
"
|
8
|
+
if ENV["mode"] == "test"
|
9
|
+
"./spec/fixtures"
|
10
|
+
else
|
11
|
+
"#{Dir.home}/.sbire"
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
def self.lang
|
@@ -34,6 +36,10 @@ module Sbire
|
|
34
36
|
config["notify_command"]
|
35
37
|
end
|
36
38
|
|
39
|
+
def self.pipe_command
|
40
|
+
config["pipe_command"]
|
41
|
+
end
|
42
|
+
|
37
43
|
private
|
38
44
|
|
39
45
|
def self.config
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Sbire
|
2
|
+
class StreamManager
|
3
|
+
attr_accessor :last_index, :max_index
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@last_index = 0
|
7
|
+
@max_index = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute(hypotheses, index, &block)
|
11
|
+
compute_max_index(index)
|
12
|
+
hypotheses = current_hypotheses(hypotheses)
|
13
|
+
unless hypotheses.include?(nil)
|
14
|
+
send_result(hypotheses, block)
|
15
|
+
@last_index = index + 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def compute_max_index(index)
|
22
|
+
@max_index = index if @max_index < index
|
23
|
+
end
|
24
|
+
|
25
|
+
def current_hypotheses(hypotheses)
|
26
|
+
hypotheses.map { |hypothese| hypothese.first }[last_index..max_index]
|
27
|
+
end
|
28
|
+
|
29
|
+
def send_result(hypotheses, block)
|
30
|
+
text = sanitize(hypotheses.join(" ")) + " "
|
31
|
+
block.call(text) if text != " "
|
32
|
+
end
|
33
|
+
|
34
|
+
def sanitize(text)
|
35
|
+
text.gsub('"', '\"')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sbire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guirec Corbel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Sbire is a command line tool that recognize your voice and execute commands
|
28
42
|
linked
|
29
43
|
email: guirec.corbel@gmail.com
|
@@ -34,8 +48,10 @@ extra_rdoc_files: []
|
|
34
48
|
files:
|
35
49
|
- bin/sbire
|
36
50
|
- lib/sbire.rb
|
51
|
+
- lib/sbire/pipe_manager.rb
|
37
52
|
- lib/sbire/audio_converter.rb
|
38
53
|
- lib/sbire/audio_recorder.rb
|
54
|
+
- lib/sbire/stream_manager.rb
|
39
55
|
- lib/sbire/os.rb
|
40
56
|
- lib/sbire/command_manager.rb
|
41
57
|
- lib/sbire/save_manager.rb
|