有没有好的办法在VC中把字符串转换成语音,并使它通过播放出来!

解决方案 »

  1.   

    TTS引擎,微软都帮你做好了。
      

  2.   

    tts好象只能读出英文,这样才能出读出中文。
      

  3.   

    #include <windows.h>
    #include <sapi.h>
    #include <wininet.h>
    #include <assert.h>
    #include <cstdio>
    #include <sphelper.h>
    #pragma comment(lib,"wininet")
    int main(int argc, char* argv[])
    {
        ISpVoice*                            pVoice ;
        ISpObjectToken*                        pVoiceToken;
        IEnumSpObjectTokens*                pEnum;    ULONG    ulCount=0;
        if (FAILED(::CoInitialize(NULL)))
            return FALSE;    HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
        if( SUCCEEDED( hr ) )
        {
            hr = SpEnumTokens(SPCAT_VOICES, NULL, NULL, &pEnum);
            
            if(SUCCEEDED(hr))
                hr = pEnum->GetCount(&ulCount);
            
            // Obtain a list of available voice tokens, set the voice to the token, and call Speak
            while (SUCCEEDED(hr) && ulCount -- )
            {
                if(SUCCEEDED(hr))
                    hr = pEnum->Next( 1, &pVoiceToken, NULL );
                
                if(SUCCEEDED(hr))
                    hr = pVoice->SetVoice(pVoiceToken);
                
                if(SUCCEEDED(hr))
                    hr = pVoice->Speak( L"How are you?", SPF_DEFAULT, NULL); 
                
                hr = pVoice->Speak(L"Hello world", 0, NULL);
                // Change pitch
                hr = pVoice->Speak(L"This sounds normal <pitch middle = '-10'/> but the pitch drops half way through", SPF_IS_XML, NULL );
                hr = pVoice->Speak(L"1234567&sup1;&thorn;&sup1;&thorn;", 0, NULL);            pVoiceToken->Release();
                pVoiceToken=NULL;        }        pVoice->Release();
            pVoice = NULL;
        }
        ::CoUninitialize();
        return TRUE;
        /*
        LPCSTR url="https://202.106.134.65/";
        HINTERNET    hInet=InternetOpen("",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,NULL);
        assert(hInet);
        HINTERNET    hHttps=InternetOpenUrl(hInet,url,NULL,NULL,NULL,NULL);
        assert(hHttps);
        ULONG  nRead=0;
        do{
            char Buffer[1024];
            Buffer[1000]=0;
            InternetReadFile(hHttps,Buffer,1000,&nRead);
            puts(Buffer);
        }while(nRead>0);
        InternetCloseHandle(hHttps);
        InternetCloseHandle(hInet);
    */
    }
      

  4.   

    多谢各位老大拔刀相助,TEXT TO SPEECH是实现了,但是只能读出英文啊,要读出中文有没有好办法?有没有这方面的中文引擎!
      

  5.   

    微软的TTS SDK5.0中有中文的
      

  6.   

    下载一个微软的TTS SDK5.0,安装后就有中文音库了。
    而且里面带详细的资料,例子。
      

  7.   

    多谢,另外下载了一个中文引擎,现在可以了。
    但是现在想把一个字符变量中的内容读出来,如:
    CString str;
    str="我们";
    hr = pVoice->Speak();
    现在要把str读出来,Speak()中应如何写呢!