Freetts.Voice + Twitter Stream
in
Contributed Library Questions
•
1 year ago
Hi All,
I'm working on a project that retrieves twitter messages (which I can do) and at the same time getting the computer to say the messages aloud.
I can get each part to work independently, but not within the same script.
Any suggestions?
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
String consumerKey = "<xxxxx>";
String consumerSecret = "<xxxxx>";
String accessToken = "<xxxxxc>";
String accessSecret = "<xxxxx>";
AccessToken token;
public class Speakerman {
String voiceName = "kevin16";
VoiceManager voiceManager;
Voice voice;
Speakerman(String name){
voiceName = name;
this.setup();
// String Stream = "tweet";
}
Twitter myTwitter;
void setup() {
myTwitter = new TwitterFactory().getInstance();
try{
Query query = new Query("London");
query.setRpp(100);
QueryResult result = myTwitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();
for(int i = 0;i<tweets.size();i++){
Tweet t = (Tweet) tweets.get(i);
String user = t.getFromUser();
String msg = t.getText();
Date d = t.getCreatedAt();
String Stream = ("Tweet by" + user + "at" + d + ": " + msg);
println(Stream);
}
}
catch(TwitterException te){
}
voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice(voiceName);
voice.setStyle("business"); //"business", "casual", "robotic", "breathy"
voice.allocate();
}
void Remember(String _Stream){
if(_Stream==null){
_Stream= "nothing";
}
voice.speak(_Stream);
}
void exit(){
voice.deallocate();
}
}
Speakerman Speaks;
void setup(){
Speaks = new Speakerman("kevin16");
Speaks.Remember ("twitter stream from above here");
}
1