this was probably a bad idea to begin with since i've never messed with multithreading or the sapi... but i got the sapi working on its own, but when I put it in its own thread it wont speak anymore. I've tried over and over and over.... i'm not sure if this is the best attempt to post, but here it is, anyone have any ideas?

#include "sapi.h"
#include <process.h> 

HANDLE thread;


long WINAPI speakthread( PCHAR text );


void cmdSpeak( PCHAR text) {
	DWORD dwID;
	DWORD dwRetVal = 0;
	thread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)speakthread,text,0,&dwID);	

	dwRetVal = WaitForSingleObject(thread, INFINITE);

	CloseHandle(thread);
}



long WINAPI speakthread( PCHAR text ){
	ISpVoice* m_pVoice;
	HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&m_pVoice);
    if( SUCCEEDED( hr ) )
    {
		wchar_t* wszStr;
		int len = strlen(text);
		wszStr = new wchar_t[len + 50];
		mbstowcs(wszStr,text,len+1);	
		
        hr = m_pVoice->lpVtbl->Speak(m_pVoice,wszStr, 0, NULL);
		m_pVoice->lpVtbl->Release(m_pVoice);
        m_pVoice = NULL;
	}
	return 0;
}

I know this is messy... sorry. It's hard to be worried about elegance when half the crap I write doesnt work anyway =P

Tried finding answers via google, but info on multithreading seems kinda thin, or just way the hell over my head.

windows.h is included from another part of the project.

Recommended Answers

All 6 Replies

I don't know if it's the extra initialization, the flags, or the fact that this is in it's own function, but I call this function from a thread and it speaks fine.

// This function does the actual speaking of the generated TTS script
void CProgNameDlg::AudioTTS()
{
	ISpVoice* Voice = NULL;
	CoInitialize(NULL);
	CoCreateInstance ( CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void**)&Voice );
	Voice -> Speak(stuffToSay.AllocSysString(), SPF_DEFAULT, NULL);
}

PLEASE HELP.When I download SpeechSDK51.exe it doesn't work.I want SAPI work in my computer.
compiler said that
C:\Documents and Settings\lasha\Desktop\SAPI\SAPI.cpp(142) : error C2065: 'ISpVoice' : undeclared identifier
C:\Documents and Settings\lasha\Desktop\SAPI\SAPI.cpp(142) : error C2065: 'pVoice' : undeclared identifier
C:\Documents and Settings\lasha\Desktop\SAPI\SAPI.cpp(147) : error C2227: left of '->Speak' must point to class/struct/union

When I download SpeechSDK51.exe and when I execute it, it doesn't executes.

What should I do?

did you

#include "sapi.h"

It took you 1 year and 2 months to check that? :icon_eek:

It took you 1 year and 2 months to check that? :icon_eek:

I think I know what the problem might be. Let me put together some code and I'll let you know next March. :)

commented: Thanks for the laugh +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.