c-api add wave write to buffer. (#1962)

Co-authored-by: jian.chen03 <jian.chen03@transwarp.io>
This commit is contained in:
cjsdurj
2025-03-10 17:21:23 +08:00
committed by GitHub
parent 6e261ed63f
commit b87fce9a7f
5 changed files with 48 additions and 8 deletions

View File

@@ -1337,6 +1337,16 @@ int32_t SherpaOnnxWriteWave(const float *samples, int32_t n,
return sherpa_onnx::WriteWave(filename, sample_rate, samples, n);
}
int64_t SherpaOnnxWaveFileSize(int32_t n_samples) {
return sherpa_onnx::WaveFileSize(n_samples);
}
SHERPA_ONNX_API void SherpaOnnxWriteWaveToBuffer(const float *samples,
int32_t n, int32_t sample_rate,
char *buffer) {
sherpa_onnx::WriteWave(buffer, sample_rate, samples, n);
}
const SherpaOnnxWave *SherpaOnnxReadWave(const char *filename) {
int32_t sample_rate = -1;
bool is_ok = false;

View File

@@ -1049,6 +1049,18 @@ SHERPA_ONNX_API int32_t SherpaOnnxWriteWave(const float *samples, int32_t n,
int32_t sample_rate,
const char *filename);
// the amount of bytes needed to store a wave file which contains a
// single channel and has 16-bit samples.
SHERPA_ONNX_API int64_t SherpaOnnxWaveFileSize(int32_t n_samples);
// Similar to SherpaOnnxWriteWave , it writes wave to allocated buffer;
//
// in some case (http tts api return wave binary file, server do not need to
// write wave to fs)
SHERPA_ONNX_API void SherpaOnnxWriteWaveToBuffer(const float *samples,
int32_t n, int32_t sample_rate,
char *buffer);
SHERPA_ONNX_API typedef struct SherpaOnnxWave {
// samples normalized to the range [-1, 1]
const float *samples;