所有。感谢您的时间任何帮助表示赞赏。
以下是我的问题: 我在“Windows Form VC ++”中编写了一些代码,该代码将文本文件对文件执行语音转文本,使用文本转语音算法的翻转。在使用MS“Speak”函数发出文本之后,它应该向textBox写入一些标题信息和所说的内容。之后更新计数变量,然后调用另一个函数,该函数将从不同的方向合成另一个声音。
问题是第一个语音是在正确的时间正确合成的,但是在标题信息和说出的单词可以写入textBox之前,第二个函数被调用,一旦它结束,它只用它的信息填充textBox 。没有第一个信息被写入textBox。
导致这种情况的原因是什么?我尝试以几种不同的方式将调用延迟到第二个函数但没有成功。我可以肯定会使用尽可能多的帮助。我在这个问题中都编码了代码片段。提前谢谢你,我希望真的很快得到帮助。再次感谢。
调用第二个代码的第一个代码:
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
答案 0 :(得分:1)
Windows窗体应用程序基于消息循环。如果messagge循环没有时间执行,则不会显示或刷新任何内容。如果更改for循环中的文本,则仅显示最后一个文本。另外请注意,Text2Speach通常是asynchonus。因此即使没有说出文本,函数也会返回。因此,请使用已完成的事件处理您的操作...(SpeechSynthesizer::SpeakCompleted)
此外,您不应该在Windows UI应用程序中使用Sleep或其他紧密循环。请考虑使用计时器(Windows :: Forms :: Timer)或考虑使用基于事件的处理!