Skip to content

Commit

Permalink
Release 1.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj committed Dec 8, 2023
1 parent 58d2782 commit 3204d6d
Show file tree
Hide file tree
Showing 28 changed files with 41 additions and 5 deletions.
32 changes: 28 additions & 4 deletions c-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOnlineRecognizerResult {
const char *text;

// Pointer to continuous memory which holds string based tokens
// which are seperated by \0
// which are separated by \0
const char *tokens;

// a pointer array contains the address of the first item in tokens
// a pointer array containing the address of the first item in tokens
const char *const *tokens_arr;

// Pointer to continuous memory which holds timestamps
Expand Down Expand Up @@ -532,6 +532,11 @@ SHERPA_ONNX_API void SherpaOnnxCircularBufferPop(
SHERPA_ONNX_API int32_t
SherpaOnnxCircularBufferSize(SherpaOnnxCircularBuffer *buffer);

// Return the head of the buffer. It's always non-decreasing until you
// invoke SherpaOnnxCircularBufferReset() which resets head to 0.
SHERPA_ONNX_API int32_t
SherpaOnnxCircularBufferHead(SherpaOnnxCircularBuffer *buffer);

// Clear all elements in the buffer
SHERPA_ONNX_API void SherpaOnnxCircularBufferReset(
SherpaOnnxCircularBuffer *buffer);
Expand Down Expand Up @@ -602,6 +607,7 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsVitsModelConfig {
const char *model;
const char *lexicon;
const char *tokens;
const char *data_dir;

float noise_scale;
float noise_scale_w;
Expand All @@ -617,6 +623,8 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsModelConfig {

SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsConfig {
SherpaOnnxOfflineTtsModelConfig model;
const char *rule_fsts;
int32_t max_num_sentences;
} SherpaOnnxOfflineTtsConfig;

SHERPA_ONNX_API typedef struct SherpaOnnxGeneratedAudio {
Expand All @@ -625,6 +633,9 @@ SHERPA_ONNX_API typedef struct SherpaOnnxGeneratedAudio {
int32_t sample_rate;
} SherpaOnnxGeneratedAudio;

typedef void (*SherpaOnnxGeneratedAudioCallback)(const float *samples,
int32_t n);

SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTts SherpaOnnxOfflineTts;

// Create an instance of offline TTS. The user has to use DestroyOfflineTts()
Expand All @@ -635,13 +646,26 @@ SHERPA_ONNX_API SherpaOnnxOfflineTts *SherpaOnnxCreateOfflineTts(
// Free the pointer returned by CreateOfflineTts()
SHERPA_ONNX_API void SherpaOnnxDestroyOfflineTts(SherpaOnnxOfflineTts *tts);

// Return the sample rate of the current TTS object
SHERPA_ONNX_API int32_t
SherpaOnnxOfflineTtsSampleRate(const SherpaOnnxOfflineTts *tts);

// Generate audio from the given text and speaker id (sid).
// The user has to use DestroyOfflineTtsGeneratedAudio() to free the returned
// pointer to avoid memory leak.
// The user has to use DestroyOfflineTtsGeneratedAudio() to free the
// returned pointer to avoid memory leak.
SHERPA_ONNX_API const SherpaOnnxGeneratedAudio *SherpaOnnxOfflineTtsGenerate(
const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid,
float speed);

// callback is called whenever SherpaOnnxOfflineTtsConfig.max_num_sentences
// sentences have been processed. The pointer passed to the callback
// is freed once the callback is returned. So the caller should not keep
// a reference to it.
SHERPA_ONNX_API const SherpaOnnxGeneratedAudio *
SherpaOnnxOfflineTtsGenerateWithCallback(
const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid, float speed,
SherpaOnnxGeneratedAudioCallback callback);

SHERPA_ONNX_API void SherpaOnnxDestroyOfflineTtsGeneratedAudio(
const SherpaOnnxGeneratedAudio *p);

Expand Down
Binary file added lib/aarch64-apple-darwin/libespeak-ng.dylib
Binary file not shown.
Binary file not shown.
Binary file modified lib/aarch64-apple-darwin/libkaldi-native-fbank-core.dylib
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file removed lib/aarch64-apple-darwin/libonnxruntime.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified lib/aarch64-apple-darwin/libsherpa-onnx-c-api.dylib
100644 → 100755
Binary file not shown.
Binary file modified lib/aarch64-apple-darwin/libsherpa-onnx-core.dylib
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added lib/aarch64-apple-darwin/libucd.dylib
Binary file not shown.
Binary file added lib/x86_64-apple-darwin/libespeak-ng.dylib
Binary file not shown.
Binary file not shown.
Binary file modified lib/x86_64-apple-darwin/libkaldi-native-fbank-core.dylib
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file removed lib/x86_64-apple-darwin/libonnxruntime.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added lib/x86_64-apple-darwin/libpiper_phonemize.dylib
Binary file not shown.
Binary file modified lib/x86_64-apple-darwin/libsherpa-onnx-c-api.dylib
100644 → 100755
Binary file not shown.
Binary file modified lib/x86_64-apple-darwin/libsherpa-onnx-core.dylib
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added lib/x86_64-apple-darwin/libucd.dylib
Binary file not shown.
14 changes: 13 additions & 1 deletion sherpa_onnx.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ type OfflineTtsVitsModelConfig struct {
Model string // Path to the VITS onnx model
Lexicon string // Path to lexicon.txt
Tokens string // Path to tokens.txt
DataDir string // Path to tokens.txt
NoiseScale float32 // noise scale for vits models. Please use 0.667 in general
NoiseScaleW float32 // noise scale for vits models. Please use 0.8 in general
LengthScale float32 // Please use 1.0 in general. Smaller -> Faster speech speed. Larger -> Slower speech speed
Expand All @@ -522,7 +523,9 @@ type OfflineTtsModelConfig struct {
}

type OfflineTtsConfig struct {
Model OfflineTtsModelConfig
Model OfflineTtsModelConfig
RuleFsts string
MaxNumSentences int
}

type GeneratedAudio struct {
Expand All @@ -547,6 +550,12 @@ func DeleteOfflineTts(tts *OfflineTts) {
// the returned tts to avoid memory leak
func NewOfflineTts(config *OfflineTtsConfig) *OfflineTts {
c := C.struct_SherpaOnnxOfflineTtsConfig{}

c.rule_fsts = C.CString(config.RuleFsts)
defer C.free(unsafe.Pointer(c.rule_fsts))

c.max_num_sentences = C.int(config.MaxNumSentences)

c.model.vits.model = C.CString(config.Model.Vits.Model)
defer C.free(unsafe.Pointer(c.model.vits.model))

Expand All @@ -556,6 +565,9 @@ func NewOfflineTts(config *OfflineTtsConfig) *OfflineTts {
c.model.vits.tokens = C.CString(config.Model.Vits.Tokens)
defer C.free(unsafe.Pointer(c.model.vits.tokens))

c.model.vits.data_dir = C.CString(config.Model.Vits.DataDir)
defer C.free(unsafe.Pointer(c.model.vits.data_dir))

c.model.vits.noise_scale = C.float(config.Model.Vits.NoiseScale)
c.model.vits.noise_scale_w = C.float(config.Model.Vits.NoiseScaleW)
c.model.vits.length_scale = C.float(config.Model.Vits.LengthScale)
Expand Down

0 comments on commit 3204d6d

Please sign in to comment.