rist 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/.rspec +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/ext/transcriber/extconf.rb +22 -0
- data/ext/transcriber/transcriber.c +145 -0
- data/lib/rist/transcriber.rb +11 -0
- data/lib/rist/version.rb +3 -0
- data/lib/rist.rb +6 -0
- data/rist.gemspec +28 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 37cde15cbc2351d914b250f95813ac49250218a2
|
4
|
+
data.tar.gz: e72797409c6a9970d18a428a6a0701f7faae5cc2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 625e3e9c074673589d9d8dc0c6af9e9403bc3d1711749749a00117740ec0924dfab0bbd32bdc142d1592f51e84bd63122e34a2e135bf158fff384a749c2aee35
|
7
|
+
data.tar.gz: 73c5b2866f0d8cedcb791cd568fac5212de3549dc00472945b7bf14414d9a641c8599e112105915466d71f91331f9d8020644e6f1702ffb3024a89ccdae07be1
|
data/.rspec
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Zhi-Qiang Lei
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Rist
|
2
|
+
|
3
|
+
Rist (Ruby Intelligent System Tools) is a tool set to build Intelligent System.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
*Warning: OpenAL and Pocketsphinx (> 0.8) are prerequisite.*
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rist'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rist
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Transcriber
|
26
|
+
|
27
|
+
Transcriber captures audio using OpenAL and turns the audio into text using [Pocketsphinx](http://cmusphinx.sourceforge.net/).
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
transcriber = Rist::Transcriber.new logfn: "/dev/null"
|
31
|
+
|
32
|
+
transcriber.transcribe do |utterance|
|
33
|
+
puts utterance
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( https://github.com/siegfried/rist/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'mkmf'
|
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'
|
10
|
+
abort 'cannot find pocketsphinx, please install it.'
|
11
|
+
end
|
12
|
+
unless find_header 'sphinxbase/sphinxbase_export.h', '/usr/local/include', '/opt/include', '/usr/include'
|
13
|
+
abort 'cannot find sphinxbase, please install it.'
|
14
|
+
end
|
15
|
+
find_header 'pocketsphinx_export.h', '/usr/local/include/pocketsphinx', '/opt/include/pocketsphinx', '/usr/include/pocketsphinx'
|
16
|
+
find_header 'sphinxbase_export.h', '/usr/local/include/sphinxbase', '/opt/include/sphinxbase', '/usr/include/sphinxbase'
|
17
|
+
|
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'
|
21
|
+
|
22
|
+
create_makefile 'transcriber/transcriber'
|
@@ -0,0 +1,145 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <AL/al.h>
|
3
|
+
#include <AL/alc.h>
|
4
|
+
#include <pocketsphinx.h>
|
5
|
+
|
6
|
+
static const arg_t cont_args_def[] = {
|
7
|
+
POCKETSPHINX_OPTIONS,
|
8
|
+
/* Argument file. */
|
9
|
+
{"-argfile",
|
10
|
+
ARG_STRING,
|
11
|
+
NULL,
|
12
|
+
"Argument file giving extra arguments."},
|
13
|
+
CMDLN_EMPTY_OPTION
|
14
|
+
};
|
15
|
+
|
16
|
+
typedef struct {
|
17
|
+
ps_decoder_t * decoder;
|
18
|
+
} Transcriber;
|
19
|
+
|
20
|
+
static VALUE rb_mRist,
|
21
|
+
rb_cTranscriber;
|
22
|
+
|
23
|
+
static void transcriber_deallocate(Transcriber * transcriber) {
|
24
|
+
ps_free(transcriber -> decoder);
|
25
|
+
xfree(transcriber);
|
26
|
+
}
|
27
|
+
|
28
|
+
static VALUE transcriber_allocate(VALUE self) {
|
29
|
+
Transcriber * transcriber;
|
30
|
+
return Data_Make_Struct(self, Transcriber, 0, transcriber_deallocate, transcriber);
|
31
|
+
}
|
32
|
+
|
33
|
+
static VALUE transcriber_initialize_pocketsphinx(VALUE self, VALUE arguments) {
|
34
|
+
Transcriber * transcriber;
|
35
|
+
char ** argv;
|
36
|
+
cmd_ln_t * config;
|
37
|
+
int i, argc;
|
38
|
+
|
39
|
+
argc = RARRAY_LEN(arguments);
|
40
|
+
argv = ALLOC_N(char *, argc);
|
41
|
+
for (i = 0; i < argc; i++) {
|
42
|
+
argv[i] = RSTRING_PTR(rb_ary_entry(arguments, i));
|
43
|
+
}
|
44
|
+
config = cmd_ln_parse_r(NULL, cont_args_def, argc, argv, TRUE);
|
45
|
+
xfree(argv);
|
46
|
+
|
47
|
+
if (config == NULL)
|
48
|
+
rb_raise(rb_eArgError, "bad configuration");
|
49
|
+
ps_default_search_args(config);
|
50
|
+
|
51
|
+
Data_Get_Struct(self, Transcriber, transcriber);
|
52
|
+
if ((transcriber -> decoder = ps_init(config)) == NULL) {
|
53
|
+
cmd_ln_free_r(config);
|
54
|
+
rb_raise(rb_eRuntimeError, "failed to initialize pocketsphinx");
|
55
|
+
}
|
56
|
+
|
57
|
+
return self;
|
58
|
+
}
|
59
|
+
|
60
|
+
static void close_raise(ALCdevice * device, VALUE error, const char * message) {
|
61
|
+
alcCaptureCloseDevice(device);
|
62
|
+
rb_raise(error, "%s\n", message);
|
63
|
+
}
|
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
|
+
/* Transcribe speech continuously.
|
78
|
+
*
|
79
|
+
* for block { |utterance| ... }
|
80
|
+
* @yield [utterance] do whatever you want to do with the utterance transcribed
|
81
|
+
*
|
82
|
+
* @yieldparam [String] utterance the utterance transcribed
|
83
|
+
*/
|
84
|
+
static VALUE transcriber_transcribe(VALUE self)
|
85
|
+
{
|
86
|
+
ALCdevice * device;
|
87
|
+
ALCuint frequency;
|
88
|
+
Transcriber * transcriber;
|
89
|
+
cmd_ln_t *config;
|
90
|
+
const char * hyp;
|
91
|
+
const char * uttid;
|
92
|
+
int16 adbuf[4096];
|
93
|
+
int32 k;
|
94
|
+
ps_decoder_t * ps;
|
95
|
+
uint8 utt_started, in_speech;
|
96
|
+
|
97
|
+
Data_Get_Struct(self, Transcriber, transcriber);
|
98
|
+
ps = transcriber -> decoder;
|
99
|
+
config = ps_get_config(ps);
|
100
|
+
frequency = cmd_ln_float32_r(config, "-samprate");
|
101
|
+
|
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);
|
106
|
+
|
107
|
+
if (ps_start_utt(ps, NULL) < 0)
|
108
|
+
close_raise(device, rb_eRuntimeError, "failed to start utterance");
|
109
|
+
utt_started = FALSE;
|
110
|
+
|
111
|
+
/* Indicate listening for next utterance */
|
112
|
+
for (;;) {
|
113
|
+
if ((k = al_read(device, adbuf, 4096)) < 0)
|
114
|
+
close_raise(device, rb_eRuntimeError, "failed to read audio");
|
115
|
+
rb_funcall(self, rb_intern("sleep"), 1, rb_float_new(0.1));
|
116
|
+
ps_process_raw(ps, adbuf, k, FALSE, FALSE);
|
117
|
+
in_speech = ps_get_in_speech(ps);
|
118
|
+
if (in_speech && !utt_started) {
|
119
|
+
utt_started = TRUE;
|
120
|
+
}
|
121
|
+
if (!in_speech && utt_started) {
|
122
|
+
//speech -> silence transition,
|
123
|
+
//time to start new utterance
|
124
|
+
ps_end_utt(ps);
|
125
|
+
hyp = ps_get_hyp(ps, NULL, &uttid);
|
126
|
+
|
127
|
+
// yield result
|
128
|
+
rb_yield(rb_str_new2(hyp));
|
129
|
+
|
130
|
+
if (ps_start_utt(ps, NULL) < 0)
|
131
|
+
close_raise(device, rb_eRuntimeError, "failed to start utterance");
|
132
|
+
/* Indicate listening for next utterance */
|
133
|
+
utt_started = FALSE;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
alcCaptureCloseDevice(device);
|
137
|
+
}
|
138
|
+
|
139
|
+
void Init_transcriber() {
|
140
|
+
rb_mRist = rb_define_module("Rist");
|
141
|
+
rb_cTranscriber = rb_define_class_under(rb_mRist, "Transcriber", rb_cObject);
|
142
|
+
rb_define_alloc_func(rb_cTranscriber, transcriber_allocate);
|
143
|
+
rb_define_private_method(rb_cTranscriber, "initialize_pocketsphinx", transcriber_initialize_pocketsphinx, 1);
|
144
|
+
rb_define_method(rb_cTranscriber, "transcribe", transcriber_transcribe, 0);
|
145
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'transcriber/transcriber'
|
2
|
+
|
3
|
+
class Rist::Transcriber
|
4
|
+
|
5
|
+
# @param [Hash] options the options to initialize a transcriber identical to Pocketsphinx arguments
|
6
|
+
def initialize(options = {})
|
7
|
+
arguments = options.inject([]) { |result, (key, value)| result + ["-#{key.to_s}", value.to_s] }
|
8
|
+
initialize_pocketsphinx(arguments);
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
data/lib/rist/version.rb
ADDED
data/lib/rist.rb
ADDED
data/rist.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rist/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rist"
|
8
|
+
spec.version = Rist::VERSION
|
9
|
+
spec.authors = ["Zhi-Qiang Lei"]
|
10
|
+
spec.email = ["zhiqiang.lei@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby Intelligent System Tools}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0") - Dir['{examples,spec}/**/*'] - %w{.gitignore Gemfile Rakefile}
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.extensions = %w{ext/transcriber/extconf.rb}
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
25
|
+
spec.add_development_dependency "factory_girl", "~> 4.0"
|
26
|
+
spec.add_development_dependency "rake-compiler"
|
27
|
+
spec.add_development_dependency "coveralls"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zhi-Qiang Lei
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: factory_girl
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake-compiler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: ''
|
98
|
+
email:
|
99
|
+
- zhiqiang.lei@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions:
|
102
|
+
- ext/transcriber/extconf.rb
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".rspec"
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- ext/transcriber/extconf.rb
|
109
|
+
- ext/transcriber/transcriber.c
|
110
|
+
- lib/rist.rb
|
111
|
+
- lib/rist/transcriber.rb
|
112
|
+
- lib/rist/version.rb
|
113
|
+
- rist.gemspec
|
114
|
+
homepage: ''
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.2.2
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Ruby Intelligent System Tools
|
138
|
+
test_files: []
|