Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Jan 7, 2025
1 parent fb7c773 commit 7b86810
Show file tree
Hide file tree
Showing 36 changed files with 342 additions and 173 deletions.
152 changes: 79 additions & 73 deletions cpp/shareddllproxy/voiceroid2/ebyroid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace ebyroid
namespace
{

ApiAdapter *NewAdapter(const string &, const string &, const string &, float, float);
ApiAdapter *NewAdapter(const string &, const string &, const string &);
int __stdcall HiraganaCallback(EventReasonCode, int32_t, IntPtr);
int __stdcall SpeechCallback(EventReasonCode, int32_t, uint64_t, IntPtr);
inline pair<bool, string> WithDirecory(const char *dir, function<pair<bool, string>(void)> yield);
Expand All @@ -26,10 +26,10 @@ namespace ebyroid
delete api_adapter_;
}

Ebyroid *Ebyroid::Create(const string &base_dir, const string &dllpath, const string &voice, float volume, float speed)
Ebyroid *Ebyroid::Create(const string &base_dir, const string &dllpath, const string &voice)
{

ApiAdapter *adapter = NewAdapter(base_dir, dllpath, voice, volume, speed);
ApiAdapter *adapter = NewAdapter(base_dir, dllpath, voice);
Ebyroid *ebyroid = new Ebyroid(adapter);
return ebyroid;
}
Expand Down Expand Up @@ -64,7 +64,81 @@ namespace ebyroid
output = response.End();
return 0;
}

void Ebyroid::Setparam(float volume, float speed, float pitch)
{
uint32_t param_size = 0;
auto result = api_adapter_->GetParam((void *)0, &param_size);
if (result != ERR_INSUFFICIENT)
{ // NOTE: Code -20 is expected here
string message = "API Get Param failed (Could not acquire the size) with code ";
message += std::to_string(result);
throw std::runtime_error(message);
}
if (param_size == sizeof(TTtsParam))
{ // voiceroid2
TTtsParam param;
// TTtsParam* param = (TTtsParam*) param_buffer;
param.size = param_size;
result = api_adapter_->GetParam(&param, &param_size);
if (result != ERR_SUCCESS)
{
string message = "API Get Param failed with code ";
message += std::to_string(result);
throw std::runtime_error(message);
}
param.extend_format = BOTH;
param.proc_text_buf = HiraganaCallback;
param.proc_raw_buf = SpeechCallback;
param.proc_event_tts = nullptr;
param.len_raw_buf_bytes = kConfigRawbufSize;

param.volume = volume;
param.speaker[0].volume = volume;
/*
param.speaker[0].pause_middle = 80;
param.speaker[0].pause_sentence = 200;
param.speaker[0].pause_long = 100;
param.speaker[0].range = 0.893;*/
param.speaker[0].speed = speed;
param.speaker[0].pitch = pitch;
result = api_adapter_->SetParam(&param);
if (result != ERR_SUCCESS)
{
string message = "API Set Param failed with code ";
message += std::to_string(result);
throw std::runtime_error(message);
}
}
else if (param_size == sizeof(AITalk_TTtsParam))
{ // voiceroid+
AITalk_TTtsParam param;
// TTtsParam* param = (TTtsParam*) param_buffer;
param.size = param_size;
result = api_adapter_->GetParam(&param, &param_size);
if (result != ERR_SUCCESS)
{
string message = "API Get Param failed with code ";
message += std::to_string(result);
throw std::runtime_error(message);
}
param.proc_text_buf = HiraganaCallback;
param.proc_raw_buf = SpeechCallback;
param.proc_event_tts = nullptr;
param.lenRawBufBytes = kConfigRawbufSize;

param.volume = volume;
param.Speaker[0].volume = volume;
param.Speaker[0].speed = speed;
param.Speaker[0].pitch = pitch;
result = api_adapter_->SetParam(&param);
if (result != ERR_SUCCESS)
{
string message = "API Set Param failed with code ";
message += std::to_string(result);
throw std::runtime_error(message);
}
}
}
int Ebyroid::Speech(const char *inbytes, std::vector<int16_t> &output, uint32_t mode)
{
Response<int16_t> response{api_adapter_};
Expand All @@ -73,7 +147,6 @@ namespace ebyroid
param.mode_in_out = mode == 0u ? IOMODE_AIKANA_TO_WAVE : (JobInOut)mode;
param.user_data = &response;


int32_t job_id;
ResultCode result = api_adapter_->TextToSpeech(&job_id, &param, inbytes);

Expand Down Expand Up @@ -104,7 +177,7 @@ namespace ebyroid
namespace
{

ApiAdapter *NewAdapter(const string &base_dir, const string &dllpath, const string &voice, float volume, float speed)
ApiAdapter *NewAdapter(const string &base_dir, const string &dllpath, const string &voice)
{
SettingsBuilder builder(base_dir, voice);
Settings settings = builder.Build();
Expand Down Expand Up @@ -139,74 +212,7 @@ namespace ebyroid
message += std::to_string(result);
throw std::runtime_error(message);
}
uint32_t param_size = 0;
result = adapter->GetParam((void *)0, &param_size);
if (result != ERR_INSUFFICIENT)
{ // NOTE: Code -20 is expected here
string message = "API Get Param failed (Could not acquire the size) with code ";
message += std::to_string(result);
throw std::runtime_error(message);
}
if (param_size == sizeof(TTtsParam))
{ // voiceroid2
TTtsParam param;
// TTtsParam* param = (TTtsParam*) param_buffer;
param.size = param_size;
result = adapter->GetParam(&param, &param_size);
if (result != ERR_SUCCESS)
{
string message = "API Get Param failed with code ";
message += std::to_string(result);
throw std::runtime_error(message);
}
param.extend_format = BOTH;
param.proc_text_buf = HiraganaCallback;
param.proc_raw_buf = SpeechCallback;
param.proc_event_tts = nullptr;
param.len_raw_buf_bytes = kConfigRawbufSize;

param.volume = volume;
param.speaker[0].volume = volume;
/*param.speaker[0].pitch = 1.111;
param.speaker[0].pause_middle = 80;
param.speaker[0].pause_sentence = 200;
param.speaker[0].pause_long = 100;
param.speaker[0].range = 0.893;*/
param.speaker[0].speed = speed;
result = adapter->SetParam(&param);
if (result != ERR_SUCCESS)
{
string message = "API Set Param failed with code ";
message += std::to_string(result);
throw std::runtime_error(message);
}
}
else if (param_size == sizeof(AITalk_TTtsParam))
{ // voiceroid+
AITalk_TTtsParam param;
// TTtsParam* param = (TTtsParam*) param_buffer;
param.size = param_size;
result = adapter->GetParam(&param, &param_size);
if (result != ERR_SUCCESS)
{
string message = "API Get Param failed with code ";
message += std::to_string(result);
throw std::runtime_error(message);
}
param.proc_text_buf = HiraganaCallback;
param.proc_raw_buf = SpeechCallback;
param.proc_event_tts = nullptr;
param.lenRawBufBytes = kConfigRawbufSize;

param.volume = volume;
result = adapter->SetParam(&param);
if (result != ERR_SUCCESS)
{
string message = "API Set Param failed with code ";
message += std::to_string(result);
throw std::runtime_error(message);
}
}
auto _ = adapter.get();
adapter.release();
return _;
Expand Down
9 changes: 3 additions & 6 deletions cpp/shareddllproxy/voiceroid2/ebyroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ namespace ebyroid
Ebyroid(Ebyroid &&) = delete;
~Ebyroid();

static Ebyroid *Create(const std::string &base_dir, const std::string &dllpath, const std::string &voice, float volume, float speed);
static Ebyroid *Create(const std::string &base_dir, const std::string &dllpath, const std::string &voice);
int Hiragana(const char *inbytes, std::vector<char> &);
int Speech(const char *inbytes, std::vector<int16_t> &, uint32_t mode = 0u);
int Convert(const ConvertParams &params,
const unsigned char *inbytes,
int16_t **outbytes,
size_t *outsize);

private:
Ebyroid(ApiAdapter *api_adapter) : api_adapter_(api_adapter) {}
ApiAdapter *api_adapter_;
public:
void Setparam(float volume, float speed, float pitch);
};

template <typename T>
Expand Down
18 changes: 8 additions & 10 deletions cpp/shareddllproxy/voiceroid2/voice2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,19 @@ int voiceroid2wmain(int argc, wchar_t *wargv[])
float _rate;
if (!ReadFile(hPipe, &_rate, 4, &_, NULL))
break;
if ((voice != last) || (rate != _rate))
float _pitch;
if (!ReadFile(hPipe, &_pitch, 4, &_, NULL))
break;
if (voice != last)
{
last = voice;
rate = _rate;
if (ebyroid)
{
delete ebyroid;
}
ebyroid = Ebyroid::Create(argv[1], //"C:\\dataH\\Yukari2",
ebyroid = Ebyroid::Create(argv[1],
argv[2],
voice.c_str(),
2,
rate); // 1); //0.1-2,0.5-4
voice.c_str());
last = voice;
}

ebyroid->Setparam(2, _rate, _pitch); // 0.5-4, 0.5-2
ZeroMemory(input_j, sizeof(input_j));
if (!ReadFile(hPipe, input_j, 4096, &_, NULL))
break;
Expand Down
4 changes: 2 additions & 2 deletions cpp/version.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

set(VERSION_MAJOR 6)
set(VERSION_MINOR 17)
set(VERSION_PATCH 8)
set(VERSION_MINOR 18)
set(VERSION_PATCH 0)
set(VERSION_REVISION 0)
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp)
Expand Down
Loading

0 comments on commit 7b86810

Please sign in to comment.