64 lines
2.2 KiB
C++
Raw Normal View History

2024-05-17 22:53:40 +08:00
bool _Speak(std::wstring &Content, const wchar_t *token, int voiceid, int rate, int volume, int *length, char **buffer);
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[])
{
auto hkey = argv[4];
auto idx = std::stoi(argv[5]);
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-03-23 18:33:58 +08:00
int II = 0;
2024-04-02 15:36:52 +08:00
while (true)
{
wchar_t text[10000];
2024-03-23 18:33:58 +08:00
II += 1;
DWORD _;
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;
char *buff;
_Speak(content, hkey, idx, speed, 100, &fsize, &buff);
memcpy(mapview, buff, fsize);
delete buff;
WriteFile(hPipe, &fsize, 4, &_, NULL);
2024-04-02 15:36:52 +08:00
}
return 0;
2024-01-08 23:37:00 +08:00
}