Programme with Ekho
(updated on Apr 30, 2020)
For Linux Platform
First, install Ekho.
Second, try following simple example.
/* file try.cpp */ #include "config.h" // this file is generated when building Ekho #include "ekho.h" using namespace ekho; int main(int argc, char **argv) { Ekho wong("Cantonese"); wong.blockSpeak("123"); return 0; }
Third, compile and run it.
On linux platform, issue following commands (suppose we are under directory of Ekho and suppose Festival is not enabled):
$ g++ try.cpp libekho.a libmusicxml/libmusicxml2.a \ -I. -Iutfcpp/source -Isonic -lsndfile \ -lespeak-ng -pthread \ `pkg-config --libs libpulse-simple` `pkg-config --cflags libpulse-simple` $ ./a.out
Festival is a bit more complicated. If you have enabled it, you should add g++ flags yourself.
Check ekho.h for API.
For Windows Platform
You can use Ekho through SAPI5 on Windows. You need to install the SAPI5 SDK yourself first and read the document about how to use it. Following is a HelloWorld.
Note: The Ekho on Windows platform does not support English yet.
#include "stdafx.h" #include <iostream> #include <sapi.h> #include <sphelper.h> #include <atlcom.h> using namespace std; int main ( int NumOfArguments, char** Argument ) { HRESULT hr = S_OK; CComPtr<IEnumSpObjectTokens> cpEnum; ULONG ulCount = 0; ISpVoice * pSpVoice = NULL; CComPtr<ISpObjectToken> cpToken; // Initialize COM CoInitialize(NULL); // Create the voice interface object if (FAILED(CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_INPROC_SERVER, IID_ISpVoice, (void **)&pSpVoice))) { cerr << "Fail to create instance of ISpVoice!" << endl; return -1; } if (FAILED(SpEnumTokens(SPCAT_VOICES, L"Name=Ekho Cantonese", NULL, &cpEnum))) { cerr << "Fail to get voices!" << endl; return -1; } //Get the closest token if (FAILED(cpEnum->Next(1, &cpToken, NULL))) { cerr << "Fail to get voice EkhoVoice!" << endl; return -1; } //set the voice if (FAILED(pSpVoice->SetVoice( cpToken))) { cerr << "Fail to set voice EkhoVoice!" << endl; return -1; } pSpVoice->Speak(L"123", SPF_DEFAULT, NULL); // Shutdown COM CoUninitialize (); return 0; }
Email me (Cameron) or leave messages in the forum for further questions :-)