Text to speech API for Object Pascal. (#1273)

This commit is contained in:
Fangjun Kuang
2024-08-20 20:52:16 +08:00
committed by GitHub
parent e34a1a2aa3
commit 5a2aa110b8
14 changed files with 905 additions and 22 deletions

View File

@@ -18,6 +18,7 @@
#include "sherpa-onnx/csrc/offline-punctuation.h"
#include "sherpa-onnx/csrc/offline-recognizer.h"
#include "sherpa-onnx/csrc/online-recognizer.h"
#include "sherpa-onnx/csrc/resample.h"
#include "sherpa-onnx/csrc/speaker-embedding-extractor.h"
#include "sherpa-onnx/csrc/speaker-embedding-manager.h"
#include "sherpa-onnx/csrc/spoken-language-identification.h"
@@ -1584,3 +1585,56 @@ const char *SherpaOfflinePunctuationAddPunct(
}
void SherpaOfflinePunctuationFreeText(const char *text) { delete[] text; }
struct SherpaOnnxLinearResampler {
std::unique_ptr<sherpa_onnx::LinearResample> impl;
};
SherpaOnnxLinearResampler *SherpaOnnxCreateLinearResampler(
int32_t samp_rate_in_hz, int32_t samp_rate_out_hz, float filter_cutoff_hz,
int32_t num_zeros) {
SherpaOnnxLinearResampler *p = new SherpaOnnxLinearResampler;
p->impl = std::make_unique<sherpa_onnx::LinearResample>(
samp_rate_in_hz, samp_rate_out_hz, filter_cutoff_hz, num_zeros);
return p;
}
void SherpaOnnxDestroyLinearResampler(SherpaOnnxLinearResampler *p) {
delete p;
}
const SherpaOnnxResampleOut *SherpaOnnxLinearResamplerResample(
SherpaOnnxLinearResampler *p, const float *input, int32_t input_dim,
int32_t flush) {
std::vector<float> o;
p->impl->Resample(input, input_dim, flush, &o);
float *s = new float[o.size()];
std::copy(o.begin(), o.end(), s);
SherpaOnnxResampleOut *ans = new SherpaOnnxResampleOut;
ans->samples = s;
ans->n = static_cast<int32_t>(o.size());
return ans;
}
void SherpaOnnxLinearResamplerResampleFree(const SherpaOnnxResampleOut *p) {
delete[] p->samples;
delete p;
}
int32_t SherpaOnnxLinearResamplerResampleGetInputSampleRate(
const SherpaOnnxLinearResampler *p) {
return p->impl->GetInputSamplingRate();
}
int32_t SherpaOnnxLinearResamplerResampleGetOutputSampleRate(
const SherpaOnnxLinearResampler *p) {
return p->impl->GetOutputSamplingRate();
}
void SherpaOnnxLinearResamplerReset(SherpaOnnxLinearResampler *p) {
p->impl->Reset();
}

View File

@@ -1315,6 +1315,52 @@ SHERPA_ONNX_API const char *SherpaOfflinePunctuationAddPunct(
SHERPA_ONNX_API void SherpaOfflinePunctuationFreeText(const char *text);
// for resampling
SHERPA_ONNX_API typedef struct SherpaOnnxLinearResampler
SherpaOnnxLinearResampler;
/*
float min_freq = min(sampling_rate_in_hz, samp_rate_out_hz);
float lowpass_cutoff = 0.99 * 0.5 * min_freq;
int32_t lowpass_filter_width = 6;
You can set filter_cutoff_hz to lowpass_cutoff
sand set num_zeros to lowpass_filter_width
*/
// The user has to invoke SherpaOnnxDestroyLinearResampler()
// to free the returned pointer to avoid memory leak
SHERPA_ONNX_API SherpaOnnxLinearResampler *SherpaOnnxCreateLinearResampler(
int32_t samp_rate_in_hz, int32_t samp_rate_out_hz, float filter_cutoff_hz,
int32_t num_zeros);
SHERPA_ONNX_API void SherpaOnnxDestroyLinearResampler(
SherpaOnnxLinearResampler *p);
SHERPA_ONNX_API void SherpaOnnxLinearResamplerReset(
SherpaOnnxLinearResampler *p);
typedef struct SherpaOnnxResampleOut {
const float *samples;
int32_t n;
} SherpaOnnxResampleOut;
// The user has to invoke SherpaOnnxLinearResamplerResampleFree()
// to free the returned pointer to avoid memory leak.
//
// If this is the last segment, you can set flush to 1; otherwise, please
// set flush to 0
SHERPA_ONNX_API const SherpaOnnxResampleOut *SherpaOnnxLinearResamplerResample(
SherpaOnnxLinearResampler *p, const float *input, int32_t input_dim,
int32_t flush);
SHERPA_ONNX_API void SherpaOnnxLinearResamplerResampleFree(
const SherpaOnnxResampleOut *p);
SHERPA_ONNX_API int32_t SherpaOnnxLinearResamplerResampleGetInputSampleRate(
const SherpaOnnxLinearResampler *p);
SHERPA_ONNX_API int32_t SherpaOnnxLinearResamplerResampleGetOutputSampleRate(
const SherpaOnnxLinearResampler *p);
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif