Esempio n. 1
0
static int speak_buffer (const char *buf, int (*should_stop)())
{
    ISpVoice *v = NULL;
    WCHAR *w;
    char line[2048];

    v = get_sapi_voice();
    if (v == NULL) return 1;

    bufgets_init(buf);

    while (bufgets(line, sizeof line, buf)) {
        if (should_stop()) {
            ISpVoice_Speak(v, L"OK, stopping", 0, NULL);
            break;
        }
        tailstrip(line);
        w = wide_string(line);
        ISpVoice_Speak(v, w, 0, NULL);
        free(w);
    }

    bufgets_finalize(buf);

    release_sapi_voice(v);

    return 0;
}
Esempio n. 2
0
static void speak_dataset_comments (const dataset *dset)
{
    int i;
    ISpVoice *v = NULL;
    HRESULT hr;

    hr = CoInitialize(NULL);
    if (!SUCCEEDED(hr)) {
        fprintf(stderr, "CoInitialize failed\n");
        return;
    }

    hr = CoCreateInstance(&CLSID_SpVoice, 
                          NULL, 
                          CLSCTX_ALL, 
                          &IID_ISpVoice, 
                          (void *) &v); 

    if (SUCCEEDED(hr)) {
	for (i=0; i<N_COMMENTS; i++) {
	    if (dset->comments[i] != NULL) {
		WCHAR *w = wide_string(dset->comments[i]);

		ISpVoice_Speak(v, w, 0, NULL);
		free(w);
	    }
	}
        ISpVoice_Release(v);
    } 

    CoUninitialize();
}
Esempio n. 3
0
static int speak_line (const char *line)
{
    static ISpVoice *v = NULL;

    if (line == NULL) {
        if (v != NULL) {
            release_sapi_voice(v);
        }
        return 0;
    }

    if (v == NULL) {
        v = get_sapi_voice();
    }

    if (v != NULL) {
        WCHAR *w = wide_string(line);

        ISpVoice_Speak(v, w, 0, NULL);
        free(w);
    } else {
        return 1;
    }

    return 0;
}
Esempio n. 4
0
void Speak(void * pV, const wchar_t * pwcs, void * pToken, PPNVOICE pVoices){
	ISpVoice		*pVoice = pV;
	PPNVOICE		voice = NULL;
	wchar_t			*pBuffer = NULL;

	pBuffer = calloc(wcslen(pwcs) + 256, sizeof(wchar_t));
	if(pVoice && pBuffer){
		if(pToken != NULL){
			ISpVoice_SetVoice(pVoice, (ISpObjectToken *)pToken);
		}
		voice = GetVoiceByToken(pVoices, (DWORD)pToken);
		if(voice){
			swprintf(pBuffer, wcslen(pwcs) + 256, L"<volume level = '%d'/><rate absspeed = '%d'/><pitch middle = '%d'/> %ls", voice->volume, voice->rate, voice->pitch, pwcs);
		}
		else{
			wcscat(pBuffer, pwcs);
		}
		ISpVoice_Speak(pVoice, pBuffer, SPF_ASYNC | SPF_PURGEBEFORESPEAK | SPF_IS_XML, NULL);
		free(pBuffer);
	}
}
Esempio n. 5
0
int
speech_sapi5_out(void *ifp, char* text)
{
    HRESULT hr;
    ISpVoice * pVoice = ifp;
    gunichar2* utf16_text;


    printf("speech_out_sapi5: %s\n", text);

    utf16_text = g_utf8_to_utf16(text, -1 /* zero terminated */,
                    NULL, NULL, NULL);
    if(utf16_text != NULL) {
        hr = ISpVoice_Speak(pVoice,utf16_text, 0, NULL);
        g_free(utf16_text);
        return SUCCEEDED(hr);
    }

    printf("speech_sapi5_out: failed to convert %s to utf16!\n", text);
    return FALSE;
}
Esempio n. 6
0
static void audio_graph_error (const char *msg)
{
#ifdef HAVE_FLITE
    cst_voice *v;
#endif
#ifdef WIN32_SAPI
    ISpVoice *v = NULL;
    HRESULT hr;
#endif    

    fprintf(stderr, "%s\n", msg);

#ifdef HAVE_FLITE
    flite_init();

    v = register_cmu_us_kal();
    flite_text_to_speech(msg, v, "play");
#endif
#ifdef WIN32_SAPI
    hr = CoInitialize(NULL);
    if (!SUCCEEDED(hr)) return;

    hr = CoCreateInstance(&CLSID_SpVoice, 
                          NULL, 
                          CLSCTX_ALL, 
                          &IID_ISpVoice, 
                          (void *) &v);
    if (SUCCEEDED(hr)) {
	wchar_t *w = wide_string(msg);

	ISpVoice_Speak(v, w, 0, NULL);
	free(w);
        ISpVoice_Release(v);
    } 
#endif
}
Esempio n. 7
0
void StopSpeak(void * pV){
	ISpVoice		*pVoice = pV;
	if(pVoice){
		ISpVoice_Speak(pVoice, NULL, SPF_PURGEBEFORESPEAK, NULL);
	}
}