Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 2.96 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2. Copyright Paul James Mutton, 2001-2004, http://www.jibble.org/
  3.  
  4. This file is part of SpeechBot.
  5.  
  6. This software is dual-licensed, allowing you to choose between the GNU
  7. General Public License (GPL) and the www.jibble.org Commercial License.
  8. Since the GPL may be too restrictive for use in a proprietary application,
  9. a commercial license is also provided. Full license information can be
  10. found at http://www.jibble.org/licenses/
  11.  
  12. $Author: pjm2 $
  13. $Id: SpeechBot.java,v 1.1 2004/05/15 13:07:51 pjm2 Exp $
  14.  
  15. */
  16.  
  17. package org.jibble.speechbot;
  18.  
  19. import javax.swing.*;
  20. import org.jibble.pircbot.*;
  21. import com.sun.speech.freetts.*;
  22. import com.sun.speech.freetts.audio.*;
  23. import javax.sound.sampled.*;
  24. import java.io.File;
  25.  
  26. public class SpeechBotMain extends JApplet {
  27. public class SpeechBot extends PircBot {
  28.  
  29.     private boolean noisy = true;
  30.     private Voice voice;
  31.     private AudioPlayer voicePlayer;
  32.    
  33.     public SpeechBot(String name) {
  34.         setName(name);
  35.  
  36.         String voiceName = "kevin16";
  37.         VoiceManager voiceManager = VoiceManager.getInstance();
  38.         voice = voiceManager.getVoice(voiceName);
  39.  
  40.         if (voice == null) {
  41.             System.out.println("Voice not found.");
  42.             System.exit(1);
  43.         }
  44.  
  45.         voice.allocate();
  46.  
  47.         voicePlayer = new JavaClipAudioPlayer();
  48.         voicePlayer.setAudioFormat(new AudioFormat(8000, 16, 1, false, true));
  49.     }
  50.    
  51.    
  52.     // This method is not called from anywhere yet.
  53.     public void exit() {
  54.         voice.deallocate();
  55.     }
  56.  
  57.     public void onMessage(String channel, String sender, String login, String hostname, String message) {
  58.         message = message.trim();
  59.         if (message.toLowerCase().startsWith("!send ")) {
  60.             String input = message.substring(6);
  61.             String filename = "./archive/SpeechBot-" + System.currentTimeMillis();
  62.             AudioPlayer filePlayer = filePlayer = new SingleFileAudioPlayer(filename,  AudioFileFormat.Type.WAVE);
  63.             filePlayer.setAudioFormat(new AudioFormat(8000, 16, 1, false, true));
  64.             speak(input, filePlayer);
  65.             filePlayer.close();
  66.             dccSendFile(new File(filename + ".wav"), sender, 120000);
  67.         }
  68.         if (message.toLowerCase().startsWith("!say ")) {
  69.             String input = sender + /* " on " + channel + */ " says: " + message.substring(5);
  70.             speak(input, voicePlayer);
  71.         }
  72.         else if (noisy) {
  73.             String input = /*sender +  " on " + channel + " says: " +*/ message;
  74.             speak(input, voicePlayer);
  75.         }
  76.     }
  77.  
  78.     private void speak(String input, AudioPlayer player) {
  79.         voice.setAudioPlayer(player);
  80.         voice.speak(input);
  81.     }
  82.  
  83.     public void SpeechBot(String[] args) throws Exception {
  84.         final String  Server = getParameter("Server");
  85.         final String  Channel = getParameter("Channel");
  86.         final String  Name = getParameter("Name");
  87.         SpeechBot bot = new SpeechBot(Name);
  88.         bot.connect(Server);
  89.         bot.joinChannel(Channel);
  90.     }
  91. }
  92. }