|
24 | 24 | #include "sherpa-onnx/csrc/macros.h"
|
25 | 25 | #include "sherpa-onnx/csrc/offline-punctuation.h"
|
26 | 26 | #include "sherpa-onnx/csrc/offline-recognizer.h"
|
| 27 | +#include "sherpa-onnx/csrc/online-punctuation.h" |
27 | 28 | #include "sherpa-onnx/csrc/online-recognizer.h"
|
28 | 29 | #include "sherpa-onnx/csrc/resample.h"
|
29 | 30 | #include "sherpa-onnx/csrc/speaker-embedding-extractor.h"
|
@@ -1717,6 +1718,53 @@ const char *SherpaOfflinePunctuationAddPunct(
|
1717 | 1718 |
|
1718 | 1719 | void SherpaOfflinePunctuationFreeText(const char *text) { delete[] text; }
|
1719 | 1720 |
|
| 1721 | +struct SherpaOnnxOnlinePunctuation { |
| 1722 | + std::unique_ptr<sherpa_onnx::OnlinePunctuation> impl; |
| 1723 | +}; |
| 1724 | + |
| 1725 | +const SherpaOnnxOnlinePunctuation *SherpaOnnxCreateOnlinePunctuation( |
| 1726 | + const SherpaOnnxOnlinePunctuationConfig *config) { |
| 1727 | + auto p = new SherpaOnnxOnlinePunctuation; |
| 1728 | + try { |
| 1729 | + sherpa_onnx::OnlinePunctuationConfig punctuation_config; |
| 1730 | + punctuation_config.model.cnn_bilstm = SHERPA_ONNX_OR(config->model.cnn_bilstm, ""); |
| 1731 | + punctuation_config.model.bpe_vocab = SHERPA_ONNX_OR(config->model.bpe_vocab, ""); |
| 1732 | + punctuation_config.model.num_threads = SHERPA_ONNX_OR(config->model.num_threads, 1); |
| 1733 | + punctuation_config.model.debug = config->model.debug; |
| 1734 | + punctuation_config.model.provider = SHERPA_ONNX_OR(config->model.provider, "cpu"); |
| 1735 | + |
| 1736 | + p->impl = |
| 1737 | + std::make_unique<sherpa_onnx::OnlinePunctuation>(punctuation_config); |
| 1738 | + } catch (const std::exception &e) { |
| 1739 | + SHERPA_ONNX_LOGE("Failed to create online punctuation: %s", e.what()); |
| 1740 | + delete p; |
| 1741 | + return nullptr; |
| 1742 | + } |
| 1743 | + return p; |
| 1744 | +} |
| 1745 | + |
| 1746 | +void SherpaOnnxDestroyOnlinePunctuation(const SherpaOnnxOnlinePunctuation *p) { |
| 1747 | + delete p; |
| 1748 | +} |
| 1749 | + |
| 1750 | +const char *SherpaOnnxOnlinePunctuationAddPunct( |
| 1751 | + const SherpaOnnxOnlinePunctuation *punctuation, const char *text) { |
| 1752 | + if (!punctuation || !text) return nullptr; |
| 1753 | + |
| 1754 | + try { |
| 1755 | + std::string s = punctuation->impl->AddPunctuationWithCase(text); |
| 1756 | + char *p = new char[s.size() + 1]; |
| 1757 | + std::copy(s.begin(), s.end(), p); |
| 1758 | + p[s.size()] = '\0'; |
| 1759 | + return p; |
| 1760 | + } catch (const std::exception &e) { |
| 1761 | + SHERPA_ONNX_LOGE("Failed to add punctuation: %s", e.what()); |
| 1762 | + return nullptr; |
| 1763 | + } |
| 1764 | +} |
| 1765 | + |
| 1766 | +void SherpaOnnxOnlinePunctuationFreeText(const char *text) { delete[] text; } |
| 1767 | + |
1720 | 1768 | struct SherpaOnnxLinearResampler {
|
1721 | 1769 | std::unique_ptr<sherpa_onnx::LinearResample> impl;
|
1722 | 1770 | };
|
|
0 commit comments