/* Modification of cmdlinespeak source included in ViaVoice OutLoud package. */ // First created: Dec 13, 1999 // Modified by: Andrew Plumb // E-mail me at: andrew@plumb.org // Requires IBM's ViaVoice Outloud Runtime kit for speech synthesis package, // available at: // http://www.ibm.com/viavoice/dev_home.html // Application to Output text from the command line // Modified from original pipespeak.cpp to include switches for setting // voice used. #include #include #include #include #include #include #include int main (int argc, char * argv[], int envc, char * envv[]) { int ret; int maxlength=255; int lineNum = 1; int espklen; char speakervoice[maxlength]; ECIHand hECI; FILE *ECICheck; char lineread[maxlength]; char endspeak[maxlength]; char eciiniFile[maxlength]; if(getenv("ECIINI")) { strcpy(eciiniFile,getenv("ECIINI")); // cout << "ECIINI Environment variable set to: " << eciiniFile << endl; } else { eciiniFile="/usr/lib/ViaVoiceOutloud/samples/cmdlinespeak/eci.ini"; setenv("ECIINI",eciiniFile,1); } endspeak="`v2 Finished.\n"; hECI = eciNew(); // create a new ECI instance #ifdef FILEOUTPUT // output to file - set name to temp.au ret=eciSetOutputFilename(hECI,"temp.au"); // cout << "ret=" << ret << " from eciSetOutputFilename\n"; #else // output to device - default device is 0 ret=eciSetOutputDevice(hECI, 0); // cout << "ret=" << ret << " from eciSetOutputDevice\n"; #endif // Read in switches for setting the initial voice strcpy(speakervoice,""); strcpy(lineread,""); if ( argc >= 2 ) { char temp[maxlength]; // speak all arguments; change switches into ` format voice commands for (int i=1; i=argc) { cerr << "No argument provided for the -done command; exiting.\n"; return 1; } strcpy(endspeak,argv[i++]); strcpy(temp,""); // cout << "Done phrase is: " << endspeak << endl; } else if (strcmp(temp,"-eciini")==0) { // Place holder with bounds checking for specifying the eciini file // from the command line, instead of as an environment variable // to allow for multiple eciini files and independence from shell // configuration issues. // cout << "Doing -eciini processing...\n"; if(i>=argc) { cerr << "No argument provided for the -eciini command; exiting.\n"; return 1; } strcpy(temp,""); strcpy(eciiniFile,argv[i++]); setenv("ECIINI",eciiniFile,1); } else { // otherwise treat the switch as a backquoted Outloud voice command temp[0]='`'; } } strcat(temp," "); strcat(speakervoice,temp); // cout << "Header phrase is now: " << speakervoice << endl; } strcpy(lineread,speakervoice); // cout << "Total header phrase is: " << speakervoice << endl; // Check that ECIINI points to a file that exists strcpy(eciiniFile,getenv("ECIINI")); if ( ECICheck=fopen(eciiniFile,"r") ) { fclose(ECICheck); // cout << "ECIINI variable set to " << getenv("ECIINI") << " by the -eciini switch.\n"; } else { cerr << "The ECIINI file " << getenv("ECIINI") << " does not exist. Text will not be spoken by ViaVoice Outloud. Please set your ECIINI environment variable, or use the -eciini command-line option.\n"; // return 1; } ret=eciSetParam(hECI,eciInputType,1); ret=eciAddText(hECI,lineread); ret=eciSynthesize(hECI); ret=eciSynchronize(hECI); } while ( !cin.fail() && !cin.eof() ) { // Get next line of text and echo cin.getline( lineread, maxlength ); cout << lineread << endl; // set engine to parse annotated text ret=eciSetParam(hECI,eciInputType,1); // Add text to engine ret=eciAddText(hECI,lineread); // cout << "ret=" << ret << " from eciAddText\n"; // Begin synthesis of Text ret=eciSynthesize(hECI); // cout << "ret=" << ret << " from eciSynthesize\n"; // Synchronize. This will wait until all text is processed. ret=eciSynchronize(hECI); // cout << "ret=" << ret << " from eciSynchronize\n"; } if ( cin.fail() && !cin.eof() ) { cerr << "Unable to open pipe for input" << endl; } else { strcat(lineread,endspeak); // cout << lineread; ret=eciSetParam(hECI,eciInputType,1); ret=eciAddText(hECI,lineread); ret=eciSynthesize(hECI); ret=eciSynchronize(hECI); } // Delete the instance eciDelete(hECI); return 0; }