Support user provided data in tts callback. (#653)
This commit is contained in:
@@ -636,6 +636,32 @@ const SherpaOnnxGeneratedAudio *SherpaOnnxOfflineTtsGenerateWithCallback(
|
|||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SherpaOnnxGeneratedAudio *SherpaOnnxOfflineTtsGenerateWithCallbackWithArg(
|
||||||
|
const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid, float speed,
|
||||||
|
SherpaOnnxGeneratedAudioCallbackWithArg callback, void *arg) {
|
||||||
|
auto wrapper = [callback, arg](const float *samples, int32_t n) {
|
||||||
|
callback(samples, n, arg);
|
||||||
|
};
|
||||||
|
|
||||||
|
sherpa_onnx::GeneratedAudio audio =
|
||||||
|
tts->impl->Generate(text, sid, speed, wrapper);
|
||||||
|
|
||||||
|
if (audio.samples.empty()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
SherpaOnnxGeneratedAudio *ans = new SherpaOnnxGeneratedAudio;
|
||||||
|
|
||||||
|
float *samples = new float[audio.samples.size()];
|
||||||
|
std::copy(audio.samples.begin(), audio.samples.end(), samples);
|
||||||
|
|
||||||
|
ans->samples = samples;
|
||||||
|
ans->n = audio.samples.size();
|
||||||
|
ans->sample_rate = audio.sample_rate;
|
||||||
|
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
void SherpaOnnxDestroyOfflineTtsGeneratedAudio(
|
void SherpaOnnxDestroyOfflineTtsGeneratedAudio(
|
||||||
const SherpaOnnxGeneratedAudio *p) {
|
const SherpaOnnxGeneratedAudio *p) {
|
||||||
if (p) {
|
if (p) {
|
||||||
|
|||||||
@@ -644,6 +644,9 @@ SHERPA_ONNX_API typedef struct SherpaOnnxGeneratedAudio {
|
|||||||
typedef void (*SherpaOnnxGeneratedAudioCallback)(const float *samples,
|
typedef void (*SherpaOnnxGeneratedAudioCallback)(const float *samples,
|
||||||
int32_t n);
|
int32_t n);
|
||||||
|
|
||||||
|
typedef void (*SherpaOnnxGeneratedAudioCallbackWithArg)(const float *samples,
|
||||||
|
int32_t n, void *arg);
|
||||||
|
|
||||||
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTts SherpaOnnxOfflineTts;
|
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTts SherpaOnnxOfflineTts;
|
||||||
|
|
||||||
// Create an instance of offline TTS. The user has to use DestroyOfflineTts()
|
// Create an instance of offline TTS. The user has to use DestroyOfflineTts()
|
||||||
@@ -678,6 +681,13 @@ SherpaOnnxOfflineTtsGenerateWithCallback(
|
|||||||
const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid, float speed,
|
const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid, float speed,
|
||||||
SherpaOnnxGeneratedAudioCallback callback);
|
SherpaOnnxGeneratedAudioCallback callback);
|
||||||
|
|
||||||
|
// Same as SherpaOnnxGeneratedAudioCallback but you can pass an additional
|
||||||
|
// `void* arg` to the callback.
|
||||||
|
SHERPA_ONNX_API const SherpaOnnxGeneratedAudio *
|
||||||
|
SherpaOnnxOfflineTtsGenerateWithCallbackWithArg(
|
||||||
|
const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid, float speed,
|
||||||
|
SherpaOnnxGeneratedAudioCallbackWithArg callback, void *arg);
|
||||||
|
|
||||||
SHERPA_ONNX_API void SherpaOnnxDestroyOfflineTtsGeneratedAudio(
|
SHERPA_ONNX_API void SherpaOnnxDestroyOfflineTtsGeneratedAudio(
|
||||||
const SherpaOnnxGeneratedAudio *p);
|
const SherpaOnnxGeneratedAudio *p);
|
||||||
|
|
||||||
|
|||||||
@@ -43,5 +43,3 @@ void PybindAlsa(py::module *m) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sherpa_onnx
|
} // namespace sherpa_onnx
|
||||||
|
|
||||||
#endif // SHERPA_ONNX_PYTHON_CSRC_FAKED_ALSA_H_
|
|
||||||
|
|||||||
Reference in New Issue
Block a user