spoken-language-identification.cc
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// sherpa-onnx/python/csrc/spoken-language-identification.cc
//
// Copyright (c) 2024 Xiaomi Corporation
#include "sherpa-onnx/python/csrc/spoken-language-identification.h"
#include <string>
#include "sherpa-onnx/csrc/spoken-language-identification.h"
namespace sherpa_onnx {
static void PybindSpokenLanguageIdentificationWhisperConfig(py::module *m) {
using PyClass = SpokenLanguageIdentificationWhisperConfig;
py::class_<PyClass>(*m, "SpokenLanguageIdentificationWhisperConfig")
.def(py::init<>())
.def(py::init<const std::string &, const std::string &, int32_t>(),
py::arg("encoder"), py::arg("decoder"),
py::arg("tail_paddings") = -1)
.def_readwrite("encoder", &PyClass::encoder)
.def_readwrite("decoder", &PyClass::decoder)
.def_readwrite("tail_paddings", &PyClass::tail_paddings)
.def("validate", &PyClass::Validate)
.def("__str__", &PyClass::ToString);
}
static void PybindSpokenLanguageIdentificationConfig(py::module *m) {
PybindSpokenLanguageIdentificationWhisperConfig(m);
using PyClass = SpokenLanguageIdentificationConfig;
py::class_<PyClass>(*m, "SpokenLanguageIdentificationConfig")
.def(py::init<>())
.def(py::init<const SpokenLanguageIdentificationWhisperConfig &, int32_t,
bool, const std::string &>(),
py::arg("whisper"), py::arg("num_threads") = 1,
py::arg("debug") = false, py::arg("provider") = "cpu")
.def_readwrite("whisper", &PyClass::whisper)
.def_readwrite("num_threads", &PyClass::num_threads)
.def_readwrite("debug", &PyClass::debug)
.def_readwrite("provider", &PyClass::provider)
.def("validate", &PyClass::Validate)
.def("__str__", &PyClass::ToString);
}
void PybindSpokenLanguageIdentification(py::module *m) {
PybindSpokenLanguageIdentificationConfig(m);
using PyClass = SpokenLanguageIdentification;
py::class_<PyClass>(*m, "SpokenLanguageIdentification")
.def(py::init<const SpokenLanguageIdentificationConfig &>(),
py::arg("config"), py::call_guard<py::gil_scoped_release>())
.def("create_stream", &PyClass::CreateStream,
py::call_guard<py::gil_scoped_release>())
.def("compute", &PyClass::Compute, py::arg("s"),
py::call_guard<py::gil_scoped_release>());
}
} // namespace sherpa_onnx