89 lines
2.9 KiB
C++
Raw Normal View History

2024-01-08 23:37:00 +08:00
#include "ebyroid.h"
2024-04-02 15:36:52 +08:00
#include "api_adapter.h"
2024-01-08 23:37:00 +08:00
#include "ebyutil.h"
2024-04-02 15:36:52 +08:00
using ebyroid::Ebyroid;
#include "types.h"
int voiceroid2wmain(int argc, wchar_t *wargv[])
{
char **argv = new char *[argc];
2024-01-08 23:37:00 +08:00
for (int i = 0; i < argc; i++)
{
2024-05-17 16:25:05 +08:00
int length = WideCharToMultiByte(CP_ACP, 0, wargv[i], -1, NULL, 0, NULL, NULL);
2024-01-08 23:37:00 +08:00
argv[i] = new char[length];
2024-05-17 16:25:05 +08:00
WideCharToMultiByte(CP_ACP, 0, wargv[i], -1, argv[i], length, NULL, NULL);
2024-04-02 15:36:52 +08:00
}
2024-05-17 16:25:05 +08:00
HANDLE hPipe = CreateNamedPipeA(argv[6], PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 65535, 65535, NMPWAIT_WAIT_FOREVER, 0);
2024-01-08 23:37:00 +08:00
2024-04-02 15:36:52 +08:00
Ebyroid *ebyroid;
2024-01-08 23:37:00 +08:00
2024-04-02 15:36:52 +08:00
ebyroid = Ebyroid::Create((const char *)argv[1], //"C:\\dataH\\Yukari2",
(const char *)argv[2],
2024-05-17 16:25:05 +08:00
(const char *)argv[3], //"yukari_emo_44",
2,
2024-04-02 15:36:52 +08:00
atof((const char *)argv[5])); // 1); //0.1-2,0.5-4
2024-05-17 16:25:05 +08:00
auto handle = CreateFileMappingA(INVALID_HANDLE_VALUE, &allAccess, PAGE_EXECUTE_READWRITE, 0, 1024 * 1024 * 10, argv[8]);
auto mapview = (char *)MapViewOfFile(handle, FILE_MAP_ALL_ACCESS | FILE_MAP_EXECUTE, 0, 0, 1024 * 1024 * 10);
memset(mapview, 0, 1024 * 1024 * 10);
SetEvent(CreateEventA(&allAccess, FALSE, FALSE, argv[7]));
ConnectNamedPipe(hPipe, NULL);
2024-01-08 23:37:00 +08:00
int freq1 = atoi(argv[4]);
2024-04-02 15:36:52 +08:00
while (true)
{
unsigned char *out;
2024-01-08 23:37:00 +08:00
size_t output_size;
2024-04-02 15:36:52 +08:00
int16_t *out2;
2024-01-08 23:37:00 +08:00
2024-04-02 15:36:52 +08:00
unsigned char input_j[4096] = {0};
2024-01-08 23:37:00 +08:00
DWORD _;
2024-04-02 15:36:52 +08:00
if (!ReadFile(hPipe, input_j, 4096, &_, NULL))
break;
// int result = ebyroid->Hiragana((const unsigned char*)UnicodeToShift_jis(input), &out, &output_size);
int result = ebyroid->Hiragana((const unsigned char *)input_j, &out, &output_size);
2024-01-08 23:37:00 +08:00
result = ebyroid->Speech(out, &out2, &output_size);
int fsize = output_size + 44;
2024-05-17 16:25:05 +08:00
if (fsize > 1024 * 1024 * 10)
{
fsize = 0;
}
else
{
int ptr = 0;
memcpy(mapview, "RIFF", 4);
ptr += 4;
memcpy(mapview + ptr, &fsize, 4);
ptr += 4;
memcpy(mapview + ptr, "WAVEfmt ", 8);
ptr += 8;
memcpy(mapview + ptr, "\x10\x00\x00\x00\x01\x00\x01\x00", 8);
ptr += 8;
int freq = freq1;
memcpy(mapview + ptr, &freq, 4);
ptr += 4;
freq = freq * 2;
memcpy(mapview + ptr, &freq, 4);
ptr += 4;
memcpy(mapview + ptr, "\x02\x00\x10\x00", 4);
ptr += 4;
memcpy(mapview + ptr, "data", 4);
ptr += 4;
memcpy(mapview + ptr, &output_size, 4);
ptr += 4;
memcpy(mapview + ptr, out2, output_size);
}
WriteFile(hPipe, &fsize, 4, &_, NULL);
2024-01-08 23:37:00 +08:00
free(out);
free(out2);
}
2024-04-02 15:36:52 +08:00
// sndPlaySound((const char*)argv[6], SND_SYNC);
2024-01-08 23:37:00 +08:00
return 0;
}