58 lines
1.6 KiB
C++
Raw Normal View History

2024-01-08 23:37:00 +08:00

2024-04-02 15:36:52 +08:00
#include "define.h"
#include "cinterface.h"
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-01-08 23:37:00 +08:00
2024-04-02 15:36:52 +08:00
namespace SAPI
{
2024-05-17 22:53:40 +08:00
bool Speak(std::wstring &Content, int version, int voiceid, int rate, int volume, int *length, char **buffer);
2024-04-02 15:36:52 +08:00
std::vector<std::wstring> List(int version);
2024-01-08 23:37:00 +08:00
constexpr wchar_t SPCAT_VOICES_7[] = L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices";
constexpr wchar_t SPCAT_VOICES_10[] = L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech_OneCore\\Voices";
2024-04-02 15:36:52 +08:00
};
2024-01-08 23:37:00 +08:00
2024-05-17 22:53:40 +08:00
bool SAPI::Speak(std::wstring &Content, int version, int voiceid, int rate, int volume, int *length, char **buffer)
2024-04-02 15:36:52 +08:00
{
if (version == 7)
{
2024-05-17 22:53:40 +08:00
return _Speak(Content, SPCAT_VOICES_7, voiceid, rate, volume, length, buffer);
2024-01-08 23:37:00 +08:00
}
2024-04-02 15:36:52 +08:00
else if (version == 10)
{
2024-05-17 22:53:40 +08:00
return _Speak(Content, SPCAT_VOICES_10, voiceid, rate, volume, length, buffer);
2024-01-08 23:37:00 +08:00
}
2024-04-02 15:36:52 +08:00
else
{
2024-01-08 23:37:00 +08:00
return false;
}
}
2024-04-02 15:36:52 +08:00
std::vector<std::wstring> SAPI::List(int version)
{
if (version == 7)
{
2024-01-08 23:37:00 +08:00
return _List(SPCAT_VOICES_7);
}
2024-04-02 15:36:52 +08:00
else if (version == 10)
{
2024-01-08 23:37:00 +08:00
return _List(SPCAT_VOICES_10);
}
2024-04-02 15:36:52 +08:00
else
{
2024-01-08 23:37:00 +08:00
return {};
}
}
2024-05-17 22:53:40 +08:00
DECLARE bool SAPI_Speak(const wchar_t *Content, int version, int voiceid, int rate, int volume, int *length, char **buffer)
2024-04-02 15:36:52 +08:00
{
auto _c = std::wstring(Content);
2024-05-17 22:53:40 +08:00
return SAPI::Speak(_c, version, voiceid, rate, volume, length, buffer);
2024-01-08 23:37:00 +08:00
}
2024-04-02 15:36:52 +08:00
wchar_t **SAPI_List(int version, size_t *num)
{
auto _list = SAPI::List(version);
2024-01-08 23:37:00 +08:00
*num = _list.size();
return vecwstr2c(_list);
}