Created
June 6, 2015 08:53
-
-
Save KazukoShikiya/ee2b4ce6f7456ee5f733 to your computer and use it in GitHub Desktop.
JJUG主催で6/6に行われたPepperイベで作ったもの
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import twitter4j.Query; | |
import twitter4j.QueryResult; | |
import twitter4j.Status; | |
import twitter4j.Twitter; | |
import twitter4j.TwitterFactory; | |
import com.aldebaran.qi.Application; | |
import com.aldebaran.qi.CallError; | |
import com.aldebaran.qi.Session; | |
import com.aldebaran.qi.helper.EventCallback; | |
import com.aldebaran.qi.helper.proxies.ALBehaviorManager; | |
import com.aldebaran.qi.helper.proxies.ALMemory; | |
import com.aldebaran.qi.helper.proxies.ALTextToSpeech; | |
public class PepperAndTwitter { | |
public static void main(String[] args){ | |
Application application = new Application(args,"tcp://Pepperくん名:ポート番号"); | |
ALBehaviorManager behaviorManager; | |
ALTextToSpeech tts; | |
application.start(); | |
Session session = application.session(); | |
Twitter twitter = TwitterFactory.getSingleton(); | |
Query query = new Query("Twitterの検索キーワード"); | |
try{ | |
QueryResult result = twitter.search(query); | |
// 起動時の動作 | |
behaviorManager = new ALBehaviorManager(session); | |
behaviorManager.startBehavior("animations/Stand/Waiting/Rest_1"); | |
tts = new ALTextToSpeech(session); | |
tts.setLanguage("Japanese"); | |
tts.say("起動しました。"); | |
ALMemory alMemory = new ALMemory(session); | |
// 頭を触ったとき | |
alMemory.subscribeToEvent("MiddleTactilTouched", | |
new EventCallback<Float>() { | |
@Override | |
public void onEvent(Float touch) throws InterruptedException, CallError { | |
if ((float) touch == 1.0) { | |
tts.say("さようなら!"); | |
application.stop(); | |
} | |
} | |
}); | |
// 左手を触ったとき | |
alMemory.subscribeToEvent("HandLeftBackTouched", | |
new EventCallback<Float>() { | |
@Override | |
public void onEvent(Float touch) throws InterruptedException, CallError { | |
if ((float) touch > 0.5) { | |
tts.say("今から、よみますね?"); | |
String s = ""; | |
for (Status status : result.getTweets()) { | |
// RTの文を取り除く | |
s=status.getText(); | |
if(s.indexOf("RT")<0){ | |
System.out.println(s); | |
tts.say(s); | |
} | |
tts.say("おわりました。"); | |
} | |
} | |
} | |
}); | |
// 誰かが接近する | |
alMemory.subscribeToEvent("EngagementZones/PersonApproached", | |
new EventCallback<Integer>() { | |
@Override | |
public void onEvent(Integer touch) throws InterruptedException, CallError { | |
tts.say("こんにちは!"); | |
tts.say("左手を触ったら、ツイッターを読みます。"); | |
} | |
}); | |
// 近かった人が遠ざかるs | |
alMemory.subscribeToEvent("EngagementZones/PersonMovedAway", | |
new EventCallback<Integer>() { | |
@Override | |
public void onEvent(Integer touch) throws InterruptedException, CallError { | |
tts.say("もう行っちゃうの?"); | |
} | |
}); | |
application.run(); | |
} | |
catch(Exception e){ | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment