user2080934
user2080934

Reputation: 11

All code does not execute before the function is called

all. Thanks for the time any help is appreciated.

Here is my issue: I have written some code in "Windows Form VC++" that would take a text file perform a speech-To-Text on the file, using a flip of a Text-To-Speech algorithm. After the text is vocalized using MS "Speak" function it is then supposed to write to a textBox some header information and what was said. After that a count variable is updated and then another function is called that would synthesize another voice from a different direction.

The problem is that the first voice is synthesized correctly and at the right time, however before the header info and spoken words can be written into the textBox the second function is called and once it ends it fills the textBox with its information only. No information from the first is ever written into the textBox.

What could be causing this?? I tried delaying the call to the second function in several different ways with no success. I could sure use as much help as is out there. I both code snippets in this questions. Thank you in advance and I hope for assistance really really quick. Thanks again.

First code with call to second:

    for(ClickCount_ATCText = 0; ClickCount_ATCText < FilesSelected_ATC_A; ClickCount_ATCText++)
                   {
                     SetChannelVolumeLevel(ATC_OverLord);
                     PlaySound(TEXT("c:\\SSL_Sound\\AC_AudioBackground.wav"), NULL, SND_FILENAME);
                     //GetWavFilePath(ATC_OverLord);

                     //if(ClickCount_ATCText > (FilesSelected_ATC_A - 1))
                     //{
                        //ClickCount_ATCText = 0;
                     //}// End DataLink if statement

                    SpeechSynthesizer^ Vocalize     = gcnew SpeechSynthesizer();                                                    //Create a voice synthesizer instance.

                    string TTS_TxtPath              = ATC_TxtFiles[ClickCount_ATCText];                                             //The following two lines converts the standard string in to a system string for use in the StreamReader function.
                    String^ TTS_FilePath            = gcnew String(TTS_TxtPath.c_str());        

                    StreamReader^ FileRead          = gcnew StreamReader(TTS_FilePath);                                             //Get the text file from the path identified.
                    String^ AutoTTSFileRead         = FileRead->ReadToEnd();                                                        //Read the entire file and store the text characters in the string variable "AutoTTSFileRead".                              

                    Vocalize->Speak(AutoTTSFileRead);                                                                               //Vocalize the text in the textbox.

                  //Sleep(3000);                                                                                                    //Pause half a second before displaying the text. Not needed, but kept for reference.

                  //* The 6 lines code below provides a timestamp and formats the output of the data link message.
                    TextToSpeechTextbox->Text           = "                            Data Link Message \r\n \r\n";
                    time(&WhatTimeIsIt);
                    String^ strNew                      = gcnew String(ctime(&WhatTimeIsIt));
                    TextToSpeechTextbox->Text           = TextToSpeechTextbox->Text + "Timestamp: " + strNew + "\r\n"; 
                    TextToSpeechTextbox->Text           = TextToSpeechTextbox->Text + "\r\n";
                    TextToSpeechTextbox->Text           = TextToSpeechTextbox->Text + "Message:    " + AutoTTSFileRead + "\r\n";    //Display the speech data in the text box.             

                    ClickCount_ATCText++;   
                    NE_STT_SLL_Function();

                   }//End for loop   

**NE_STT_SLL_Function:**  

void NE_STT_SLL_Function() 
         {
            //Sleep(3000);

            SetChannelVolumeLevel(North_East);                              //Set the volume level for this SSL and zero the rest.

            PlaySound(TEXT("c:\\SSL_Sound\\AC_AudioBackground.wav"), NULL, SND_FILENAME);                                   //Play a snippet of radio noise in the background before sythesizing

            if(ClickCount_NorthEastText >= (FilesSelected_NE - 1))
              {
                 ClickCount_NorthEastText = 0;
              }// End DataLink if statement

            SpeechSynthesizer^ Vocalize     = gcnew SpeechSynthesizer();                                                    //Create a voice synthesizer instance.

            string TTS_TxtPath              = NorthEast_TxtFiles[ClickCount_NorthEastText];                                 //The following two lines converts the standard string in to a system string for use in the StreamReader function.
            String^ TTS_FilePath            = gcnew String(TTS_TxtPath.c_str());        

            StreamReader^ FileRead          = gcnew StreamReader(TTS_FilePath);                                             //Get the text file from the path identified.
            String^ AutoTTSFileRead         = FileRead->ReadToEnd();                                                        //Read the entire file and store the text characters in the string variable "AutoTTSFileRead".                              

            Vocalize->Speak(AutoTTSFileRead);                                                                               //Vocalize the text in the textbox.

            //* The 6 lines code below provides a timestamp and formats the output of the data link message.
            TextToSpeechTextbox->Text           = "                 (NE) Sound Source Location Message \r\n \r\n";
            time(&WhatTimeIsIt);
            String^ strNew                      = gcnew String(ctime(&WhatTimeIsIt));
            TextToSpeechTextbox->Text           = TextToSpeechTextbox->Text + "Timestamp: " + strNew + "\r\n"; 
            TextToSpeechTextbox->Text           = TextToSpeechTextbox->Text + "\r\n";
            TextToSpeechTextbox->Text           = TextToSpeechTextbox->Text + "Message:    " + AutoTTSFileRead + "\r\n";    //Display the speech data in the text box.  

            ClickCount_NorthEastText++; //Increment array index value.
            return;

          }//End NE STT SSL function

Upvotes: 0

Views: 63

Answers (1)

Jochen Kalmbach
Jochen Kalmbach

Reputation: 3684

A windows Forms application is based on a message loop. If the messagge loop has no time to execute, then nothing will be displayed or refreshed. If you change a text in a for-loop, only the last one will be displayed. Also be aware, that the Text2Speach is normally asynchonus. So the function returns even if the text was not spoken. So please use the finished event to process with your actions... (SpeechSynthesizer::SpeakCompleted)

Also you should never use Sleep or other tight loops in a windows UI application. Please consider to use a timer (Windows::Forms::Timer) or consider to use event-based processing!

Upvotes: 1

Related Questions