[1.1] 自分が今行いたい事は何か
簡単な会話のやり取りができるプログラムを作りたいです
[1.2] どのように取り組んだか(プログラムコードがある場合記載)
少し長いですが、
// aitanaka.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <Windows.h>
#include <stdio.h>
#include <time.h>
#include "util_pipeline.h"
#include "voice_out.h"
#pragma comment( lib, "winmm.lib" )
using namespace std;
//
//class Pipeline: public UtilPipeline {
//public:
//
// // 1.コンストラクタ
// Pipeline(void)
// : UtilPipeline()
// {
// // 必要なデータを有効にする
// EnableVoiceRecognition();
// }
//
// // 2.音声エンジンのセットアップを行う
// virtual void OnVoiceRecognitionSetup(PXCVoiceRecognition::ProfileInfo * finfo)
// {
// // 日本語の音声エンジンを探す
// auto voiceRecognition = QueryVoiceRecognition();
// for ( int i = 0; ; ++i ) {
// PXCVoiceRecognition::ProfileInfo pinfo = { 0 };
// auto ret = voiceRecognition->QueryProfile( i, &pinfo );
// if ( ret != PXC_STATUS_NO_ERROR ) {
// break;
// }
//
// if ( pinfo.language == PXCVoiceRecognition::ProfileInfo::LANGUAGE_JP_JAPANESE ) {
// *finfo = pinfo;
// std::cout << "日本語の音声エンジンを設定しました" << std::endl;
// }
// }
//
// std::cout << "音声認識を開始します" << std::endl;
// }
//
// // 3.音声認識されたテキストを取得する
// virtual void PXCAPI OnRecognized( PXCVoiceRecognition::Recognition *cmd ) {
// std::wcout << L"認識した文: " << cmd->dictation << std::endl;
// }
//};
void widen(const std::string &src, std::wstring &dest) {
size_t returnvalue;
wchar_t *wcs = new wchar_t[src.length() + 1];
mbstowcs_s(&returnvalue,wcs,100, src.c_str(), src.length() + 1);
dest = wcs;
delete [] wcs;
}
void voicesyn(wstring message){
// 2.wide-charactorを扱えるようにする
std::locale::global(std::locale("japanese"));
// 3. UtilPipelineクラスをそのまま利用する
UtilPipeline pipeline;
pipeline.Init();
// 4. 音声合成の機能を利用可能にする
PXCVoiceSynthesis* synthesis = nullptr;
pipeline.QuerySession()->CreateImpl<PXCVoiceSynthesis>( &synthesis );
// 5. 音声エンジンを設定する
PXCVoiceSynthesis::ProfileInfo pinfo = { 0 };
for ( int i = 0; ; ++i ) {
auto ret = synthesis->QueryProfile( i, &pinfo );
if ( ret != PXC_STATUS_NO_ERROR ) {
break;
}
if ( pinfo.language == PXCVoiceRecognition::ProfileInfo::LANGUAGE_JP_JAPANESE ) {
synthesis->SetProfile( &pinfo );
break;
}
}
// 6.テキストを音声化し、スピーカーから出力する
VoiceOut voice( &pinfo );
// 音声合成のキューに入れる
pxcUID id=0;
synthesis->QueueSentence( (wchar_t*)message.c_str(), message.size(), &id );
for (;;) {
PXCSmartSP sp;
PXCAudio *sample;
// 音声合成を行う
auto ret = synthesis->ProcessAudioAsync(id, &sample, &sp);
if ( ret<PXC_STATUS_NO_ERROR ) {
break;
}
ret = sp->Synchronize();
if ( ret<PXC_STATUS_NO_ERROR ) {
break;
}
// 音声データをスピーカーに出力する
voice.RenderAudio(sample);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
string line,str;
wstring message,name2,str2;
int a,nameNo,lineNo,random;
setlocale(LC_CTYPE, "JPN");
//try {
// // 4.wide-charactorを表示できるようにする
// std::locale::global(std::locale("japanese"));
// Pipeline pipeline;
// pipeline.LoopFrames();
// }
// catch ( std::exception& ex ) {
// std::cout << ex.what() << std::endl;
// }
cout<<"田中:会話しましょう"<<endl;
message=L"会話しましょう";
voicesyn(message);
cout<<"あなた:";
while(cin){
a=0;
cin>>line;
ifstream fs1("greeting.txt");
ifstream fs2("abuse.txt");
ifstream fs4("name.txt");
ifstream fs5("random.txt");
if (fs1.fail())
{
cerr << "失敗" << endl;
return -1;
}
if (fs2.fail())
{
cerr << "失敗" << endl;
return -1;
}
if (fs4.fail())
{
cerr << "失敗" << endl;
return -1;
}
if (fs5.fail())
{
cerr << "失敗" << endl;
return -1;
}
while(getline(fs1,str)){
if((line.find(str)!=-1)&&(a==0)){
cout<<"田中:どうも"<<endl;
message=L"どうも";
voicesyn(message);
a++;
}
}
while(getline(fs2,str)){
if((line.find(str)!=-1)&&(a==0)){
cout<<"田中:ひどいですね"<<endl;
message=L"ひどいですね";
voicesyn(message);
a++;
}
}
if((line.find("私の名前")!=-1)&&(a==0)){
nameNo=line.find("です")-line.find("名前は")-6;
string name(line,10,nameNo);
ifstream fs4("name.txt");
while(getline(fs4,str)){
if(name.find(str)!=-1){
cout<<"田中:また会いましたね、"<<name<<"さん"<<endl;
message=L"また会いましたね";
voicesyn(message);
a=1;
}
}
if(a==0){
ofstream fs3("name.txt",ios::app);
fs3<<name<<endl;
cout<<"田中:こんにちは、"<<name<<"さん"<<endl;
message=L"こんにちは";
voicesyn(message);
}
a++;
}
if(a==0){
lineNo=0;
srand((unsigned int)time(NULL));
random=rand()%5+1;
while(getline(fs5,str)){
lineNo++;
if(lineNo==random){
cout<<"田中:"<<str<<endl;
widen(str,str2);
message=str2;
voicesyn(message);
}
}
}
cout<<"あなた:";
}
return 0;
}
[1.3] どのようなエラーやトラブルで困っているか(エラーメッセージが解る場合は記載)
実行画面で、
「田中:会話しましょう」
「あなた:」
で実行待ちになったところに、「a」と入力してエンターキーを押すと、以下のダイアログが出ます。
実行画面には、期待しているランダムな返答が表示されます。
出力
①Heap block at 005BA068 modified at 005BA0A6 past requested size of 36
aitanaka.exe によってブレークポイントが発生しました。
②HEAP[aitanaka.exe]: Heap block at 01027CD0 modified at 01027D32 past requested size of 5a
aitanaka.exe によってブレークポイントが発生しました。
③Critical error detected c0000374
など、場合によっていろいろです。
ダイアログ
aitanaka.exe によってブレークポイントが発生しました
[1.4] 今何がわからないのか、知りたいのか
エラーの原因が全く分かりません。
[2] 環境
[2.1] OS : Windows, Linux等々
windows8.1です。
[2.2] コンパイラ名 : VC++ 2008EE, Borand C++, gcc等々
vc++2012です
[3] その他
・どの程度C言語を理解しているか
初心者です。
・ライブラリを使っている場合は何を使っているか