C/C++ 文字到语音

VS2015下实现把txt文档里面的内容用语音读出;

涉及:

1:读取txt文档内容;

2:用语音读出

CODE:

#define _ATL_APARTMENT_THREADED
//#include 
//extern CComModule _Module;
#include 
#include 
#include 
#include 

int main(int argc, char* argv[])
{
	ISpVoice * pVoice = NULL;

	if (FAILED(::CoInitialize(NULL)))
		return FALSE;

	HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
	if (SUCCEEDED(hr))
	{
		FILE* file;
		file = fopen("C:\\Users\\zhouchong\\Desktop\\txt\\auotomedian.txt", "r");
		if (file == NULL)
		{
			return 0;
		}
		else
		{
			char buff[1024];
			USES_CONVERSION;
			while (fgets(buff, 1024, file) != NULL)
			{
			//	hr = pVoice->Speak(L"Hello world", 0, NULL);
				wchar_t* test12 = A2W(buff);
				hr = pVoice->Speak(test12, 0, NULL);
				
			}
			pVoice->Release();
			pVoice = NULL;
		}
		::CoUninitialize();
	}

	return TRUE;
}

参考:

微软MSDN Text-to-Speech Tutorial:https://msdn.microsoft.com/en-us/library/ee125082(v=vs.85).aspx


你可能感兴趣的:(C++)