Created
July 2, 2019 17:01
-
-
Save JavierJF/65bf0d9182caf780b7397e3351654cdf to your computer and use it in GitHub Desktop.
Windows SAPI voice profile properties enumeration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pch.h" | |
#include <iostream> | |
#include <io.h> | |
#include <fcntl.h> | |
#include <Shlobj.h> | |
#include <string> | |
CComPtr<ISpObjectToken> createIspObjectToken() { | |
// Declare local identifiers: | |
HRESULT hr = S_OK; | |
CComPtr<ISpObjectWithToken> cpObjectWithToken; | |
CComPtr<ISpObjectToken> cpObjectToken; | |
hr = SpGetDefaultTokenFromCategoryId(SPCAT_VOICES, &cpObjectToken); | |
if (SUCCEEDED(hr)) | |
{ | |
hr = cpObjectToken->CreateInstance(NULL, CLSCTX_INPROC_SERVER, IID_ISpObjectWithToken, (void **)&cpObjectWithToken); | |
return cpObjectToken; | |
} else { | |
return NULL; | |
} | |
} | |
int main() { | |
CoInitialize(NULL); | |
// Declare local identifiers: | |
HRESULT hr = S_OK; | |
CComPtr<ISpRecognizer> cpRecognizer = NULL; | |
CComPtr<ISpObjectToken> cpObjectToken = NULL; | |
WCHAR *pwszRecoProfileName = NULL; | |
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize | |
// has already been called. | |
hr = CoCreateInstance(CLSID_SpInprocRecognizer, NULL, CLSCTX_INPROC_SERVER, IID_ISpRecognizer, (LPVOID*)&cpRecognizer); | |
// Get the current recognizer's recognition profile token. | |
hr = cpRecognizer->GetRecoProfile(&cpObjectToken); | |
if (SUCCEEDED(hr)) | |
{ | |
// Get the reco profile name (that is, the default value of the token). | |
hr = cpObjectToken->GetStringValue(NULL, &pwszRecoProfileName); | |
} | |
if (SUCCEEDED(hr)) | |
{ | |
// Do stuff here. | |
_setmode(_fileno(stdout), _O_U16TEXT); | |
std::wcout << L"Name: " << pwszRecoProfileName << "\r\n"; | |
LPWSTR strId = NULL; | |
cpObjectToken->GetId(&strId); | |
LPWSTR category = NULL; | |
BOOL moreKeys = true; | |
int32_t tokenIndex = 0; | |
while (moreKeys) { | |
LPWSTR keyStr = NULL; | |
hr = cpObjectToken->EnumKeys(tokenIndex, &keyStr); | |
if (SUCCEEDED(hr)) { | |
std::wcout << L"Key: " << keyStr << "\r\n"; | |
CoTaskMemFree(keyStr); | |
} else if (hr == SPERR_NO_MORE_ITEMS) { | |
moreKeys = FALSE; | |
} | |
tokenIndex = tokenIndex + 1; | |
} | |
std::wcout << L"\r\n"; | |
LPWSTR valueStr = NULL; | |
BOOL moreValues = true; | |
int32_t valueIndex = 0; | |
while (moreValues) { | |
hr = cpObjectToken->EnumValues(valueIndex, &valueStr); | |
if (SUCCEEDED(hr)) { | |
std::wcout << L"Value: " << valueStr << "\r\n"; | |
CoTaskMemFree(valueStr); | |
} else if (hr == SPERR_NO_MORE_ITEMS) { | |
moreValues = false; | |
} | |
valueIndex = valueIndex + 1; | |
} | |
_setmode(_fileno(stdout), _O_TEXT); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment