forked from rhasspy/piper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
175 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#include "piper.hpp" | ||
#include "piperlib.hpp" | ||
#include <cstring> | ||
|
||
extern "C" | ||
{ | ||
eSpeakConfig* create_eSpeakConfig() { | ||
return new eSpeakConfig(); | ||
} | ||
|
||
void destroy_eSpeakConfig(eSpeakConfig* config) { | ||
delete config; | ||
} | ||
|
||
PiperConfig* create_PiperConfig(char* eSpeakDataPath) { | ||
auto config = new PiperConfig(); | ||
config->eSpeakDataPath = eSpeakDataPath; | ||
return config; | ||
} | ||
|
||
void destroy_PiperConfig(PiperConfig* config) { | ||
delete config; | ||
} | ||
|
||
PhonemizeConfig* create_PhonemizeConfig() { | ||
return new PhonemizeConfig(); | ||
} | ||
|
||
void destroy_PhonemizeConfig(PhonemizeConfig* config) { | ||
delete config; | ||
} | ||
|
||
SynthesisConfig* create_SynthesisConfig() { | ||
return new SynthesisConfig(); | ||
} | ||
|
||
void destroy_SynthesisConfig(SynthesisConfig* config) { | ||
delete config; | ||
} | ||
|
||
ModelConfig* create_ModelConfig() { | ||
return new ModelConfig(); | ||
} | ||
|
||
void destroy_ModelConfig(ModelConfig* config) { | ||
delete config; | ||
} | ||
|
||
ModelSession* create_ModelSession() { | ||
return new ModelSession(); | ||
} | ||
|
||
void destroy_ModelSession(ModelSession* config) { | ||
delete config; | ||
} | ||
|
||
SynthesisResult* create_SynthesisResult() { | ||
return new SynthesisResult(); | ||
} | ||
|
||
void destroy_SynthesisResult(SynthesisResult* config) { | ||
delete config; | ||
} | ||
|
||
Voice* create_Voice() { | ||
return new Voice(); | ||
} | ||
|
||
void destroy_Voice(Voice* voice) { | ||
delete voice; | ||
} | ||
|
||
bool isSingleCodepoint(const char* s) { | ||
std::string str(s); | ||
return piper::isSingleCodepoint(str); | ||
} | ||
|
||
char32_t getCodepoint(const char* s) { | ||
return piper::getCodepoint(s); | ||
} | ||
|
||
char* getVersion() { | ||
auto version = piper::getVersion(); | ||
char* cstr = new char[version.size() + 1]; | ||
std::strcpy(cstr, version.c_str()); | ||
return cstr; | ||
} | ||
|
||
void initializePiper(PiperConfig* config) { | ||
piper::initialize(*config); | ||
} | ||
|
||
void terminatePiper(PiperConfig* config) { | ||
piper::terminate(*config); | ||
} | ||
|
||
SynthesisConfig getSynthesisConfig(Voice* voice) { | ||
return voice->synthesisConfig; | ||
} | ||
|
||
void loadVoice(PiperConfig* config, const char* modelPath, const char* modelConfigPath, Voice* voice, int64_t* speakerId) { | ||
std::optional<piper::SpeakerId> optSpeakerId; | ||
if (speakerId) { | ||
optSpeakerId = *speakerId; | ||
} | ||
piper::loadVoice(*config, modelPath, modelConfigPath, *voice, optSpeakerId); | ||
} | ||
|
||
void textToAudio(PiperConfig* config, Voice* voice, const char* text, SynthesisResult* result, AudioCallback audioCallback) { | ||
std::vector<int16_t> audioBuf; | ||
piper::textToAudio(*config, *voice, text, audioBuf, *result, [&audioBuf, audioCallback] { audioCallback(audioBuf.data(), audioBuf.size()); }); | ||
} | ||
|
||
void textToWavFile(PiperConfig* config, Voice* voice, const char* text, const char* audioFile, SynthesisResult* result) { | ||
std::string audioFilePath = audioFile; | ||
std::ofstream audioFileStream(audioFilePath, std::ios::binary); | ||
piper::textToWavFile(*config, *voice, text, audioFileStream, *result); | ||
audioFileStream << "opened"; | ||
audioFileStream.flush(); | ||
audioFileStream.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include "piper.hpp" | ||
|
||
using namespace piper; | ||
|
||
#if defined(_WIN32) && !defined(__MINGW32__) | ||
# define PIPER_API __declspec(dllexport) | ||
#else | ||
# define PIPER_API __attribute__ ((visibility ("default"))) | ||
#endif | ||
|
||
extern "C" { | ||
typedef void (*AudioCallback)(int16_t* audioBuffer, int length); | ||
|
||
PIPER_API eSpeakConfig* create_eSpeakConfig(); | ||
PIPER_API void destroy_eSpeakConfig(eSpeakConfig* config); | ||
PIPER_API PiperConfig* create_PiperConfig(char* eSpeakDataPath); | ||
PIPER_API void destroy_PiperConfig(PiperConfig* config); | ||
PIPER_API PhonemizeConfig* create_PhonemizeConfig(); | ||
PIPER_API void destroy_PhonemizeConfig(PhonemizeConfig* config); | ||
PIPER_API SynthesisConfig* create_SynthesisConfig(); | ||
PIPER_API void destroy_SynthesisConfig(SynthesisConfig* config); | ||
PIPER_API ModelConfig* create_ModelConfig(); | ||
PIPER_API void destroy_ModelConfig(ModelConfig* config); | ||
PIPER_API ModelSession* create_ModelSession(); | ||
PIPER_API void destroy_ModelSession(ModelSession* config); | ||
PIPER_API SynthesisResult* create_SynthesisResult(); | ||
PIPER_API void destroy_SynthesisResult(SynthesisResult* config); | ||
PIPER_API Voice* create_Voice(); | ||
PIPER_API void destroy_Voice(Voice* voice); | ||
|
||
PIPER_API bool isSingleCodepoint(const char* s); | ||
PIPER_API char32_t getCodepoint(const char* s); | ||
PIPER_API char* getVersion(); | ||
PIPER_API void initializePiper(PiperConfig* config); | ||
PIPER_API void terminatePiper(PiperConfig* config); | ||
PIPER_API SynthesisConfig getSynthesisConfig(Voice* voice); | ||
PIPER_API void loadVoice(PiperConfig* config, const char* modelPath, const char* modelConfigPath, Voice* voice, SpeakerId* speakerId); | ||
PIPER_API void textToAudio(PiperConfig* config, Voice* voice, const char* text, SynthesisResult* result, AudioCallback audioCallback); | ||
PIPER_API void textToWavFile(PiperConfig* config, Voice* voice, const char* text, const char* audioFile, SynthesisResult* result); | ||
} |