sbire 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/audio_converter.rb +8 -9
- data/lib/command_manager.rb +4 -3
- data/lib/save_manager.rb +28 -5
- data/lib/sbire.rb +14 -4
- data/lib/sbire_config.rb +26 -38
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45e5f155d99a6a4463375d5a99e1c2ccb2dd68b3
|
4
|
+
data.tar.gz: 790ce32c63fe7fe79036bc06cd1f47d892fec57e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e34a6dc1a39b55034e9134e9733b362565e60f52ab6ba7152c2f5ffd27d30a6bd79a96bb5b2bbce3e0ac82b0b804cf4f586927def1a13c0a82bc434b07449516
|
7
|
+
data.tar.gz: 1b0a5f9006a2e879e2df5a1f3b451e14dec9ca169932256b0f3fb42e9a694714f256fbb77f31fcfa0231f0901ae80299b306fb4223f57599540c87b5d18652d1
|
data/README.md
CHANGED
data/lib/audio_converter.rb
CHANGED
@@ -19,22 +19,21 @@ class AudioConverter
|
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
|
-
def write_pid(pid)
|
23
|
-
File.open(SbireConfig.converter_pid_file, 'w') {|file| file.write(pid)}
|
24
|
-
end
|
25
22
|
|
26
23
|
def listen_audio(block)
|
27
24
|
fork do
|
28
25
|
index = 1
|
29
26
|
stop = false
|
27
|
+
hypotheses = []
|
30
28
|
|
31
29
|
while stop == false
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
Thread.new(index) do |i|
|
31
|
+
if File.exist?(filename(i + 1))
|
32
|
+
index += 1
|
33
|
+
hypotheses[i - 1] = send_to_google(filename(i))
|
34
|
+
block.call(hypotheses, i - 1)
|
35
|
+
stop = true if ENV["mode"] == "test"
|
36
|
+
end
|
38
37
|
end
|
39
38
|
sleep 0.1
|
40
39
|
end
|
data/lib/command_manager.rb
CHANGED
@@ -7,9 +7,10 @@ class CommandManager
|
|
7
7
|
@commands = YAML.load_file(path) if File.exist?(path)
|
8
8
|
end
|
9
9
|
|
10
|
-
def execute(hypotheses)
|
11
|
-
|
12
|
-
|
10
|
+
def execute(hypotheses, index)
|
11
|
+
current_hypothese = hypotheses[index]
|
12
|
+
unless current_hypothese.first.empty?
|
13
|
+
command = find(current_hypothese)
|
13
14
|
system("#{command} &")
|
14
15
|
return command
|
15
16
|
end
|
data/lib/save_manager.rb
CHANGED
@@ -1,11 +1,34 @@
|
|
1
1
|
class SaveManager
|
2
|
-
attr_accessor :
|
2
|
+
attr_accessor :last_index, :max_index
|
3
3
|
|
4
|
-
def initialize
|
5
|
-
@
|
4
|
+
def initialize
|
5
|
+
@last_index = 0
|
6
|
+
@max_index = 0
|
6
7
|
end
|
7
8
|
|
8
|
-
def save
|
9
|
-
|
9
|
+
def save(hypotheses, index)
|
10
|
+
compute_max_index(index)
|
11
|
+
hypotheses = current_hypotheses(hypotheses)
|
12
|
+
unless hypotheses.include?(nil)
|
13
|
+
append_to_file(hypotheses)
|
14
|
+
@last_index = index + 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def compute_max_index(index)
|
21
|
+
@max_index = index if @max_index < index
|
22
|
+
end
|
23
|
+
|
24
|
+
def current_hypotheses(hypotheses)
|
25
|
+
hypotheses.map { |hypothese| hypothese.first }[last_index..max_index]
|
26
|
+
end
|
27
|
+
|
28
|
+
def append_to_file(hypotheses)
|
29
|
+
text = hypotheses.join(" ") + " "
|
30
|
+
if text != " "
|
31
|
+
File.open(SbireConfig.text_file, 'ab+') {|file| file.write(text)}
|
32
|
+
end
|
10
33
|
end
|
11
34
|
end
|
data/lib/sbire.rb
CHANGED
@@ -31,7 +31,9 @@ class Sbire
|
|
31
31
|
def start
|
32
32
|
show("Sbire is listening your voice")
|
33
33
|
audio_recorder.start
|
34
|
-
audio_converter.start
|
34
|
+
audio_converter.start do |results, index|
|
35
|
+
command_manager.execute(results, index)
|
36
|
+
end
|
35
37
|
end
|
36
38
|
|
37
39
|
def stop
|
@@ -42,12 +44,16 @@ class Sbire
|
|
42
44
|
def save
|
43
45
|
show("Sbire is listening your voice")
|
44
46
|
audio_recorder.start
|
45
|
-
|
46
|
-
audio_converter.start do |
|
47
|
-
|
47
|
+
recreate_text_file
|
48
|
+
audio_converter.start do |results, index|
|
49
|
+
save_manager.save(results, index) if results
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
53
|
+
def recreate_text_file
|
54
|
+
File.write(SbireConfig.text_file, '')
|
55
|
+
end
|
56
|
+
|
51
57
|
def command_manager
|
52
58
|
@command_manager ||= CommandManager.new(SbireConfig.command_path)
|
53
59
|
end
|
@@ -60,6 +66,10 @@ class Sbire
|
|
60
66
|
@audio_converter ||= AudioConverter.new(pid_manager)
|
61
67
|
end
|
62
68
|
|
69
|
+
def save_manager
|
70
|
+
@save_manager ||= SaveManager.new
|
71
|
+
end
|
72
|
+
|
63
73
|
def show(message)
|
64
74
|
Notifier.call(message)
|
65
75
|
end
|
data/lib/sbire_config.rb
CHANGED
@@ -1,50 +1,38 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
class SbireConfig
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def self.config_path
|
5
|
+
"#{base_directory}/config.yml"
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def self.base_directory
|
9
|
+
"/home/dougui/.sbire"
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def self.lang
|
13
|
+
config["lang"] ||= "en-US"
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def self.out_path
|
17
|
+
config["out_path"] ||= "#{base_directory}/out/"
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
def self.out_file
|
21
|
+
config["out_file"] ||= "#{out_path}.audiofile"
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
def self.text_file
|
25
|
+
config["text_file"] ||= "#{base_directory}/text"
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
def self.command_path
|
29
|
+
config["command_path"] ||= "#{base_directory}/commands.yml"
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
config["converter_pid_file"] ||= "#{tmp_directory}/.converter.pid"
|
34
|
-
end
|
32
|
+
private
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
def self.command_path
|
41
|
-
config["command_path"] ||= "#{base_directory}/commands.yml"
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def self.config
|
47
|
-
return @config if @config
|
48
|
-
@config = YAML.load_file(config_path) || {}
|
49
|
-
end
|
34
|
+
def self.config
|
35
|
+
return @config if @config
|
36
|
+
@config = YAML.load_file(config_path) || {}
|
37
|
+
end
|
50
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.5
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|