import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.io.FileInputStream;
import java.sql.*;
import javazoom.jl.player.Player;
public class TTS {
/**
* @param args
*/
static ArrayList<String> to_syllablize=new ArrayList<String>();
static ArrayList<String> final_array=new ArrayList<String>();
static ArrayList<Object> orig_array=new ArrayList<Object>();
public static void main(String[] args) {
HashMap hm=new HashMap();
//using hashmap
hm.put(new String("अ"),"a");
hm.put("आ","aa");
hm.put("इ","i");
hm.put("ई","ii");
hm.put("उ","u");
hm.put("ऊ","uu");
hm.put("ए","e");
hm.put("ऐ","ai");
hm.put("ओ","o");
hm.put("औ","au");
hm.put("ा","aa");
hm.put("ि","i");
hm.put("ी","ii");
hm.put("ु","u");
hm.put("ू","uu");
hm.put("ो","o");
hm.put("ौ","au");
hm.put("े","e");
hm.put("ै","ai");
hm.put("क","k");
hm.put("ख","kh");
hm.put("ग","g");
hm.put("घ","gh");
hm.put("ङ","ng");
hm.put("च","ch");
hm.put("छ","chh");
hm.put("ज","j");
hm.put("झ","jh");
hm.put("ट","tt");
hm.put("ठ","tth");
hm.put("ड","dd");
hm.put("ढ","ddh");
hm.put("ण","nn");
hm.put("त","t");
hm.put("थ","th");
hm.put("द","d");
hm.put("ध","dh");
hm.put("न","n");
hm.put("प","p");
hm.put("फ","f");
hm.put("ब","b");
hm.put("भ","bh");
hm.put("म","m");
hm.put("य","y");
hm.put("र","r");
hm.put("ल","l");
hm.put("व","v");
hm.put("श","sh");
hm.put("स","s");
hm.put("ह","h");
hm.put("ज्ञ ","gy");
Object temp ;
String input="समारोह";
String tokens[]=input.split("");
String[] class_tokens=new String[15];
String t;
for(int i=0;i<tokens.length;i++)
{
//System.out.println(t);
t=tokens[i];
//System.out.println(t);
temp= hm.get(t);
orig_array.add(temp);
System.out.println(temp);
if(temp=="a" || temp=="aa" || temp=="i" || temp=="ii" || temp=="u" || temp=="uu" ||temp=="e" || temp=="ai" || temp=="o" || temp=="au" )
{
class_tokens[i]="V";
}
else if(temp != null && temp!=" " )
{
class_tokens[i]="C";
}
else if(temp== null)
{
continue;
}
//temp_tokens[i]=temp;
// String tok = "";
}
for(int k=1;k<(class_tokens.length)-2;k++)
{
if(class_tokens[k]== null)
{
if(class_tokens[k-1]==null)
{
break;
}
syllablize(to_syllablize);
}
to_syllablize.add(class_tokens[k]);
}
Collections.reverse(final_array);
System.out.println(final_array);
/*------------------------------*/
ResultSet rs;
Statement st;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=audio;user=sa;password=swochchhal;";
Connection con = DriverManager.getConnection(connectionUrl);
st = con.createStatement();
// ResultSet r = st.executeQuery("Select Filepath from soundtest where AudioFileName ="+orig_array.get(i));
// rs = st.executeQuery("SELECT AudioFileName,Filepath FROM soundtest");
//String name = rs.getString("AudioFileName");
//String [] word = {"s","m","aa","r","o","h"};
for(int i=1;i<orig_array.size();i++){
ResultSet r = st.executeQuery("Select Filepath from soundtest where AudioFileName ='"+orig_array.get(i)+"'");
while(r.next())
{
// if(orig_array.get(i).equals(r.getString("AudioFileName"))){
String path = r.getString("Filepath");
try
{
FileInputStream fis = new FileInputStream(path);
Player playMP3 = new Player(fis);
playMP3.play();
playMP3.close();
}
catch(Exception e)
{
System.out.println(e);
}
// }
}
}
}
catch(SQLException e)
{
System.out.println("SQL Exception:" + e.toString());
}
catch(ClassNotFoundException ce)
{
System.out.println("class not found exception: "+ ce.toString());
}
}
//syllablize function to break the words to syllables
private static void syllablize(ArrayList<String> to_syllablize)
{
int last_index=to_syllablize.size();
if(to_syllablize.get(last_index - 1).equals("C"))
{
to_syllablize.set(last_index-1,"Ch");
}
for(int l=last_index-1;l>=0;)
{
if((to_syllablize.get(l).equals("C") && l==0) ||(to_syllablize.get(l).equals("C") && l==-1))
{
final_array.add("C1");
l--;
}
else if(to_syllablize.get(l).equals("C"))
{
if(to_syllablize.get(l - 1).equals(""))
{
final_array.add("C1");
}
else if(to_syllablize.get(l - 1).equals("V"))
{
if(to_syllablize.get(l - 2).equals("C"))
{
final_array.add("CVC");
l=l-3;
}
else
{
final_array.add("VC");
l=l-2;
}
}
else if (to_syllablize.get(l - 1).equals("C"))
{
final_array.add("C1C");
l=l-2;
}
else if(to_syllablize.get(l - 1).equals("Ch"))
{
final_array.add("C1C");
l=l-2;
}
}
else if((to_syllablize.get(l).equals("Ch") && l==0 ) ||(to_syllablize.get(l).equals("Ch") && l==-1))
{
final_array.add("0C");
l--;
}
else if(to_syllablize.get(l).equals("Ch"))
{
if(to_syllablize.get(l - 1).equals(""))
{
final_array.add("0C");
}
else if(to_syllablize.get(l - 1).equals("V"))
{
if(to_syllablize.get(l - 2).equals("C"))
{
final_array.add("CVC");
l=l-3;
}
else
{
final_array.add("VC");
l=l-1;
}
}
else if (to_syllablize.get(l - 1).equals("C"))
{
final_array.add("C1C");
l=l-2;
}
else if(to_syllablize.get(l - 2).equals("Ch"))
{
if((to_syllablize.get(l - 1) + to_syllablize.get(l)).equals("CHCV"))
{
final_array.add("CHCV");
}
else
{
final_array.add("0C");
}
}
}
else if((to_syllablize.get(l).equals("V") && l==0 ) ||(to_syllablize.get(l).equals("V") && l==-1))
{
final_array.add("V");
l--;
}
else if(to_syllablize.get(l).equals("V"))
{
if(to_syllablize.get(l - 1).equals(""))
{
final_array.add("V");
//l=l-2;
}
else if(to_syllablize.get(l - 1).equals("V"))
{
final_array.add("V");
l=l-2;
}
else if (to_syllablize.get(l - 1).equals("C"))
{
final_array.add("CV");
l=l-2;
}
else if(to_syllablize.get(l - 2).equals("Ch"))
{
final_array.add("CV");
l=l-1;
}
} // end of if else
} //end for
} //end syllabalize();
} //end main