Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing or Copying Visual C++ console output to text file

I am working with Intel Perceptual Computing SDK Voice Recognition Module. Using Microsoft Visual Studio 2012 Professional, the SDK sample perceives the dictation and after processing the voice input prints it on the console window. All i want to do is to copy the output printed on console window and write it in a .txt file. I am following the general way but somehow the text written in file is just some numbers.

// Callback for recognized commands and alerts
class MyHandler: public PXCVoiceRecognition::Recognition::Handler, public    PXCVoiceRecognition::Alert::Handler 

{ public: MyHandler(std::vector &commands) { this->commands=commands; }

virtual void PXCAPI OnRecognized(PXCVoiceRecognition::Recognition *cmd) 
{
  wprintf_s(L"\nRecognized: <%s>\n", (cmd->label>=0)?commands[cmd->label]:cmd-    >dictation); //this line prints the dictated statement//
  // writing to a text file
  printf("Writing to the txt file...");
  std::ofstream out("c:\\MyVoice.txt");
  out<<cmd->dictation;
}

protected:
std::vector<pxcCHAR*> commands;

};

int wmain(int argc, wchar_t* argv[]) {
// Create session
PXCSmartPtr<PXCSession> session;
pxcStatus sts = PXCSession_Create(&session);
if (sts < PXC_STATUS_NO_ERROR) {
wprintf_s(L"Failed to create the PXCSession\n");
return 3;
}
// Parse command line
UtilCmdLine cmdl(session);
if (!cmdl.Parse(L"-file-iuid-grammar-sdname-realtime-eos",argc, argv)) return 1;

// Create PXCVoiceRecognition instance
PXCSmartPtr<PXCVoiceRecognition> vc;
sts=session->CreateImpl(cmdl.m_iuid, PXCVoiceRecognition::CUID, (void **)&vc);
if (sts<PXC_STATUS_NO_ERROR) 
{
 wprintf_s(L"Failed to create PXCVoiceRecognition\n");
 return 3;
}

// Find and initilize capture module
UtilCaptureFile capture(session,cmdl.m_recordedFile,false);
if (cmdl.m_sdname) capture.SetFilter(cmdl.m_sdname);

 // Query PXCVoiceRecognition profile
 PXCVoiceRecognition::ProfileInfo profile;
 for (int i=0;;i++) 
 {
  sts=vc->QueryProfile(i, &profile);
  sts=capture.LocateStreams(&profile.inputs);
  return 3;
 }
if (cmdl.m_realtime >= 0) capture.SetRealtime(cmdl.m_realtime);
// Set PXCVoiceRecognition profile
if (cmdl.m_eos) profile.endOfSentence = cmdl.m_eos;
sts=vc->SetProfile(&profile);

// Grammar intialization
pxcUID grammar = 0;
if (cmdl.m_grammar.size()<0)
{
  wprintf_s(L"Dictation Mode\n");
}

vc->SetGrammar(grammar);  
// SubscribeRecognition
MyHandler handler(cmdl.m_grammar);
vc->SubscribeRecognition(80, &handler); 
vc->SubscribeAlert(&handler);

// Processing loop
PXCSmartPtr<PXCAudio> audio;
PXCSmartSPArray sps(3);
wprintf_s(L"Press any key to exit\n");

while (!_kbhit()) 
{
  sts = capture.ReadStreamAsync(audio.ReleaseRef(),sps.ReleaseRef(0));
  sts=vc->ProcessAudioAsync(audio,sps.ReleaseRef(1));
  sps.SynchronizeEx();
}

}

like image 863
Kandarp Joshi Avatar asked Feb 11 '14 08:02

Kandarp Joshi


People also ask

How do I copy a console output to a text file?

the shortcut is Ctrl + Shift + S ; it allows the output to be saved as a text file, or as HTML including colors!

How do I redirect console output to a file in Visual Studio?

You can use > to redirect the output of the command run by Visual Studio. Add it to the command arguments by selecting your project in the solution explorer and clicking PROJECT->Properties->Configuration Properties->Debugging. Then enter > output. txt into the Command Arguments.


2 Answers

You can use > to redirect the output of the command run by Visual Studio. Add it to the command arguments by selecting your project in the solution explorer and clicking PROJECT->Properties->Configuration Properties->Debugging. Then enter > output.txt into the Command Arguments. After you run your application, the file will appear in the Working Directory - which by default is the same directory as your .sln files.

like image 81
Rastaban Avatar answered Oct 19 '22 21:10

Rastaban


I think he is simply suggesting to run your executable and direct it to a file:
C:\.exe > C:\output.txt

Here is a link about redirection.

like image 3
ChileAddict - Intel Avatar answered Oct 19 '22 19:10

ChileAddict - Intel