sbire 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +60 -0
- data/bin/sbire +4 -0
- data/lib/audio_converter.rb +34 -0
- data/lib/audio_recorder.rb +25 -0
- data/lib/command_manager.rb +24 -0
- data/lib/notifier.rb +5 -0
- data/lib/save_manager.rb +11 -0
- data/lib/sbire.rb +73 -0
- data/lib/sbire_config.rb +18 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eb41a603c08dadb787fb09ab565377f095284b03
|
4
|
+
data.tar.gz: d5cc30071265b6028a0d96b7a641340951229623
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd3a2e5d0f07d31b0a64d1d3118a73def68956dee981c8659e30619b7e258b33010d271ec9aa357075f8720595968edff0ab7a886bd33bd8ed095fa21c80dd3b
|
7
|
+
data.tar.gz: d2b5985816ee42e352eee31363caa794ee2f2d2ebd86be588b71558e56d3d4fec2512433e5bb2af9025c9831d3f7b2fd7e9925961351cfc178d48c8b86465e8d
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Sbire
|
2
|
+
|
3
|
+
In french, a "Sbire" is a henchman. It's the guy who do what you say. Sbire is program which is capable to listen what you said and execute the command associated.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
In Ubuntu :
|
8
|
+
|
9
|
+
sudo apt-get install sox notify-osd ruby1.9.1
|
10
|
+
gem install sbire
|
11
|
+
mkdir ~\.sbire\
|
12
|
+
|
13
|
+
In other systems : In the ToDo list
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
To execute a command :
|
18
|
+
|
19
|
+
- Open a terminal
|
20
|
+
- Type `sbire start`
|
21
|
+
- Say the command you want ("Firefox" for example)
|
22
|
+
- Type `sbire stop`
|
23
|
+
- The command will be executed
|
24
|
+
|
25
|
+
To write a text file :
|
26
|
+
|
27
|
+
- Open a terminal
|
28
|
+
- Type `sbire start`
|
29
|
+
- Say what you want ("This project rocks" for example)
|
30
|
+
- Type `sbire save`
|
31
|
+
- A file will be created in `~\.sbire\sbire.txt`
|
32
|
+
|
33
|
+
## Configuration
|
34
|
+
|
35
|
+
By default, the language is en-US. You can change it by adding a file `~\.sbire\config.yml` and put `lang: fr-FR` in it.
|
36
|
+
|
37
|
+
## Bind phrase and commands
|
38
|
+
|
39
|
+
You can bind more complexe phrases with commands by adding a file`~\.sbire\commands.yml` and put in it something like this :
|
40
|
+
|
41
|
+
"chromium-browser": ["open chrome", "chrome"]
|
42
|
+
"skype": "open skype"
|
43
|
+
|
44
|
+
## Make a shortcut
|
45
|
+
|
46
|
+
For an obscure reason, Ubuntu does not execute ruby commands binded with a keyboard shortcut. You must to install [xbindkeys](http://doc.ubuntu-fr.org/xbindkeys) to make it working.
|
47
|
+
|
48
|
+
## ToDo list
|
49
|
+
|
50
|
+
- Make it work with leap motion
|
51
|
+
- Make it cross-platform
|
52
|
+
- Enable streaming to write texts
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/bin/sbire
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'curb'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class AudioConverter
|
5
|
+
attr_accessor :file
|
6
|
+
|
7
|
+
def initialize(file_path)
|
8
|
+
@file = File.read(file_path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def results
|
12
|
+
http_request.http_post
|
13
|
+
read_response(http_request)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def read_response(http_request)
|
18
|
+
data = JSON.parse(http_request.body)
|
19
|
+
data['hypotheses'].map {|ut| [ut['utterance'], ut['confidence']] }.first
|
20
|
+
end
|
21
|
+
|
22
|
+
def http_request
|
23
|
+
return @http_request if @http_request
|
24
|
+
http_request = Curl::Easy.new(url)
|
25
|
+
http_request.headers['Content-Type'] = "audio/x-flac; rate=22050"
|
26
|
+
http_request.post_body = "Content=#{file}"
|
27
|
+
@http_request = http_request
|
28
|
+
end
|
29
|
+
|
30
|
+
def url
|
31
|
+
lang = Sbire::CONFIG.lang
|
32
|
+
"https://www.google.com/speech-api/v1/recognize?lang=#{lang}"
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class AudioRecorder
|
2
|
+
attr_accessor :path
|
3
|
+
def initialize(path)
|
4
|
+
@path = path
|
5
|
+
end
|
6
|
+
|
7
|
+
def start
|
8
|
+
pid = record_audio
|
9
|
+
write_pid(pid)
|
10
|
+
end
|
11
|
+
|
12
|
+
def stop
|
13
|
+
pid = File.readlines(Sbire::PID_FILE)[0]
|
14
|
+
system("kill #{pid}")
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def write_pid(pid)
|
19
|
+
File.open(Sbire::PID_FILE, 'w') {|file| file.write(pid)}
|
20
|
+
end
|
21
|
+
|
22
|
+
def record_audio
|
23
|
+
fork { exec "sox -t alsa -r 22050 default #{path} -q" }
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class CommandManager
|
4
|
+
attr_accessor :commands
|
5
|
+
|
6
|
+
def initialize(path)
|
7
|
+
@commands = YAML.load_file(path) if File.exist?(path)
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute(hypotheses)
|
11
|
+
command = find(hypotheses)
|
12
|
+
system("#{command} &")
|
13
|
+
return command
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def find(hypotheses)
|
18
|
+
hypothese = hypotheses.first.downcase
|
19
|
+
if commands
|
20
|
+
commands.each_pair {|key, value| return key if value.include?(hypothese)}
|
21
|
+
end
|
22
|
+
return hypothese
|
23
|
+
end
|
24
|
+
end
|
data/lib/notifier.rb
ADDED
data/lib/save_manager.rb
ADDED
data/lib/sbire.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require_relative 'notifier'
|
2
|
+
require_relative 'audio_converter'
|
3
|
+
require_relative 'command_manager'
|
4
|
+
require_relative 'audio_recorder'
|
5
|
+
require_relative 'save_manager'
|
6
|
+
require_relative 'sbire_config'
|
7
|
+
require 'rest_client'
|
8
|
+
|
9
|
+
class Sbire
|
10
|
+
|
11
|
+
BASE_DIRECTORY = "#{Dir.home}/.sbire"
|
12
|
+
OUT_FILE = "#{BASE_DIRECTORY}/.audiofile.flac"
|
13
|
+
PID_FILE = "#{BASE_DIRECTORY}/.pid"
|
14
|
+
TEXT_FILE = "#{BASE_DIRECTORY}/sbire.txt"
|
15
|
+
CONFIG_PATH = "#{BASE_DIRECTORY}/config.yml"
|
16
|
+
COMMAND_PATH = "#{BASE_DIRECTORY}/commands.yml"
|
17
|
+
CONFIG = SbireConfig.new(CONFIG_PATH)
|
18
|
+
|
19
|
+
attr_accessor :command
|
20
|
+
|
21
|
+
def self.run(argv)
|
22
|
+
self.new(argv).call
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(argv)
|
26
|
+
@command = argv.first
|
27
|
+
end
|
28
|
+
|
29
|
+
def call
|
30
|
+
if command == "start" || command == "stop" || command == "save"
|
31
|
+
send(command)
|
32
|
+
else
|
33
|
+
show("Command not found")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def start
|
39
|
+
audio_recorder.start
|
40
|
+
show("Sbire is listening your voice")
|
41
|
+
end
|
42
|
+
|
43
|
+
def stop
|
44
|
+
show("Sbire is analyzing your voice")
|
45
|
+
audio_recorder.stop
|
46
|
+
hypotheses = audio_converter.results
|
47
|
+
show(command_manager.execute(hypotheses))
|
48
|
+
end
|
49
|
+
|
50
|
+
def save
|
51
|
+
show("Sbire is writing what you said")
|
52
|
+
audio_recorder.stop
|
53
|
+
hypotheses = audio_converter.results
|
54
|
+
SaveManager.new(hypotheses).save
|
55
|
+
show("Sbire has ended to write your voice")
|
56
|
+
end
|
57
|
+
|
58
|
+
def command_manager
|
59
|
+
@command_manager ||= CommandManager.new(COMMAND_PATH)
|
60
|
+
end
|
61
|
+
|
62
|
+
def audio_recorder
|
63
|
+
@audio_recorder ||= AudioRecorder.new(OUT_FILE)
|
64
|
+
end
|
65
|
+
|
66
|
+
def audio_converter
|
67
|
+
@audio_converter ||= AudioConverter.new(OUT_FILE)
|
68
|
+
end
|
69
|
+
|
70
|
+
def show(message)
|
71
|
+
Notifier.call(message)
|
72
|
+
end
|
73
|
+
end
|
data/lib/sbire_config.rb
ADDED
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sbire
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guirec Corbel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Sbire is a command line tool that recognize your voice and execute commands
|
14
|
+
linked
|
15
|
+
email: guirec.corbel@gmail.com
|
16
|
+
executables:
|
17
|
+
- sbire
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/sbire
|
22
|
+
- lib/audio_converter.rb
|
23
|
+
- lib/audio_recorder.rb
|
24
|
+
- lib/sbire.rb
|
25
|
+
- lib/command_manager.rb
|
26
|
+
- lib/save_manager.rb
|
27
|
+
- lib/sbire_config.rb
|
28
|
+
- lib/notifier.rb
|
29
|
+
- README.md
|
30
|
+
homepage: https://github.com/GCorbel/sbire
|
31
|
+
licenses: []
|
32
|
+
metadata: {}
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 2.0.3
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: The henchman who do what you say
|
53
|
+
test_files: []
|