rist 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37cde15cbc2351d914b250f95813ac49250218a2
4
- data.tar.gz: e72797409c6a9970d18a428a6a0701f7faae5cc2
3
+ metadata.gz: 25fe8929aa49a303ac481c44c0cc54925abebffe
4
+ data.tar.gz: 3365df1dccaa8069c2f73e4d8b0b3140a2ef2530
5
5
  SHA512:
6
- metadata.gz: 625e3e9c074673589d9d8dc0c6af9e9403bc3d1711749749a00117740ec0924dfab0bbd32bdc142d1592f51e84bd63122e34a2e135bf158fff384a749c2aee35
7
- data.tar.gz: 73c5b2866f0d8cedcb791cd568fac5212de3549dc00472945b7bf14414d9a641c8599e112105915466d71f91331f9d8020644e6f1702ffb3024a89ccdae07be1
6
+ metadata.gz: 64e8773fd58f1343d29f56b6e95c48e541575ca94661655b78f925d79a9b2d6d04c10eda3ea8413354dfcc7c4031b5566c9ea17104e957734284d7caada34707
7
+ data.tar.gz: 1c9adabfca2fc14955edab3f231e7b263be06b8da87d192acfce6c534c5f11da798a114200df4cba35f9c5652806891a2f747b345d1097a5645b18a115226c02
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # Rist
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/rist.svg)](http://badge.fury.io/rb/rist)
4
+ [![Inline docs](http://inch-ci.org/github/siegfried/rist.svg?branch=master)](http://inch-ci.org/github/siegfried/rist)
5
+
3
6
  Rist (Ruby Intelligent System Tools) is a tool set to build Intelligent System.
4
7
 
5
8
  ## Installation
6
9
 
7
- *Warning: OpenAL and Pocketsphinx (> 0.8) are prerequisite.*
10
+ *Warning: Pocketsphinx (> 0.8) are prerequisite.*
8
11
 
9
12
  Add this line to your application's Gemfile:
10
13
 
@@ -24,7 +27,7 @@ Or install it yourself as:
24
27
 
25
28
  ### Transcriber
26
29
 
27
- Transcriber captures audio using OpenAL and turns the audio into text using [Pocketsphinx](http://cmusphinx.sourceforge.net/).
30
+ Transcriber transcribes audio into text using [Pocketsphinx](http://cmusphinx.sourceforge.net/).
28
31
 
29
32
  ```ruby
30
33
  transcriber = Rist::Transcriber.new logfn: "/dev/null"
@@ -1,22 +1,21 @@
1
1
  require 'mkmf'
2
2
 
3
- unless find_header 'AL/al.h', '/usr/local/include', '/usr/include'
4
- abort 'cannot find OpenAL, please install it.'
5
- end
6
- unless find_header 'AL/alc.h', '/usr/local/include', '/usr/include'
7
- abort 'cannot find OpenAL, please install it.'
8
- end
9
- unless find_header 'pocketsphinx/pocketsphinx_export.h', '/usr/local/include', '/opt/include', '/usr/include'
3
+ header_paths = ['/usr/local/include', '/opt/include', '/usr/include']
4
+
5
+ unless find_header 'pocketsphinx/pocketsphinx_export.h', *header_paths
10
6
  abort 'cannot find pocketsphinx, please install it.'
11
7
  end
12
- unless find_header 'sphinxbase/sphinxbase_export.h', '/usr/local/include', '/opt/include', '/usr/include'
8
+ unless find_header 'sphinxbase/sphinxbase_export.h', *header_paths
13
9
  abort 'cannot find sphinxbase, please install it.'
14
10
  end
15
11
  find_header 'pocketsphinx_export.h', '/usr/local/include/pocketsphinx', '/opt/include/pocketsphinx', '/usr/include/pocketsphinx'
16
12
  find_header 'sphinxbase_export.h', '/usr/local/include/sphinxbase', '/opt/include/sphinxbase', '/usr/include/sphinxbase'
17
13
 
18
- find_library 'pocketsphinx', 'ps_init', '/usr/local/lib', '/opt/lib', '/usr/lib'
19
- find_library 'sphinxbase', 'cmd_ln_init', '/usr/local/lib', '/opt/lib', '/usr/lib'
20
- find_library 'openal', 'alcCaptureOpenDevice'
14
+ lib_paths = ['/usr/local/lib', '/opt/lib', '/usr/lib']
15
+
16
+ find_library 'pocketsphinx', 'ps_init', *lib_paths
17
+ find_library 'sphinxbase', 'cmd_ln_init', *lib_paths
18
+ find_library 'sphinxad', 'ad_open_dev', *lib_paths
21
19
 
20
+ create_header
22
21
  create_makefile 'transcriber/transcriber'
@@ -1,7 +1,6 @@
1
1
  #include <ruby.h>
2
- #include <AL/al.h>
3
- #include <AL/alc.h>
4
2
  #include <pocketsphinx.h>
3
+ #include <sphinxbase/ad.h>
5
4
 
6
5
  static const arg_t cont_args_def[] = {
7
6
  POCKETSPHINX_OPTIONS,
@@ -21,7 +20,8 @@ static VALUE rb_mRist,
21
20
  rb_cTranscriber;
22
21
 
23
22
  static void transcriber_deallocate(Transcriber * transcriber) {
24
- ps_free(transcriber -> decoder);
23
+ if (transcriber -> decoder)
24
+ ps_free(transcriber -> decoder);
25
25
  xfree(transcriber);
26
26
  }
27
27
 
@@ -57,23 +57,11 @@ static VALUE transcriber_initialize_pocketsphinx(VALUE self, VALUE arguments) {
57
57
  return self;
58
58
  }
59
59
 
60
- static void close_raise(ALCdevice * device, VALUE error, const char * message) {
61
- alcCaptureCloseDevice(device);
60
+ static void close_and_raise(ad_rec_t * ad, VALUE error, const char * message) {
61
+ ad_close(ad);
62
62
  rb_raise(error, "%s\n", message);
63
63
  }
64
64
 
65
- static int32 al_read(ALCdevice * device, int16 * buffer, int32 max) {
66
- ALCint number;
67
-
68
- alcGetIntegerv(device, ALC_CAPTURE_SAMPLES, sizeof(number), &number);
69
- if (number >= 0) {
70
- number = (number < max ? number : max);
71
- alcCaptureSamples(device, buffer, number);
72
- }
73
-
74
- return number;
75
- }
76
-
77
65
  /* Transcribe speech continuously.
78
66
  *
79
67
  * for block { |utterance| ... }
@@ -81,46 +69,45 @@ static int32 al_read(ALCdevice * device, int16 * buffer, int32 max) {
81
69
  *
82
70
  * @yieldparam [String] utterance the utterance transcribed
83
71
  */
84
- static VALUE transcriber_transcribe(VALUE self)
85
- {
86
- ALCdevice * device;
87
- ALCuint frequency;
72
+ static VALUE transcriber_transcribe(VALUE self) {
88
73
  Transcriber * transcriber;
89
- cmd_ln_t *config;
90
- const char * hyp;
91
- const char * uttid;
74
+ ad_rec_t * ad;
92
75
  int16 adbuf[4096];
93
76
  int32 k;
94
- ps_decoder_t * ps;
95
77
  uint8 utt_started, in_speech;
78
+ char const * hyp;
79
+ char const * uttid;
80
+ cmd_ln_t * config;
81
+ ps_decoder_t * ps;
96
82
 
97
83
  Data_Get_Struct(self, Transcriber, transcriber);
98
84
  ps = transcriber -> decoder;
99
85
  config = ps_get_config(ps);
100
- frequency = cmd_ln_float32_r(config, "-samprate");
101
86
 
102
- device = alcCaptureOpenDevice(NULL, frequency, AL_FORMAT_MONO16, frequency * 10);
103
- if (device == NULL)
104
- rb_raise(rb_eRuntimeError, "failed to open audio device");
105
- alcCaptureStart(device);
87
+ if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"),
88
+ (int) cmd_ln_float32_r(config,
89
+ "-samprate"))) == NULL)
90
+ close_and_raise(ad, rb_eRuntimeError, "failed to open audio device");
91
+ if (ad_start_rec(ad) < 0)
92
+ close_and_raise(ad, rb_eRuntimeError, "failed to start recording");
106
93
 
107
94
  if (ps_start_utt(ps, NULL) < 0)
108
- close_raise(device, rb_eRuntimeError, "failed to start utterance");
95
+ close_and_raise(ad, rb_eRuntimeError, "failed to start utterance");
109
96
  utt_started = FALSE;
110
97
 
111
- /* Indicate listening for next utterance */
112
98
  for (;;) {
113
- if ((k = al_read(device, adbuf, 4096)) < 0)
114
- close_raise(device, rb_eRuntimeError, "failed to read audio");
99
+ if ((k = ad_read(ad, adbuf, 4096)) < 0)
100
+ close_and_raise(ad, rb_eRuntimeError, "failed to read audio");
115
101
  rb_funcall(self, rb_intern("sleep"), 1, rb_float_new(0.1));
102
+
116
103
  ps_process_raw(ps, adbuf, k, FALSE, FALSE);
117
104
  in_speech = ps_get_in_speech(ps);
118
105
  if (in_speech && !utt_started) {
119
106
  utt_started = TRUE;
120
107
  }
121
108
  if (!in_speech && utt_started) {
122
- //speech -> silence transition,
123
- //time to start new utterance
109
+ // speech -> silence transition,
110
+ // time to start new utterance
124
111
  ps_end_utt(ps);
125
112
  hyp = ps_get_hyp(ps, NULL, &uttid);
126
113
 
@@ -128,12 +115,11 @@ static VALUE transcriber_transcribe(VALUE self)
128
115
  rb_yield(rb_str_new2(hyp));
129
116
 
130
117
  if (ps_start_utt(ps, NULL) < 0)
131
- close_raise(device, rb_eRuntimeError, "failed to start utterance");
132
- /* Indicate listening for next utterance */
118
+ close_and_raise(ad, rb_eRuntimeError, "failed to start utterance");
133
119
  utt_started = FALSE;
134
120
  }
135
121
  }
136
- alcCaptureCloseDevice(device);
122
+ ad_close(ad);
137
123
  }
138
124
 
139
125
  void Init_transcriber() {
data/lib/rist/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rist
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhi-Qiang Lei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-20 00:00:00.000000000 Z
11
+ date: 2014-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler