Simulation vocale, la machine vous parle.

Simulation vocale, la machine vous parle.

ISpVoice_Speak

Voir version :

Pas de dépendances

Télécharger :

#define COBJMACROS
#include <sapi.h>
#include <stdio.h>

#pragma comment(lib, "sapi.lib")
#pragma comment(lib, "ole32.lib")

ISpVoice *initvoice(unsigned short volume, long rate)
{
    ISpVoice *pVoice = 0;
    if(CoCreateInstance(&CLSID_SpVoice, 0, CLSCTX_ALL, &IID_ISpVoice, (void **)&pVoice) >= 0) 
    {
        ISpVoice_SetVolume(pVoice, volume);
        ISpVoice_SetRate(pVoice, rate);
    }
    return pVoice;
}

void speak(ISpVoice *pVoice, const wchar_t *text)
{
    printf("%S\n",text);
    ISpVoice_Speak(pVoice, text, SPF_IS_XML, 0);
}

void freevoice(ISpVoice *pVoice)
{
    if(pVoice) 
    {
        ISpVoice_Release(pVoice);
        pVoice = 0;
    }
}

int main(void)
{
    if(CoInitialize(0) >= 0) 
    {
        ISpVoice *pVoice = initvoice(100, -4);
        if(pVoice) 
        {
            speak(pVoice, L"I just test these functions and put it on my samplepage.");            
            speak(pVoice, L"It seems to work, thank you magma for posting these functions of the forum siteduzero.");            
            speak(pVoice, L"Essayons de parler français maintenant, je pense cependant que ça va être mauvais...");            
            freevoice(pVoice);
        }
        CoUninitialize();
    }
    return 0;
}



Commentaires

	Voici un programme vraiment sympathique, qui va vous permettre de faire parler votre machine.
	Trouvé sur le site du zéro, posté par magma.

	http://www.siteduzero.com/forum-83-813491-p1-peut-on-dire-je-t-aime-en-c.html#r7789671

	Le programme se comprend bien, on initialise une ISpVoice, et on envoie des phrases avec ISpVoice_Speak.
	Je n'ai pas encore essayé les différents paramètres.