Skip to content

能给 main 函数写一个资源释放代码吗? #45

Description

@nanfei01055

在我的应用中 tts 更常见的用法是实时朗读,拆分句子很可能是由上层调用软件来做的。每一句调用一次,而长篇调用的情景是不多的。比如我,就只是想用它来朗读小说或其它文章。

但我遇到一个问题,如果是调用 .exe,每次调用都要从头初始化,如果我每次调用只有一句话的时候,效率会大打折扣。如果一次调用传入多个句子,反应时间太长,跟不上朗读节奏。所以我打算将它改成一个动态链接库。

以下是我大致要修改成的样子,以免多次中、英、中英混合在一个项目无限次调用时出现内存泄漏。我需要资源释放的代码,我看到现在 main 中似乎并没有释放 model 和其它成员的代码,我自己写可能有难度。

‘’‘
#ifndef TTS_LIB_H
#define TTS_LIB_H

#ifdef __cplusplus
extern "C" {
#endif

struct ByteArray {
	const unsigned char* data;
	int length;
};

__declspec(dllexport) int __stdcall createTtsTask(const char* modelPath, const char* language);

__declspec(dllexport) void __stdcall closeTtsTask(int taskId);

__declspec(dllexport) int __stdcall getSpeakerCount(int taskId);

__declspec(dllexport) int __stdcall synthesize(int taskId, int speakerIndex, const char* text, ByteArray* result);

#ifdef __cplusplus
}
#endif

#endif /* TTS_LIB_H */
’‘’

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions