Writing or Copying Visual C++ console output to text file(将 Visual C++ 控制台输出写入或复制到文本文件)
问题描述
我正在使用英特尔感知计算 SDK 语音识别模块.SDK 示例使用 Microsoft Visual Studio 2012 Professional 感知听写,并在处理语音输入后将其打印在控制台窗口上.我要做的就是复制打印在控制台窗口上的输出并将其写入 .txt
文件.我遵循一般方式,但不知何故,文件中写入的文本只是一些数字.
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
{上市:MyHandler(std::vector &commands){这->命令=命令;}
{ public: MyHandler(std::vector &commands) { this->commands=commands; }
virtual void PXCAPI OnRecognized(PXCVoiceRecognition::Recognition *cmd)
{
wprintf_s(L"
Recognized: <%s>
", (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
");
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
");
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
");
}
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
");
while (!_kbhit())
{
sts = capture.ReadStreamAsync(audio.ReleaseRef(),sps.ReleaseRef(0));
sts=vc->ProcessAudioAsync(audio,sps.ReleaseRef(1));
sps.SynchronizeEx();
}
}
推荐答案
您可以使用 >
重定向 Visual Studio 运行的命令的输出.通过在解决方案资源管理器中选择您的项目并单击 PROJECT->Properties->Configuration Properties->Debugging,将其添加到命令参数中.然后输入>output.txt
到命令参数中.运行应用程序后,该文件将出现在工作目录中 - 默认情况下,该目录与您的 .sln 文件位于同一目录.
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.
这篇关于将 Visual C++ 控制台输出写入或复制到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 Visual C++ 控制台输出写入或复制到文本文件
- Qt计时器使用方法详解 2023-05-30
- 我应该为我的项目使用相对包含路径,还是将包含目录放在包含路径上? 2022-10-30
- c++ const 成员函数,返回一个 const 指针.但是返回的指针是什么类型的 const? 2022-10-11
- Easyx实现扫雷游戏 2023-02-06
- C语言详解float类型在内存中的存储方式 2023-03-27
- C语言qsort()函数的使用方法详解 2023-04-26
- C++ 数据结构超详细讲解顺序表 2023-03-25
- ubuntu下C/C++获取剩余内存 2023-09-18
- C语言手把手带你掌握带头双向循环链表 2023-04-03
- 详解C语言中sizeof如何在自定义函数中正常工作 2023-04-09