// C++ demo and test program for Fluency API // Copyright (C) 2008-2015 Fluency, Amsterdam // This version of the program requires Fluency TTS 8.0 or higher #include "stdafx.h" #include #include "FluencyAPI.h" // do not forget to also add FluencyAPI.cpp to your program! bool fluencyDone; // callback function for fluencySpeak and fluencySpeakToFile void WINAPI FLUENCYSYNC(unsigned Event, unsigned Param1, unsigned Param2, unsigned User) { switch (Event) { case SYNC_START: //printf("start\n"); break; case SYNC_PROGRESS: break; case SYNC_FINISH: //printf("\nfinish\n"); fluencyDone = TRUE; break; case SYNC_PHONEME: char p[3]; p[0] = (char)Param1; p[1] = (char)(Param1 >> 8); p[2] = (char)0; printf("%s ", p); break; case SYNC_BOOKMARK: printf("<%d> ", Param1); break; } } // main program int _tmain(int argc, _TCHAR* argv[]) { HINSTANCE hFluencyDLL; wchar_t Path[250]; wchar_t Wrd[200]; wchar_t NextWrd[200]; wchar_t Transcription[200]; int Voices; int i; wchar_t VoiceName[200]; void *Voice; void *Channel; char *Phone; void *Wav; unsigned TextIndex; unsigned Samples; unsigned WordLength; unsigned Bookmark; MSG Msg; // load DLL hFluencyDLL = fluencyLoadDLL(L""); if (hFluencyDLL) { // test GetVersion (can be called before Initialize) wprintf(L"Welcome to Fluency TTS %d.%d\n", fluencyGetMajorVersion(), fluencyGetMinorVersion()); if (fluencyGetMajorVersion() < 8) wprintf(L"\nWARNING: This program requires Fluency TTS 8.0 or higher!\n"); // initialize if (fluencyInitialize()) { // test AboutWindow //fluencyAboutWindow((HWND)0); // test fluencyGetUserDataPath fluencyGetUserDataPathW(Path, 250 * sizeof(wchar_t)); wprintf(L"\nSettings directory:\n%s\n", Path); // test fluencyAddWord //fluencyAddWordW(L"muflon", L"m*u-flOn"); // test fluencyLookupWord fluencyLookupWordW(L"muflon", Transcription, 200 * sizeof(wchar_t)); wprintf(L"\n\nTest fluencyLookupWord()\nmuflon=%s\n", Transcription); // test fluencyUserLexiconNextWord wprintf(L"\nTest fluencyUserLexiconNextWord()\n"); Wrd[0] = L'\0'; while (fluencyUserLexiconNextWordW(Wrd, NextWrd, 200 * sizeof(wchar_t))) { wprintf(L"%s ", NextWrd); wcscpy_s(Wrd, NextWrd); } wprintf(L"\n"); // test enumerate voices Voices = fluencyGetVoiceCount(); wprintf(L"\n%d voices:\n", Voices); for (i = 1; i <= Voices; i++) { fluencyGetVoiceNameW(i, VoiceName, 200 * sizeof(wchar_t)); wprintf(L"%s ", VoiceName); } // get preferred voice fluencyGetPreferredVoiceNameW(VoiceName, 200 * sizeof(wchar_t)); wprintf(L"\n\nPreferred voice: %s\n", VoiceName); // create voice and channel Voice = fluencyCreateVoiceW(VoiceName); Channel = fluencyCreateChannel(Voice, 0, TRUE); // test fluencyGetPhone() printf("\nTest synthesis with fluencyGetPhone() and fluencyGetBookmark()\n"); fluencySetInputTextW(Channel, L"\\bookmark=0\\ Hallo, \\bookmark=1\\ \\bookmark=2\\ dit is een test voor \\bookmark=3\\ Fluency TTS. \\bookmark=4\\"); while (fluencyGetPhone(Channel, &Phone, &Samples, &Wav, &TextIndex, &WordLength)) { while (fluencyGetBookmark(Channel, &Bookmark)) wprintf(L"<%d> ", Bookmark); printf("%s ", Phone); // note: Phone is only available as char* } // test set tempo/volume/balance fluencySetTempo(Channel, -4); fluencySetVolume(Channel, 40); fluencySetBalance(Channel, -60); // test fluencySpeakToFile() printf("\n\nTest synthesis with fluencySpeakToFile()\n"); fluencyDone = FALSE; fluencySetInputTextW(Channel, L"\\bookmark=0\\ Hallo, \\bookmark=1\\ \\bookmark=2\\ dit is een test voor \\bookmark=3\\ Fluency TTS. \\bookmark=4\\"); fluencySpeakToFileW(Channel, L"tmp.wav", &FLUENCYSYNC, 0); // sleep while Fluency TTS is writing to file while (!fluencyDone) Sleep(10); // test fluencySpeak() printf("\n\nTest synthesis and audio playback with fluencySpeak()\n"); fluencyDone = FALSE; fluencySetInputTextW(Channel, L"\\bookmark=0\\ Hallo, \\bookmark=1\\ \\bookmark=2\\ dit is een test voor \\bookmark=3\\ Fluency TTS. \\bookmark=4\\"); fluencySpeak(Channel, &FLUENCYSYNC, 0); // important: keep a message loop running while Fluency TTS is speaking while ((!fluencyDone) && (GetMessage(&Msg, 0, 0, 0))) { TranslateMessage(&Msg); DispatchMessage(&Msg); } // clean up fluencyDeleteChannel(Channel); fluencyDeleteVoice(Voice); fluencyClose(); } // free dll FreeLibrary(hFluencyDLL); } return 0; }