Skip to content

Commit ae861e6

Browse files
authored
Merge pull request Kitt-AI#418 from Kitt-AI/devel
Added examples for using the frontend signal processing
2 parents 61494e4 + 3300225 commit ae861e6

File tree

13 files changed

+27
-6
lines changed

13 files changed

+27
-6
lines changed

examples/Android/SnowboyAlexaDemo/src/ai/kitt/snowboy/audio/RecordingThread.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public RecordingThread(Handler handler, AudioDataReceivedListener listener) {
4141
this.listener = listener;
4242

4343
detector.SetSensitivity("0.6");
44-
//-detector.SetAudioGain(1);
44+
detector.SetAudioGain(1);
4545
detector.ApplyFrontend(true);
4646
try {
4747
player.setDataSource(strEnvWorkSpace+"ding.wav");

examples/C++/demo.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,13 @@ int main(int argc, char* argv[]) {
207207
std::string model_filename = "resources/models/snowboy.umdl";
208208
std::string sensitivity_str = "0.5";
209209
float audio_gain = 1;
210+
bool apply_frontend = false;
210211

211212
// Initializes Snowboy detector.
212213
snowboy::SnowboyDetect detector(resource_filename, model_filename);
213214
detector.SetSensitivity(sensitivity_str);
214215
detector.SetAudioGain(audio_gain);
216+
detector.ApplyFrontend(apply_frontend);
215217

216218
// Initializes PortAudio. You may use other tools to capture the audio.
217219
PortAudioWrapper pa_wrapper(detector.SampleRate(),

examples/C++/demo2.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#define resource_filename "resources/common.res"
66
#define model_filename "resources/models/snowboy.umdl"
77
#define sensitivity_str "0.5"
8+
#define audio_gain 1.0
9+
#define apply_frontend false
810

911
struct wavHeader { //44 byte HEADER only
1012
char RIFF[4];
@@ -136,6 +138,8 @@ int main(int argc, char * argv[]) {
136138
// Initializes Snowboy detector.
137139
snowboy::SnowboyDetect detector(resource_filename, model_filename);
138140
detector.SetSensitivity(sensitivity_str);
141+
detector.SetAudioGain(audio_gain);
142+
detector.ApplyFrontend(apply_frontend);
139143

140144
int result = detector.RunDetection(&data_buffer[0], fsize/sizeof(short));
141145
std::cout << ">>>>> Result: " << result << " <<<<<" << std::endl;

examples/C/demo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,14 @@ int main(int argc, char* argv[]) {
190190
const char model_filename[] = "resources/models/snowboy.umdl";
191191
const char sensitivity_str[] = "0.5";
192192
float audio_gain = 1;
193+
bool apply_frontend = false;
193194

194195
// Initializes Snowboy detector.
195196
SnowboyDetect* detector = SnowboyDetectConstructor(resource_filename,
196197
model_filename);
197198
SnowboyDetectSetSensitivity(detector, sensitivity_str);
198199
SnowboyDetectSetAudioGain(detector, audio_gain);
200+
SnowboyDetectApplyFrontend(detector, apply_frontend);
199201

200202
// Initializes PortAudio. You may use other tools to capture the audio.
201203
StartAudioCapturing(SnowboyDetectSampleRate(detector),

examples/Go/detect/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func main() {
1818
detector := snowboydetect.NewSnowboyDetect("../../../resources/common.res", os.Args[1])
1919
detector.SetSensitivity("0.5")
2020
detector.SetAudioGain(1)
21+
detector.ApplyFrontend(false)
2122
defer snowboydetect.DeleteSnowboyDetect(detector)
2223

2324
dat, err := ioutil.ReadFile(os.Args[2])
@@ -36,4 +37,4 @@ func main() {
3637
} else {
3738
fmt.Println("Snowboy detected keyword ", res)
3839
}
39-
}
40+
}

examples/Java/Demo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static void main(String[] args) {
2424
"resources/models/snowboy.umdl");
2525
detector.SetSensitivity("0.5");
2626
detector.SetAudioGain(1);
27+
detector.ApplyFrontend(false);
2728

2829
try {
2930
TargetDataLine targetLine =

examples/Node/file.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ models.add({
1414
const detector = new Detector({
1515
resource: "resources/common.res",
1616
models: models,
17-
audioGain: 1.0
17+
audioGain: 1.0,
18+
applyFrontend: false
1819
});
1920

2021
detector.on('silence', function () {

examples/Node/microphone.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ models.add({
1313
const detector = new Detector({
1414
resource: "resources/common.res",
1515
models: models,
16-
audioGain: 2.0
16+
audioGain: 2.0,
17+
applyFrontend: true
1718
});
1819

1920
detector.on('silence', function () {

examples/Perl/snowboy_googlevoice.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
$sb = new Snowboy::SnowboyDetect('resources/common.res', $model);
134134
$sb->SetSensitivity('0.5');
135135
$sb->SetAudioGain(1.0);
136+
$sb->ApplyFrontend(0);
136137

137138
# Running the detection forever.
138139
print "\n";

examples/Perl/snowboy_unit_test.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
$sb->SetSensitivity ("0.5");
1818
$sb->SetAudioGain (1);
19+
$sb->ApplyFrontend (0);
1920

2021
print "==== SnowBoy object properties ====\n";
2122
print "Sample Rate : ", $sb->SampleRate(), "\n";

examples/Python/snowboydecoder.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@ class HotwordDetector(object):
8888
decoder. If an empty list is provided, then the
8989
default sensitivity in the model will be used.
9090
:param audio_gain: multiply input volume by this factor.
91+
:param apply_frontend: applies the frontend processing algorithm if True.
9192
"""
9293
def __init__(self, decoder_model,
9394
resource=RESOURCE_FILE,
9495
sensitivity=[],
95-
audio_gain=1):
96+
audio_gain=1,
97+
apply_frontend=False):
9698

9799
def audio_callback(in_data, frame_count, time_info, status):
98100
self.ring_buffer.extend(in_data)
@@ -110,6 +112,7 @@ def audio_callback(in_data, frame_count, time_info, status):
110112
self.detector = snowboydetect.SnowboyDetect(
111113
resource_filename=resource.encode(), model_str=model_str.encode())
112114
self.detector.SetAudioGain(audio_gain)
115+
self.detector.ApplyFrontend(apply_frontend)
113116
self.num_hotwords = self.detector.NumHotwords()
114117

115118
if len(decoder_model) > 1 and len(sensitivity) == 1:

examples/Python3/snowboydecoder.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ class HotwordDetector(object):
8989
decoder. If an empty list is provided, then the
9090
default sensitivity in the model will be used.
9191
:param audio_gain: multiply input volume by this factor.
92+
:param apply_frontend: applies the frontend processing algorithm if True.
9293
"""
9394

9495
def __init__(self, decoder_model,
9596
resource=RESOURCE_FILE,
9697
sensitivity=[],
97-
audio_gain=1):
98+
audio_gain=1,
99+
apply_frontend=False):
98100

99101
tm = type(decoder_model)
100102
ts = type(sensitivity)
@@ -107,6 +109,7 @@ def __init__(self, decoder_model,
107109
self.detector = snowboydetect.SnowboyDetect(
108110
resource_filename=resource.encode(), model_str=model_str.encode())
109111
self.detector.SetAudioGain(audio_gain)
112+
self.detector.ApplyFrontend(apply_frontend)
110113
self.num_hotwords = self.detector.NumHotwords()
111114

112115
if len(decoder_model) > 1 and len(sensitivity) == 1:

examples/iOS/Obj-C/SnowboyTest/ViewController.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ - (void)initSnowboy {
3131
std::string([[[NSBundle mainBundle]pathForResource:@"alexa" ofType:@"umdl"] UTF8String]));
3232
_snowboyDetect->SetSensitivity("0.5");
3333
_snowboyDetect->SetAudioGain(1.0);
34+
_snowboyDetect->ApplyFrotnend(false);
3435
}
3536

3637
- (void) initMic {

0 commit comments

Comments
 (0)