int AddVoice()

in installvoices/InstallVoices.cpp [169:223]


int AddVoice(const VoiceForSAPI& voiceForSapi)
{
	CComPtr<ISpObjectToken> cpToken;
	CComPtr<ISpDataKey> cpDataKeyAttribs;

	auto hr = SpCreateNewTokenEx(
		SPCAT_VOICES,
		const_cast<WCHAR *>(voiceForSapi.tokenKeyName.c_str()),
		&CLSID_PollyTTSEngine,
		const_cast<WCHAR*>(voiceForSapi.langDependentName.c_str()),
		voiceForSapi.langid,
		const_cast<WCHAR*>(voiceForSapi.langIndependentName.c_str()),
		&cpToken,
		&cpDataKeyAttribs);

	//--- Set additional attributes for searching and the path to the
	//    voice data file we just created.
	if (SUCCEEDED(hr))
	{
		hr = cpDataKeyAttribs->SetStringValue(L"Gender", voiceForSapi.gender.c_str());
		if (SUCCEEDED(hr))
		{
			hr = cpDataKeyAttribs->SetStringValue(L"Name", voiceForSapi.langIndependentName.c_str());
		}
		if (SUCCEEDED(hr))
		{
			hr = cpDataKeyAttribs->SetStringValue(L"VoiceId", voiceForSapi.voiceId.c_str());
		}
		if (SUCCEEDED(hr))
		{
			hr = cpDataKeyAttribs->SetStringValue(L"Language", voiceForSapi.languageText.c_str());
		}
		if (SUCCEEDED(hr))
		{
			hr = cpDataKeyAttribs->SetStringValue(L"Age", voiceForSapi.age.c_str());
		}
		if (SUCCEEDED(hr))
		{
			hr = cpDataKeyAttribs->SetStringValue(L"Vendor", voiceForSapi.vendor.c_str());
		}
		if (SUCCEEDED(hr))
		{
			hr = cpDataKeyAttribs->SetStringValue(L"IsNeural", voiceForSapi.hasNeural ? L"1" : L"0");
		}
		if (SUCCEEDED(hr))
		{
			hr = cpDataKeyAttribs->SetStringValue(L"IsNews", voiceForSapi.hasNewscasterStyle ? L"1" : L"0");
		}
		if (SUCCEEDED(hr))
		{
			hr = cpDataKeyAttribs->SetStringValue(L"IsConversational", voiceForSapi.hasConversationalStyle ? L"1" : L"0");
		}
	}
	return SUCCEEDED(hr);
}