76 lines
2.6 KiB
C++
Raw Normal View History

2024-07-14 15:09:37 +08:00
std::optional<std::vector<byte>> _Speak(std::wstring &Content, const wchar_t *token, int voiceid, int rate, int volume);
2024-01-08 23:37:00 +08:00
2024-05-17 22:53:40 +08:00
std::vector<std::wstring> _List(const wchar_t *token);
2024-04-02 15:36:52 +08:00
int neospeechlist(int argc, wchar_t *argv[])
{
FILE *f = _wfopen(argv[1], L"wb");
for (auto key : {L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices", L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech_OneCore\\Voices"})
2024-03-23 18:33:58 +08:00
{
2024-04-02 15:36:52 +08:00
auto speechs = _List(key);
for (int i = 0; i < speechs.size(); i++)
{
if (speechs[i].substr(0, 2) == L"VW")
{
fwrite(speechs[i].c_str(), 1, speechs[i].size() * 2, f);
fwrite(L"\n", 1, 2, f);
fwrite(key, 1, wcslen(key) * 2, f);
fwrite(L"\n", 1, 2, f);
auto idx = std::to_wstring(i);
fwrite(idx.c_str(), 1, idx.size() * 2, f);
fwrite(L"\n", 1, 2, f);
2024-03-23 18:33:58 +08:00
}
2024-01-08 23:37:00 +08:00
}
}
2024-04-02 15:36:52 +08:00
fclose(f);
2024-03-23 18:33:58 +08:00
return 0;
}
2024-04-02 15:36:52 +08:00
int neospeech(int argc, wchar_t *argv[])
{
HANDLE hPipe = CreateNamedPipe(argv[1], 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-05-17 22:53:40 +08:00
auto handle = CreateFileMappingW(INVALID_HANDLE_VALUE, &allAccess, PAGE_EXECUTE_READWRITE, 0, 1024 * 1024 * 10, argv[3]);
auto mapview = (char *)MapViewOfFile(handle, FILE_MAP_ALL_ACCESS | FILE_MAP_EXECUTE, 0, 0, 1024 * 1024 * 10);
memset(mapview, 0, 1024 * 1024 * 10);
2024-03-23 18:33:58 +08:00
SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[2]));
2024-04-02 15:36:52 +08:00
if (ConnectNamedPipe(hPipe, NULL) != NULL)
{
2024-03-23 18:33:58 +08:00
DWORD len = 0;
2024-04-02 15:36:52 +08:00
}
2024-08-05 19:56:47 +08:00
wchar_t text[10000];
DWORD _;
2024-04-02 15:36:52 +08:00
while (true)
{
2024-08-05 19:56:47 +08:00
ZeroMemory(text, sizeof(text));
2024-03-23 18:33:58 +08:00
int speed;
2024-04-02 15:36:52 +08:00
if (!ReadFile(hPipe, (unsigned char *)&speed, 4, &_, NULL))
break;
if (!ReadFile(hPipe, (unsigned char *)text, 10000 * 2, &_, NULL))
break;
2024-03-23 18:33:58 +08:00
std::wstring content = text;
2024-05-17 22:53:40 +08:00
int fsize;
2024-08-05 19:56:47 +08:00
ZeroMemory(text, sizeof(text));
if (!ReadFile(hPipe, (unsigned char *)text, 10000 * 2, &_, NULL))
break;
std::wstring hkey = text;
int idx;
if (!ReadFile(hPipe, &idx, 4, &_, NULL))
break;
ZeroMemory(text, sizeof(text));
auto data = std::move(_Speak(content, hkey.c_str(), idx, speed, 100));
2024-07-14 15:09:37 +08:00
if (data)
{
memcpy(mapview, data.value().data(), data.value().size());
fsize = data.value().size();
WriteFile(hPipe, &fsize, 4, &_, NULL);
}
else
{
fsize = 0;
WriteFile(hPipe, &fsize, 4, &_, NULL);
}
2024-04-02 15:36:52 +08:00
}
return 0;
2024-01-08 23:37:00 +08:00
}