PALROというロボットのプログラムです。
HTMLのサイトからタグを引き出してspeakで発話するプログラムなのですが、うまくURLをpageに取り込めてないのか、発話しません、どなたか力を貸してはいただけないでしょうか。
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
#include "hevent.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <libxml/HTMLparser.h>
//SPCのインスタンスを定義する
Chevent spcApp;
//コンストラクタ
Chevent::Chevent() {
}
//デストラクタ
Chevent::~Chevent() {
}
void FindInfo(xmlNode*& element);
using namespace std;
//std::string str;
//SPC初期化イベント
void Chevent::onInitialize(){
enableNetwork();
speak("テストします");
// HTML用の構造体
htmlDocPtr m_doc;
char* sapo = "http://www.visit-hokkaido.jp/article/detail/2";
char* asah = "http://www.visit-hokkaido.jp/article/detail/11";
char* hako = "http://www.visit-hokkaido.jp/article/detail/7";
char* otar= "http://www.visit-hokkaido.jp/article/detail/8";
char* url;
//std::string str = std::string(url);
//札幌、函館、旭川、小樽を選択させる。
SPC_ANSWER answer;
std::vectorstd::string answerWords;
std::string recogWord;
int recogIndex;
//認識したい言葉を全角カタカナで追加する answerWords.push_back("サッポロ"); answerWords.push_back("アサヒカワ"); answerWords.push_back("ハコダテ"); answerWords.push_back("オタル"); //質問をする long rtn; rtn = waitForAnswer("札幌、旭川、函館、小樽から選んでください", answerWords, answer, recogWord, recogIndex); if(rtn != 0){ //waitForAnswer処理失敗 //アプリケーションの終了 exitComponent(); return; } switch(answer){ case SPC_ANSWER_RECOGEND: // ここに質問が正常終了した場合の処理を記述する // 認識した単語は、recogWord、および answerWords[recogIndex] で取得できる if(recogWord == "サッポロ"){ speak("札幌です"); url = sapo; } if(recogWord == "ハコダテ"){ speak("函館です"); url = hako; } if(recogWord == "アサヒカワ"){ speak("旭川です"); url = asah; } if(recogWord == "オタル"){ speak("小樽です"); url = otar; } break; case SPC_ANSWER_CANCEL: // ここに「やめる」を認識した時の処理を記述する break; case SPC_ANSWER_TIMEOUT: // ここに質問処理がタイムアウトした時の処理を記述する break; default: break; }
// ファイル名とエンコードの設定
char* file = url;
char* enc = "utf-8";
// xmlの読み込み
if (m_doc = htmlReadFile(file, enc, HTML_PARSE_RECOVER)) {
htmlNodePtr root = xmlDocGetRootElement(m_doc);
if (root != NULL) {
FindInfo(root);
}
xmlFreeDoc(m_doc);
m_doc = NULL;
}
xmlCleanupParser(); xmlCleanupCharEncodingHandlers(); speak("テストを終了します"); exitComponent();
}
void Chevent::FindInfo(xmlNode*& element) {
char* page;
for (htmlNodePtr node = element; node != NULL; node = node->next) {
if (node->type == XML_ELEMENT_NODE) {
//pタグを発話
if(xmlStrcasecmp(node->name, (const xmlChar*)"p") == 0){
page = (char*)node->children->content;
speak("概要です");
speak(page);
}
else if(xmlStrcasecmp(node->name, (const xmlChar*)"h2")==0){
page = ((char *)node->children->content);
speak("イベント名");
speak(page);
}
}
// 再帰読み込み
if(node->children != NULL)
{
FindInfo(node->children);
}
}
}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/01/15 11:26