//=========================================================================== // VOTRAX Speech Synthesizer // Nicholas Gessler // 4 December 2006 // Modified 27 September 2012 //=========================================================================== //=========================================================================== // BORLAND CODE //=========================================================================== #include #pragma hdrstop #include #include "Unit1.h" #include #include "Unit5.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- //=========================================================================== // GLOBAL VARIABLES //=========================================================================== // COM1 Communications Management Variables HANDLE hComm = NULL; COMMTIMEOUTS ctmoNew = {0}, ctmoOld; DWORD dwWritten = 0; using namespace std; // Votrax Variables char cr[1]; // for Carraige Return or "speak now" char phoneme[64]; // all the phonemes AnsiString utterance; int length; //=========================================================================== // FUNCTIONS //=========================================================================== //--------------------------------------------------------------------- SPEAK void speak (void) { WriteFile(hComm, utterance.c_str(), utterance.Length(),&dwWritten, NULL); WriteFile(hComm, &cr, 1, &dwWritten, NULL); } //------------------------------------------------------------- FLIP PICTURES void flipPix (void) { // make all images invisible Form1->ImageWopr1->Visible = false; Form1->ImageWopr2->Visible = false; Form1->ImageDisplayUS->Visible = false; // make a random image visible int choice = random(3); if (choice == 0) Form1->ImageWopr1->Visible = true; if (choice == 1) Form1->ImageWopr2->Visible = true; if (choice == 2) Form1->ImageDisplayUS->Visible = true; } //=========================================================================== // EVENT HANDLERS //=========================================================================== //------------------------------------------- Use this instead of Form Create __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { randomize(); DCB dcbCommPort; // OPEN THE COMM PORT. hComm = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); // IF THE PORT CANNOT BE OPENED, BAIL OUT. if(hComm == INVALID_HANDLE_VALUE) Application->Terminate(); // SET THE COMM TIMEOUTS IN OUR EXAMPLE. GetCommTimeouts(hComm,&ctmoOld); ctmoNew.ReadTotalTimeoutConstant = 10; ctmoNew.ReadTotalTimeoutMultiplier = 0; ctmoNew.WriteTotalTimeoutMultiplier = 0; ctmoNew.WriteTotalTimeoutConstant = 0; SetCommTimeouts(hComm, &ctmoNew); // SET BAUD RATE, PARITY, WORD SIZE, AND STOP BITS. // THERE ARE OTHER WAYS OF DOING SETTING THESE BUT THIS IS THE EASIEST. dcbCommPort.DCBlength = sizeof(DCB); GetCommState(hComm, &dcbCommPort); BuildCommDCB("9600,N,8,1", &dcbCommPort); SetCommState(hComm, &dcbCommPort); // INITIALIZE SOME PHONEMES // The entire Votrax phoneme set for (int i = 0; i < 64; i++) { phoneme[i] = i + 64; } // The carraige-return character which means "speak now" cr[0] = 13; } //---------------------------- COM1 COMMUNICATIONS MANAGEMENT - ON FORM CLOSE void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { // WAIT FOR THREAD TO TERMINATE, // PURGE THE INTERNAL COMM BUFFER, // RESTORE THE PREVIOUS TIMEOUT SETTINGS, // AND CLOSE THE COMM PORT. Sleep(250); PurgeComm(hComm, PURGE_RXABORT); SetCommTimeouts(hComm, &ctmoOld); CloseHandle(hComm); } //------------------------------------------------------- Votrax Hello Button void __fastcall TForm1::ButtonVotraxHelloClick(TObject *Sender) { utterance = "Hell low. I am votrax."; utterance += "I am the voice of whawppurr "; utterance += "in ~xx?uh movie ~C? war ~C? games."; utterance += "I can try to pronounce any tekst you enter."; utterance += "If I don't pronounce it korrectly,"; utterance += "you can adjust my speech by spelling things"; utterance += "differently, or by including ~xx?uh korrect phone neemes"; utterance += " beetween uh till day and ~xx?uh kwest shun mark."; speak(); Sleep(27000); flipPix(); } //------------------------------------------------------ Votrax Jabber Button void __fastcall TForm1::ButtonVotraxJabberClick(TObject *Sender) { for (int sentence = 0; sentence < 4; sentence++) { int syllables = random(30); int number[30]; for (int i = 0; i < 20; i++) { number[i] = random(63); } WriteFile(hComm, "~", 1, &dwWritten, NULL); for (int i = 0; i < syllables; i++) { WriteFile(hComm, &phoneme[number[i]], 1, &dwWritten, NULL); } WriteFile(hComm, "?", 1, &dwWritten, NULL); } WriteFile(hComm, &cr, 1, &dwWritten, NULL); flipPix(); } //------------------------------------------------- Show Phoneme Chart Button void __fastcall TForm1::ButtonPhonemeChartClick(TObject *Sender) { Form5->Visible = true; } //-------------------------------------- Votrax Pronounce All Phonemes Button void __fastcall TForm1::ButtonVotraxPronounceAllPhomenesClick(TObject *Sender) { for (int i = 0; i < 64; i++) { WriteFile(hComm, "~", 1, &dwWritten, NULL); WriteFile(hComm, &phoneme[i], 1, &dwWritten, NULL); WriteFile(hComm, &phoneme[i], 1, &dwWritten, NULL); WriteFile(hComm, &phoneme[i], 1, &dwWritten, NULL); WriteFile(hComm, &phoneme[i], 1, &dwWritten, NULL); WriteFile(hComm, "?", 1, &dwWritten, NULL); WriteFile(hComm, &cr, 1, &dwWritten, NULL); Sleep(800); EditPhonemeNumber->Text = i; Application->ProcessMessages(); } flipPix(); } //---------------------------------------------------- Votrax Shall We Button void __fastcall TForm1::ButtonVotraxShallWeClick(TObject *Sender) { utterance = "~Qoo?ll we playy a game?"; speak(); Sleep(2000); flipPix(); } //--------------------------------------------------- Votrax How About Button void __fastcall TForm1::ButtonVotraxHowAboutClick(TObject *Sender) { utterance = "How about a nice game of chess?"; speak(); Sleep(3000); flipPix(); } //----------------------------------------------- Votrax Strange Games Button void __fastcall TForm1::ButtonVotraxStrangeGamesClick(TObject *Sender) { utterance = "Strange games. The only winneeng move is not to play!"; speak(); Sleep(5000); flipPix(); } //------------------------------------------------------ Votrax Global Button void __fastcall TForm1::ButtonVotraxGlobalClick(TObject *Sender) { utterance = "~mV^? yew like two play ya ggame?"; utterance += "How about glowbooll thermownewcleyur warr?"; speak(); Sleep(5000); ImageWopr1->Visible = false; ImageWopr2->Visible = false; ImageDisplayUS->Visible = true; } //----------------------------------------------------- Movie Shall We Button void __fastcall TForm1::ButtonWoprShallWeClick(TObject *Sender) { PlaySound(MAKEINTRESOURCE(100), HInstance, SND_RESOURCE); flipPix(); } //---------------------------------------------------- Movie How About Button void __fastcall TForm1::ButtonWoprHowAboutClick(TObject *Sender) { PlaySound(MAKEINTRESOURCE(200), HInstance, SND_RESOURCE); flipPix(); } //------------------------------------------------ Movie Strange Games Button void __fastcall TForm1::ButtonWoprStrangeGamesClick(TObject *Sender) { PlaySound(MAKEINTRESOURCE(300), HInstance, SND_RESOURCE); flipPix(); } //--------------------------------------------------- Movie I Wouldn't Button void __fastcall TForm1::ButtonBerengerIWouldntClick(TObject *Sender) { PlaySound(MAKEINTRESOURCE(400), HInstance, SND_RESOURCE); flipPix(); } //----------------------------------------------------------- Say This Button void __fastcall TForm1::ButtonVotraxSayThisClick(TObject *Sender) { utterance = MemoSayThis->Text; speak(); flipPix(); } //----------------------------------------------------- Say This on Key Press void __fastcall TForm1::MemoSayThisKeyPress(TObject *Sender, char &Key) { // An Edit Box will give you a Windows "Clunk" sound... // Apparently entering "Key = 0;" after "speak();" will silence it... if (Key == VK_RETURN) { utterance = MemoSayThis->Text; speak(); flipPix(); } } //---------------------------------------------------------- That's All Folks