Skip to content

Commit

Permalink
Merge pull request Kitt-AI#418 from Kitt-AI/devel
Browse files Browse the repository at this point in the history
Added examples for using the frontend signal processing
  • Loading branch information
chenguoguo authored Apr 10, 2018
2 parents 61494e4 + 3300225 commit ae861e6
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public RecordingThread(Handler handler, AudioDataReceivedListener listener) {
this.listener = listener;

detector.SetSensitivity("0.6");
//-detector.SetAudioGain(1);
detector.SetAudioGain(1);
detector.ApplyFrontend(true);
try {
player.setDataSource(strEnvWorkSpace+"ding.wav");
Expand Down
2 changes: 2 additions & 0 deletions examples/C++/demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,13 @@ int main(int argc, char* argv[]) {
std::string model_filename = "resources/models/snowboy.umdl";
std::string sensitivity_str = "0.5";
float audio_gain = 1;
bool apply_frontend = false;

// Initializes Snowboy detector.
snowboy::SnowboyDetect detector(resource_filename, model_filename);
detector.SetSensitivity(sensitivity_str);
detector.SetAudioGain(audio_gain);
detector.ApplyFrontend(apply_frontend);

// Initializes PortAudio. You may use other tools to capture the audio.
PortAudioWrapper pa_wrapper(detector.SampleRate(),
Expand Down
4 changes: 4 additions & 0 deletions examples/C++/demo2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#define resource_filename "resources/common.res"
#define model_filename "resources/models/snowboy.umdl"
#define sensitivity_str "0.5"
#define audio_gain 1.0
#define apply_frontend false

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

int result = detector.RunDetection(&data_buffer[0], fsize/sizeof(short));
std::cout << ">>>>> Result: " << result << " <<<<<" << std::endl;
Expand Down
2 changes: 2 additions & 0 deletions examples/C/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,14 @@ int main(int argc, char* argv[]) {
const char model_filename[] = "resources/models/snowboy.umdl";
const char sensitivity_str[] = "0.5";
float audio_gain = 1;
bool apply_frontend = false;

// Initializes Snowboy detector.
SnowboyDetect* detector = SnowboyDetectConstructor(resource_filename,
model_filename);
SnowboyDetectSetSensitivity(detector, sensitivity_str);
SnowboyDetectSetAudioGain(detector, audio_gain);
SnowboyDetectApplyFrontend(detector, apply_frontend);

// Initializes PortAudio. You may use other tools to capture the audio.
StartAudioCapturing(SnowboyDetectSampleRate(detector),
Expand Down
3 changes: 2 additions & 1 deletion examples/Go/detect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func main() {
detector := snowboydetect.NewSnowboyDetect("../../../resources/common.res", os.Args[1])
detector.SetSensitivity("0.5")
detector.SetAudioGain(1)
detector.ApplyFrontend(false)
defer snowboydetect.DeleteSnowboyDetect(detector)

dat, err := ioutil.ReadFile(os.Args[2])
Expand All @@ -36,4 +37,4 @@ func main() {
} else {
fmt.Println("Snowboy detected keyword ", res)
}
}
}
1 change: 1 addition & 0 deletions examples/Java/Demo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static void main(String[] args) {
"resources/models/snowboy.umdl");
detector.SetSensitivity("0.5");
detector.SetAudioGain(1);
detector.ApplyFrontend(false);

try {
TargetDataLine targetLine =
Expand Down
3 changes: 2 additions & 1 deletion examples/Node/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ models.add({
const detector = new Detector({
resource: "resources/common.res",
models: models,
audioGain: 1.0
audioGain: 1.0,
applyFrontend: false
});

detector.on('silence', function () {
Expand Down
3 changes: 2 additions & 1 deletion examples/Node/microphone.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ models.add({
const detector = new Detector({
resource: "resources/common.res",
models: models,
audioGain: 2.0
audioGain: 2.0,
applyFrontend: true
});

detector.on('silence', function () {
Expand Down
1 change: 1 addition & 0 deletions examples/Perl/snowboy_googlevoice.pl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
$sb = new Snowboy::SnowboyDetect('resources/common.res', $model);
$sb->SetSensitivity('0.5');
$sb->SetAudioGain(1.0);
$sb->ApplyFrontend(0);

# Running the detection forever.
print "\n";
Expand Down
1 change: 1 addition & 0 deletions examples/Perl/snowboy_unit_test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

$sb->SetSensitivity ("0.5");
$sb->SetAudioGain (1);
$sb->ApplyFrontend (0);

print "==== SnowBoy object properties ====\n";
print "Sample Rate : ", $sb->SampleRate(), "\n";
Expand Down
5 changes: 4 additions & 1 deletion examples/Python/snowboydecoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ class HotwordDetector(object):
decoder. If an empty list is provided, then the
default sensitivity in the model will be used.
:param audio_gain: multiply input volume by this factor.
:param apply_frontend: applies the frontend processing algorithm if True.
"""
def __init__(self, decoder_model,
resource=RESOURCE_FILE,
sensitivity=[],
audio_gain=1):
audio_gain=1,
apply_frontend=False):

def audio_callback(in_data, frame_count, time_info, status):
self.ring_buffer.extend(in_data)
Expand All @@ -110,6 +112,7 @@ def audio_callback(in_data, frame_count, time_info, status):
self.detector = snowboydetect.SnowboyDetect(
resource_filename=resource.encode(), model_str=model_str.encode())
self.detector.SetAudioGain(audio_gain)
self.detector.ApplyFrontend(apply_frontend)
self.num_hotwords = self.detector.NumHotwords()

if len(decoder_model) > 1 and len(sensitivity) == 1:
Expand Down
5 changes: 4 additions & 1 deletion examples/Python3/snowboydecoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ class HotwordDetector(object):
decoder. If an empty list is provided, then the
default sensitivity in the model will be used.
:param audio_gain: multiply input volume by this factor.
:param apply_frontend: applies the frontend processing algorithm if True.
"""

def __init__(self, decoder_model,
resource=RESOURCE_FILE,
sensitivity=[],
audio_gain=1):
audio_gain=1,
apply_frontend=False):

tm = type(decoder_model)
ts = type(sensitivity)
Expand All @@ -107,6 +109,7 @@ def __init__(self, decoder_model,
self.detector = snowboydetect.SnowboyDetect(
resource_filename=resource.encode(), model_str=model_str.encode())
self.detector.SetAudioGain(audio_gain)
self.detector.ApplyFrontend(apply_frontend)
self.num_hotwords = self.detector.NumHotwords()

if len(decoder_model) > 1 and len(sensitivity) == 1:
Expand Down
1 change: 1 addition & 0 deletions examples/iOS/Obj-C/SnowboyTest/ViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ - (void)initSnowboy {
std::string([[[NSBundle mainBundle]pathForResource:@"alexa" ofType:@"umdl"] UTF8String]));
_snowboyDetect->SetSensitivity("0.5");
_snowboyDetect->SetAudioGain(1.0);
_snowboyDetect->ApplyFrotnend(false);
}

- (void) initMic {
Expand Down

0 comments on commit ae861e6

Please sign in to comment.