sbire 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 584201d6ad6c79033ac7fd2531c95198d2e1dea4
4
- data.tar.gz: ef3dd012fcef79e09cd29dda6fa502297290f75e
3
+ metadata.gz: 45e5f155d99a6a4463375d5a99e1c2ccb2dd68b3
4
+ data.tar.gz: 790ce32c63fe7fe79036bc06cd1f47d892fec57e
5
5
  SHA512:
6
- metadata.gz: 7b73366ac9da504c1177c4ce2938bc4c6e7a162582bf1828b4bc9d7d5aeed985ef7504fad019f15cbe967ef441f85f8150e03b9d641f185d8ef1cac059e62b59
7
- data.tar.gz: 4e7df1d3741837d0436ff9c6c71670d29a236d116c652a18b3f2eed70d24df73b7136709daa0063324c7cf0b26d712ff94fc82e298d6fd67dbe7f3498115b3ea
6
+ metadata.gz: e34a6dc1a39b55034e9134e9733b362565e60f52ab6ba7152c2f5ffd27d30a6bd79a96bb5b2bbce3e0ac82b0b804cf4f586927def1a13c0a82bc434b07449516
7
+ data.tar.gz: 1b0a5f9006a2e879e2df5a1f3b451e14dec9ca169932256b0f3fb42e9a694714f256fbb77f31fcfa0231f0901ae80299b306fb4223f57599540c87b5d18652d1
data/README.md CHANGED
@@ -28,7 +28,7 @@ To write a text file :
28
28
  - Type `sbire start`
29
29
  - Say what you want ("This project rocks" for example)
30
30
  - Type `sbire save`
31
- - A file will be created in `~\.sbire\sbire.txt`
31
+ - A file will be created in `~\.sbire\text`
32
32
 
33
33
  ## Configuration
34
34
 
@@ -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
- if File.exist?(filename(index + 1))
33
- hypotheses = send_to_google(filename(index))
34
- block.call(hypotheses)
35
- index += 1
36
-
37
- stop = true if ENV["mode"] == "test"
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
@@ -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
- unless hypotheses.first.empty?
12
- command = find(hypotheses)
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 :hypotheses
2
+ attr_accessor :last_index, :max_index
3
3
 
4
- def initialize(hypotheses)
5
- @hypotheses = hypotheses
4
+ def initialize
5
+ @last_index = 0
6
+ @max_index = 0
6
7
  end
7
8
 
8
- def save
9
- File.open(SbireConfig.text_file, 'w') {|file| file.write(hypotheses.first)}
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 { |result| command_manager.execute(result) }
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
- FileUtils.rm(SbireConfig.text_file)
46
- audio_converter.start do |result|
47
- File.open(SbireConfig.text_file, 'ab+') {|f| f.write(result.first + " ") }
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
- def self.config_path
5
- "#{base_directory}/config.yml"
6
- end
4
+ def self.config_path
5
+ "#{base_directory}/config.yml"
6
+ end
7
7
 
8
- def self.base_directory
9
- "/home/dougui/.sbire"
10
- end
8
+ def self.base_directory
9
+ "/home/dougui/.sbire"
10
+ end
11
11
 
12
- def self.tmp_directory
13
- "/tmp"
14
- end
12
+ def self.lang
13
+ config["lang"] ||= "en-US"
14
+ end
15
15
 
16
- def self.lang
17
- config["lang"] ||= "en-US"
18
- end
16
+ def self.out_path
17
+ config["out_path"] ||= "#{base_directory}/out/"
18
+ end
19
19
 
20
- def self.out_path
21
- config["out_path"] ||= "#{base_directory}/out/"
22
- end
20
+ def self.out_file
21
+ config["out_file"] ||= "#{out_path}.audiofile"
22
+ end
23
23
 
24
- def self.out_file
25
- config["out_file"] ||= "#{out_path}.audiofile"
26
- end
24
+ def self.text_file
25
+ config["text_file"] ||= "#{base_directory}/text"
26
+ end
27
27
 
28
- def self.record_pid_file
29
- config["record_pid_file"] ||= "#{tmp_directory}/.recorder.pid"
30
- end
28
+ def self.command_path
29
+ config["command_path"] ||= "#{base_directory}/commands.yml"
30
+ end
31
31
 
32
- def self.converter_pid_file
33
- config["converter_pid_file"] ||= "#{tmp_directory}/.converter.pid"
34
- end
32
+ private
35
33
 
36
- def self.text_file
37
- config["text_file"] ||= "#{base_directory}/text"
38
- end
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
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-06 00:00:00.000000000 Z
11
+ date: 2013-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client