38 Nan::ThrowError(e.
what());
48 v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
49 tpl->SetClassName(Nan::New(
"SnowboyDetect").ToLocalChecked());
50 tpl->InstanceTemplate()->SetInternalFieldCount(1);
52 SetPrototypeMethod(tpl,
"Reset", Reset);
53 SetPrototypeMethod(tpl,
"RunDetection", RunDetection);
54 SetPrototypeMethod(tpl,
"SetSensitivity", SetSensitivity);
55 SetPrototypeMethod(tpl,
"GetSensitivity", GetSensitivity);
56 SetPrototypeMethod(tpl,
"SetAudioGain", SetAudioGain);
57 SetPrototypeMethod(tpl,
"UpdateModel", UpdateModel);
58 SetPrototypeMethod(tpl,
"NumHotwords", NumHotwords);
59 SetPrototypeMethod(tpl,
"SampleRate", SampleRate);
60 SetPrototypeMethod(tpl,
"NumChannels", NumChannels);
61 SetPrototypeMethod(tpl,
"BitsPerSample", BitsPerSample);
63 constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked());
64 Nan::Set(target, Nan::New(
"SnowboyDetect").ToLocalChecked(),
65 Nan::GetFunction(tpl).ToLocalChecked());
69 if (!info.IsConstructCall()) {
70 Nan::ThrowError(
"Cannot call constructor as function, you need to use "
73 }
else if (!info[0]->IsString()) {
74 Nan::ThrowTypeError(
"resource must be a string");
76 }
else if (!info[1]->IsString()) {
77 Nan::ThrowTypeError(
"model must be a string");
81 Nan::MaybeLocal<v8::Object> resource = Nan::To<v8::Object>(info[0]);
82 Nan::MaybeLocal<v8::Object>
model = Nan::To<v8::Object>(info[1]);
83 Nan::Utf8String resourceString(resource.ToLocalChecked());
84 Nan::Utf8String modelString(
model.ToLocalChecked());
86 obj->Wrap(info.This());
87 info.GetReturnValue().Set(info.This());
91 SnowboyDetect* ptr = Nan::ObjectWrap::Unwrap<SnowboyDetect>(info.Holder());
93 info.GetReturnValue().Set(Nan::New(ret));
97 if (!info[0]->IsObject()) {
98 Nan::ThrowTypeError(
"data must be a buffer");
102 Nan::MaybeLocal<v8::Object> buffer = Nan::To<v8::Object>(info[0]);
103 char* bufferData = node::Buffer::Data(buffer.ToLocalChecked());
104 size_t bufferLength = node::Buffer::Length(buffer.ToLocalChecked());
108 SnowboyDetect* ptr = Nan::ObjectWrap::Unwrap<SnowboyDetect>(info.Holder());
110 info.GetReturnValue().Set(Nan::New(ret));
114 if (!info[0]->IsString()) {
115 Nan::ThrowTypeError(
"sensitivity must be a string");
119 Nan::MaybeLocal<v8::Object>
sensitivity = Nan::To<v8::Object>(info[0]);
120 Nan::Utf8String sensitivityString(
sensitivity.ToLocalChecked());
122 SnowboyDetect* ptr = Nan::ObjectWrap::Unwrap<SnowboyDetect>(info.Holder());
127 SnowboyDetect* ptr = Nan::ObjectWrap::Unwrap<SnowboyDetect>(info.Holder());
129 info.GetReturnValue().Set(Nan::New(
sensitivity).ToLocalChecked());
133 if (!info[0]->IsNumber()) {
134 Nan::ThrowTypeError(
"gain must be a number");
138 Nan::MaybeLocal<v8::Number> gain = Nan::To<v8::Number>(info[0]);
139 SnowboyDetect* ptr = Nan::ObjectWrap::Unwrap<SnowboyDetect>(info.Holder());
144 SnowboyDetect* ptr = Nan::ObjectWrap::Unwrap<SnowboyDetect>(info.Holder());
149 SnowboyDetect* ptr = Nan::ObjectWrap::Unwrap<SnowboyDetect>(info.Holder());
151 info.GetReturnValue().Set(Nan::New(numHotwords));
155 SnowboyDetect* ptr = Nan::ObjectWrap::Unwrap<SnowboyDetect>(info.Holder());
157 info.GetReturnValue().Set(Nan::New(sampleRate));
161 SnowboyDetect* ptr = Nan::ObjectWrap::Unwrap<SnowboyDetect>(info.Holder());
163 info.GetReturnValue().Set(Nan::New(numChannels));
167 SnowboyDetect* ptr = Nan::ObjectWrap::Unwrap<SnowboyDetect>(info.Holder());
169 info.GetReturnValue().Set(Nan::New(bitsPerSample));