annyang_rails 0.2.0
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 +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/annyang_rails.gemspec +23 -0
- data/app/assets/javascripts/annyang.js +181 -0
- data/lib/annyang_rails/version.rb +3 -0
- data/lib/annyang_rails.rb +8 -0
- metadata +94 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
ODY0NWUzZjVhZDkzNzE4NzU0ZWUxMGFkY2UwYzhkMGE3MGJmZGY0Zg==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
MzFjZjZiZmVlMGU5NzkwMDMyNzY5NWM5YmQ0YjNlOThlM2QyZjUxYw==
|
|
7
|
+
SHA512:
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
MjI5MmI3MWEyYTFiMTkzN2E0NTU2MDNiNDkzZWFmY2U2MWFhMjM2Y2M2ZWZj
|
|
10
|
+
ZjQ1NGVkMTg2NzA0M2ViYWQ5ZTRkZjA1NTlhNTZmYzhjNjA2ODAyNjA5YWE2
|
|
11
|
+
OWVlMWI0NzIzNjY0ZDkwY2ExMjRiOGE3ZTUxOTI1YjRjNjFkOTI=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
MjA2NWI5YTcwMDNhNDg0YTQ3MTQxMTU2NzM1YTFmYWU2ZmU0M2Q4YWNjMTE5
|
|
14
|
+
NmU1YmRiZDZhNzkzNGZmNDMyYzRhNGU2YWU4MDFlNTI2YTY1NmZjN2M2Yjcx
|
|
15
|
+
MTEyOWY0NjM4MjdhMGZmZWQ3ZGVkMjJiMjQ4NTEwZWJjYjhhMTQ=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Guy Israeli
|
|
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,48 @@
|
|
|
1
|
+
# AnnyangRails
|
|
2
|
+
|
|
3
|
+
Adds speech recoginition with annyang.js via asset pipeline for rails 3.1+
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'annyang_rails'
|
|
10
|
+
|
|
11
|
+
add to application.js manifest
|
|
12
|
+
|
|
13
|
+
//= require annyang
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install annyang_rails
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
<script type="text/javascript">
|
|
26
|
+
if (annyang) {
|
|
27
|
+
// Let's define a command.
|
|
28
|
+
var commands = {
|
|
29
|
+
'show tps report': function() { $('#tpsreport').show(); }
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Initialize annyang with our commands
|
|
33
|
+
annyang.init(commands);
|
|
34
|
+
|
|
35
|
+
// Start listening.
|
|
36
|
+
annyang.start();
|
|
37
|
+
}
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
see https://www.talater.com/annyang/ for more stuff
|
|
41
|
+
|
|
42
|
+
## Contributing
|
|
43
|
+
|
|
44
|
+
1. Fork it
|
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'annyang_rails/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "annyang_rails"
|
|
8
|
+
spec.version = AnnyangRails::VERSION
|
|
9
|
+
spec.authors = ["Guy Israeli"]
|
|
10
|
+
spec.description = %q{Quickly add speech recognition to your Rails 3.1+ app via asset pipeline!}
|
|
11
|
+
spec.summary = %q{uses annyang.js to add speech recognition to your rails app}
|
|
12
|
+
spec.homepage = "https://github.com/guyisra/annyang_rails"
|
|
13
|
+
spec.license = "MIT"
|
|
14
|
+
|
|
15
|
+
spec.files = `git ls-files`.split($/)
|
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
18
|
+
spec.require_paths = ["lib"]
|
|
19
|
+
|
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
21
|
+
spec.add_development_dependency "rake"
|
|
22
|
+
spec.add_dependency "railties", ">=3.1"
|
|
23
|
+
end
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/*! annyang - speech recognition in js
|
|
2
|
+
* version : 0.2.0
|
|
3
|
+
* author : Tal Ater @TalAter
|
|
4
|
+
* license : MIT
|
|
5
|
+
* https://www.TalAter.com/annyang/
|
|
6
|
+
* https://github.com/TalAter/annyang
|
|
7
|
+
*/
|
|
8
|
+
(function () {
|
|
9
|
+
"use strict";
|
|
10
|
+
|
|
11
|
+
var root = this;
|
|
12
|
+
var SpeechRecognition = root.webkitSpeechRecognition ||
|
|
13
|
+
root.mozSpeechRecognition ||
|
|
14
|
+
root.msSpeechRecognition ||
|
|
15
|
+
root.oSpeechRecognition ||
|
|
16
|
+
root.SpeechRecognition;
|
|
17
|
+
// Check browser support
|
|
18
|
+
if ( !SpeechRecognition ) {
|
|
19
|
+
root.annyang = null;
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var commandsList;
|
|
24
|
+
var recognition;
|
|
25
|
+
var lang = 'en-US';
|
|
26
|
+
var callbacks = { start: [], error: [], end: [], result: [], resultMatch: [], resultNoMatch: [] };
|
|
27
|
+
var autoRestart;
|
|
28
|
+
var debugState = false;
|
|
29
|
+
var debugStyle = 'font-weight: bold; color: #00f;';
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// The command matching code is a modified version of Backbone.Router by Jeremy Ashkenas, under the MIT license.
|
|
33
|
+
var optionalParam = /\s*\((.*?)\)\s*/g;
|
|
34
|
+
var optionalRegex = /(\(\?:[^)]+\))\?/g;
|
|
35
|
+
var namedParam = /(\(\?)?:\w+/g;
|
|
36
|
+
var splatParam = /\*\w+/g;
|
|
37
|
+
var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#]/g;
|
|
38
|
+
var commandToRegExp = function(command) {
|
|
39
|
+
command = command.replace(escapeRegExp, '\\$&')
|
|
40
|
+
.replace(optionalParam, '(?:$1)?')
|
|
41
|
+
.replace(namedParam, function(match, optional) {
|
|
42
|
+
return optional ? match : '([^\\s]+)';
|
|
43
|
+
})
|
|
44
|
+
.replace(splatParam, '(.*?)')
|
|
45
|
+
.replace(optionalRegex, '\\s*$1?\\s*');
|
|
46
|
+
return new RegExp('^' + command + '$', 'i');
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
var invokeCallbacks = function(callbacks) {
|
|
50
|
+
for (var j = 0, l = callbacks.length; j < l; j++) {
|
|
51
|
+
callbacks[j].apply(this);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
root.annyang = {
|
|
56
|
+
init: function(commands) {
|
|
57
|
+
|
|
58
|
+
// Abort previous instances of recognition already running
|
|
59
|
+
if (recognition && recognition.abort) {
|
|
60
|
+
recognition.abort();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// initiate
|
|
64
|
+
recognition = new SpeechRecognition();
|
|
65
|
+
|
|
66
|
+
recognition.maxAlternatives = 5;
|
|
67
|
+
recognition.continuous = true;
|
|
68
|
+
recognition.lang = lang;
|
|
69
|
+
|
|
70
|
+
recognition.onstart = function() { invokeCallbacks(callbacks.start); };
|
|
71
|
+
|
|
72
|
+
recognition.onerror = function() { invokeCallbacks(callbacks.error); };
|
|
73
|
+
|
|
74
|
+
recognition.onend = function() {
|
|
75
|
+
invokeCallbacks(callbacks.end);
|
|
76
|
+
if (autoRestart) {
|
|
77
|
+
root.annyang.start();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
recognition.onresult = function(event) {
|
|
82
|
+
invokeCallbacks(callbacks.result);
|
|
83
|
+
var results = event.results[event.resultIndex];
|
|
84
|
+
var commandText;
|
|
85
|
+
for (var i = 0; i<results.length; i++) {
|
|
86
|
+
commandText = results[i].transcript.trim();
|
|
87
|
+
if (debugState) {
|
|
88
|
+
root.console.log('Speech recognized: %c'+commandText, debugStyle);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (var j = 0, l = commandsList.length; j < l; j++) {
|
|
92
|
+
var result = commandsList[j].command.exec(commandText);
|
|
93
|
+
if (result) {
|
|
94
|
+
var parameters = result.slice(1);
|
|
95
|
+
if (debugState) {
|
|
96
|
+
root.console.log('command matched: %c'+commandsList[j].originalPhrase, debugStyle);
|
|
97
|
+
if (parameters.length) {
|
|
98
|
+
root.console.log('with parameters', parameters);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
commandsList[j].callback.apply(this, parameters);
|
|
102
|
+
invokeCallbacks(callbacks.resultMatch);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
invokeCallbacks(callbacks.resultNoMatch);
|
|
108
|
+
return false;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// build commands list
|
|
112
|
+
commandsList = [];
|
|
113
|
+
this.addCommands(commands);
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
start: function(options) {
|
|
117
|
+
options = options || {};
|
|
118
|
+
if (typeof options.autoRestart !== 'undefined') {
|
|
119
|
+
autoRestart = !!options.autoRestart;
|
|
120
|
+
} else {
|
|
121
|
+
autoRestart = true;
|
|
122
|
+
}
|
|
123
|
+
recognition.start();
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
abort: function() {
|
|
127
|
+
autoRestart = false;
|
|
128
|
+
recognition.abort();
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
debug: function(newState) {
|
|
132
|
+
if (arguments.length > 0) {
|
|
133
|
+
debugState = !!newState;
|
|
134
|
+
} else {
|
|
135
|
+
debugState = true;
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
setLanguage: function(language) {
|
|
140
|
+
lang = language;
|
|
141
|
+
if (recognition && recognition.abort) {
|
|
142
|
+
recognition.lang = language;
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
addCommands: function(commands) {
|
|
147
|
+
var cb,
|
|
148
|
+
command;
|
|
149
|
+
for (var phrase in commands) {
|
|
150
|
+
if (commands.hasOwnProperty(phrase)) {
|
|
151
|
+
cb = root[commands[phrase]] || commands[phrase];
|
|
152
|
+
if (typeof cb !== 'function') {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
//convert command to regex
|
|
156
|
+
command = commandToRegExp(phrase);
|
|
157
|
+
|
|
158
|
+
commandsList.push({ command: command, callback: cb, originalPhrase: phrase });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (debugState) {
|
|
162
|
+
root.console.log('Commands successfully loaded: %c'+commandsList.length, debugStyle);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Lets the user add a callback of one of 6 types: start, error, end, result, resultMatch, resultNoMatch
|
|
168
|
+
*/
|
|
169
|
+
addCallback: function(type, callback) {
|
|
170
|
+
if (callbacks[type] === void 0) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
var cb = root[callback] || callback;
|
|
174
|
+
if (typeof cb !== 'function') {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
callbacks[type].push(cb);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
}).call(this);
|
metadata
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: annyang_rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Guy Israeli
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-09-16 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.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ! '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ! '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: railties
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ! '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.1'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.1'
|
|
55
|
+
description: Quickly add speech recognition to your Rails 3.1+ app via asset pipeline!
|
|
56
|
+
email:
|
|
57
|
+
executables: []
|
|
58
|
+
extensions: []
|
|
59
|
+
extra_rdoc_files: []
|
|
60
|
+
files:
|
|
61
|
+
- .gitignore
|
|
62
|
+
- Gemfile
|
|
63
|
+
- LICENSE.txt
|
|
64
|
+
- README.md
|
|
65
|
+
- Rakefile
|
|
66
|
+
- annyang_rails.gemspec
|
|
67
|
+
- app/assets/javascripts/annyang.js
|
|
68
|
+
- lib/annyang_rails.rb
|
|
69
|
+
- lib/annyang_rails/version.rb
|
|
70
|
+
homepage: https://github.com/guyisra/annyang_rails
|
|
71
|
+
licenses:
|
|
72
|
+
- MIT
|
|
73
|
+
metadata: {}
|
|
74
|
+
post_install_message:
|
|
75
|
+
rdoc_options: []
|
|
76
|
+
require_paths:
|
|
77
|
+
- lib
|
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ! '>='
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ! '>='
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
requirements: []
|
|
89
|
+
rubyforge_project:
|
|
90
|
+
rubygems_version: 2.1.3
|
|
91
|
+
signing_key:
|
|
92
|
+
specification_version: 4
|
|
93
|
+
summary: uses annyang.js to add speech recognition to your rails app
|
|
94
|
+
test_files: []
|