mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
* add hotword for deploy_tools * Support wfst decoder and contextual biasing (#1039) * Support wfst decoder and contextual biasing * Turn on fstbin compilation --------- Co-authored-by: gongbo.gb <gongbo.gb@alibaba-inc.com> * mv funasr/runtime runtime * Fix crash caused by OOV in hotwords list * funasr infer * funasr infer * funasr infer * funasr infer * funasr infer * fix some bugs about fst hotword; support wfst for websocket server and clients; mv runtime out of funasr; modify relative docs * del onnxruntime/include/gflags * update tensor.h * update run_server.sh * update deploy tools * update deploy tools * update websocket-server * update funasr-wss-server * Remove self loop propagation * Update websocket_protocol_zh.md * Update websocket_protocol_zh.md * update hotword protocol * author zhaomingwork: change hotwords for h5 and java * update hotword protocol * catch exception for json_fst_hws * update hotword on message * update onnx benchmark for ngram&hotword * update docs * update funasr-wss-serve * add NONE for LM_DIR * update docs * update run_server.sh * add whats-new * modify whats-new * update whats-new * update whats-new * Support decoder option for beam searching * update benchmark_onnx_cpp * Support decoder option for websocket * fix bug of CompileHotwordEmbedding * update html client * update docs --------- Co-authored-by: gongbo.gb <35997837+aibulamusi@users.noreply.github.com> Co-authored-by: gongbo.gb <gongbo.gb@alibaba-inc.com> Co-authored-by: 游雁 <zhifu.gzf@alibaba-inc.com>
207 lines
4.3 KiB
C++
207 lines
4.3 KiB
C++
#ifndef LIMONP_CLOSURE_HPP
|
|
#define LIMONP_CLOSURE_HPP
|
|
|
|
namespace limonp {
|
|
|
|
class ClosureInterface {
|
|
public:
|
|
virtual ~ClosureInterface() {
|
|
}
|
|
virtual void Run() = 0;
|
|
};
|
|
|
|
template <class Funct>
|
|
class Closure0: public ClosureInterface {
|
|
public:
|
|
Closure0(Funct fun) {
|
|
fun_ = fun;
|
|
}
|
|
virtual ~Closure0() {
|
|
}
|
|
virtual void Run() {
|
|
(*fun_)();
|
|
}
|
|
private:
|
|
Funct fun_;
|
|
};
|
|
|
|
template <class Funct, class Arg1>
|
|
class Closure1: public ClosureInterface {
|
|
public:
|
|
Closure1(Funct fun, Arg1 arg1) {
|
|
fun_ = fun;
|
|
arg1_ = arg1;
|
|
}
|
|
virtual ~Closure1() {
|
|
}
|
|
virtual void Run() {
|
|
(*fun_)(arg1_);
|
|
}
|
|
private:
|
|
Funct fun_;
|
|
Arg1 arg1_;
|
|
};
|
|
|
|
template <class Funct, class Arg1, class Arg2>
|
|
class Closure2: public ClosureInterface {
|
|
public:
|
|
Closure2(Funct fun, Arg1 arg1, Arg2 arg2) {
|
|
fun_ = fun;
|
|
arg1_ = arg1;
|
|
arg2_ = arg2;
|
|
}
|
|
virtual ~Closure2() {
|
|
}
|
|
virtual void Run() {
|
|
(*fun_)(arg1_, arg2_);
|
|
}
|
|
private:
|
|
Funct fun_;
|
|
Arg1 arg1_;
|
|
Arg2 arg2_;
|
|
};
|
|
|
|
template <class Funct, class Arg1, class Arg2, class Arg3>
|
|
class Closure3: public ClosureInterface {
|
|
public:
|
|
Closure3(Funct fun, Arg1 arg1, Arg2 arg2, Arg3 arg3) {
|
|
fun_ = fun;
|
|
arg1_ = arg1;
|
|
arg2_ = arg2;
|
|
arg3_ = arg3;
|
|
}
|
|
virtual ~Closure3() {
|
|
}
|
|
virtual void Run() {
|
|
(*fun_)(arg1_, arg2_, arg3_);
|
|
}
|
|
private:
|
|
Funct fun_;
|
|
Arg1 arg1_;
|
|
Arg2 arg2_;
|
|
Arg3 arg3_;
|
|
};
|
|
|
|
template <class Obj, class Funct>
|
|
class ObjClosure0: public ClosureInterface {
|
|
public:
|
|
ObjClosure0(Obj* p, Funct fun) {
|
|
p_ = p;
|
|
fun_ = fun;
|
|
}
|
|
virtual ~ObjClosure0() {
|
|
}
|
|
virtual void Run() {
|
|
(p_->*fun_)();
|
|
}
|
|
private:
|
|
Obj* p_;
|
|
Funct fun_;
|
|
};
|
|
|
|
template <class Obj, class Funct, class Arg1>
|
|
class ObjClosure1: public ClosureInterface {
|
|
public:
|
|
ObjClosure1(Obj* p, Funct fun, Arg1 arg1) {
|
|
p_ = p;
|
|
fun_ = fun;
|
|
arg1_ = arg1;
|
|
}
|
|
virtual ~ObjClosure1() {
|
|
}
|
|
virtual void Run() {
|
|
(p_->*fun_)(arg1_);
|
|
}
|
|
private:
|
|
Obj* p_;
|
|
Funct fun_;
|
|
Arg1 arg1_;
|
|
};
|
|
|
|
template <class Obj, class Funct, class Arg1, class Arg2>
|
|
class ObjClosure2: public ClosureInterface {
|
|
public:
|
|
ObjClosure2(Obj* p, Funct fun, Arg1 arg1, Arg2 arg2) {
|
|
p_ = p;
|
|
fun_ = fun;
|
|
arg1_ = arg1;
|
|
arg2_ = arg2;
|
|
}
|
|
virtual ~ObjClosure2() {
|
|
}
|
|
virtual void Run() {
|
|
(p_->*fun_)(arg1_, arg2_);
|
|
}
|
|
private:
|
|
Obj* p_;
|
|
Funct fun_;
|
|
Arg1 arg1_;
|
|
Arg2 arg2_;
|
|
};
|
|
template <class Obj, class Funct, class Arg1, class Arg2, class Arg3>
|
|
class ObjClosure3: public ClosureInterface {
|
|
public:
|
|
ObjClosure3(Obj* p, Funct fun, Arg1 arg1, Arg2 arg2, Arg3 arg3) {
|
|
p_ = p;
|
|
fun_ = fun;
|
|
arg1_ = arg1;
|
|
arg2_ = arg2;
|
|
arg3_ = arg3;
|
|
}
|
|
virtual ~ObjClosure3() {
|
|
}
|
|
virtual void Run() {
|
|
(p_->*fun_)(arg1_, arg2_, arg3_);
|
|
}
|
|
private:
|
|
Obj* p_;
|
|
Funct fun_;
|
|
Arg1 arg1_;
|
|
Arg2 arg2_;
|
|
Arg3 arg3_;
|
|
};
|
|
|
|
template<class R>
|
|
ClosureInterface* NewClosure(R (*fun)()) {
|
|
return new Closure0<R (*)()>(fun);
|
|
}
|
|
|
|
template<class R, class Arg1>
|
|
ClosureInterface* NewClosure(R (*fun)(Arg1), Arg1 arg1) {
|
|
return new Closure1<R (*)(Arg1), Arg1>(fun, arg1);
|
|
}
|
|
|
|
template<class R, class Arg1, class Arg2>
|
|
ClosureInterface* NewClosure(R (*fun)(Arg1, Arg2), Arg1 arg1, Arg2 arg2) {
|
|
return new Closure2<R (*)(Arg1, Arg2), Arg1, Arg2>(fun, arg1, arg2);
|
|
}
|
|
|
|
template<class R, class Arg1, class Arg2, class Arg3>
|
|
ClosureInterface* NewClosure(R (*fun)(Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3) {
|
|
return new Closure3<R (*)(Arg1, Arg2, Arg3), Arg1, Arg2, Arg3>(fun, arg1, arg2, arg3);
|
|
}
|
|
|
|
template<class R, class Obj>
|
|
ClosureInterface* NewClosure(Obj* obj, R (Obj::* fun)()) {
|
|
return new ObjClosure0<Obj, R (Obj::* )()>(obj, fun);
|
|
}
|
|
|
|
template<class R, class Obj, class Arg1>
|
|
ClosureInterface* NewClosure(Obj* obj, R (Obj::* fun)(Arg1), Arg1 arg1) {
|
|
return new ObjClosure1<Obj, R (Obj::* )(Arg1), Arg1>(obj, fun, arg1);
|
|
}
|
|
|
|
template<class R, class Obj, class Arg1, class Arg2>
|
|
ClosureInterface* NewClosure(Obj* obj, R (Obj::* fun)(Arg1, Arg2), Arg1 arg1, Arg2 arg2) {
|
|
return new ObjClosure2<Obj, R (Obj::*)(Arg1, Arg2), Arg1, Arg2>(obj, fun, arg1, arg2);
|
|
}
|
|
|
|
template<class R, class Obj, class Arg1, class Arg2, class Arg3>
|
|
ClosureInterface* NewClosure(Obj* obj, R (Obj::* fun)(Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3) {
|
|
return new ObjClosure3<Obj, R (Obj::*)(Arg1, Arg2, Arg3), Arg1, Arg2, Arg3>(obj, fun, arg1, arg2, arg3);
|
|
}
|
|
|
|
} // namespace limonp
|
|
|
|
#endif // LIMONP_CLOSURE_HPP
|