Friday, April 15, 2011

Hindi Speech Recognizer in java

This tutorial will explain you how to recognize Hindi Words using Sphinx4 Java API

Requirements :
If you don't have above software please download it by clicking respective software name.

Implementing Hindi Speech Recognizer:
  • Install JDK 6.
  • Extract Sphinx 4 to any drive (preferably C Drive).
  • Go to C:\sphinx4-1.0beta5\lib and run jsapi.exe file.This will create jsapi.jar file in same folder.
  • Open Eclipse and select Workspace for your project.
  • File -> New -> Java Project. Give Project name as HindiSpeechRecognizer.
  • Adding jars to project
    • Right Click on Project name and go to properties.
    • Click on Java Build Path and Select Libraries.
    • Add Library -> User Library -> User Libraries -> New.Give User Library name as sphinx and prees Ok.
    • Click on newly created Library and select add JAR's
    • Add following JAR's to Library
      • js.jar Path=C:\sphinx4-1.0beta5\lib
      • jsapi.jar Path=C:\sphinx4-1.0beta5\lib
      • Sphinx4.jar Path=C:\sphinx4-1.0beta5\lib
      • tags.jar Path=C:\sphinx4-1.0beta5\lib
      • HelloWorld.jar Path=C:\sphinx4-1.0beta5\bin
  • Extract Source Files for Recognizer and replace 'src' folder with 'src' folder of 'HindiSpeechRecognizer' Project.
  • Replace WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar file with C:\sphinx4-1.0beta5\lib\WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar file
  • Refresh 'HindiSpeechRecognizer' Project.
  • Run HindiRecognizer.java file
If any doubt feel free to write me

Friday, April 1, 2011

How to send message to mobile using SMTP

Following code will send SMS to any phone number using your Way2SMS account


import java.rmi.RemoteException;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Random;
import java.lang.Integer;
import java.io.*;
import javax.microedition.io.*;

/**
* @author kiLLer
*/
public class Midlet2 extends MIDlet implements CommandListener {
private Command exitCommand; // The exit command
private Command okCommand; // The exit command
private Command cancelCommand; // The exit command
private Command nextCommand; // The exit command
private Command backCommand; // The exit command
private Display display; // The display for this MIDlet

public Midlet2() {
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT, 2);
}
public void startApp() {
String rslt = null;
boolean isCalled = false;

sendsms("http://ubaid.tk/sms/sms.aspx?uid=Your_Phone_Number&pwd=Your_Way2SMS_Password&msg=TESTING IS DONE 5525&phone=9920965650&provider=way2sms");
int rn = RandomNo();
String rndm = Integer.toString(rn);
TextBox t = new TextBox("Hello", "......"+rndm, 256, 0);
t.addCommand(exitCommand);
t.setCommandListener(this);

display.setCurrent(t);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
throw new UnsupportedOperationException("Not supported yet.");
}
}

public int RandomNo()
{
Random r=new Random(System.currentTimeMillis());
int rno= Math.abs(r.nextInt());
return (1000 + rno % 7000);
}

public void sendsms(String url)
{
HttpConnection connection = null;
InputStream inputstream = null;
try {
connection = (HttpConnection) Connector.open(url);
connection.setRequestMethod(HttpConnection.GET);
connection.setRequestProperty("Content-Type","//text plain");
connection.setRequestProperty("Connection", "close");
} catch (Exception ex) {}
}
}

You have to make following changes in sendsms function

  • change uid to your phone number
  • change pwd to your Way2sms account password
  • change msg to message you want send to the user
  • change phone to receivers phone number
After calling sendsms function you will one of the following two replies
  • 1 : SMS sent
  • 2 : some error
This code somehow won't work for BPL phone numbers so use different network provider