Friday, January 21, 2011

Record Your Voice and Listen it

Hey Friends I am working on Java sound API. Its a Simple program in which you record your voice and listen it. In this what you have to do is that press capture button and start recording press the stop button to stop recording and press play back button to listen your recorded message.

File name is AudioCapture01.java


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.sound.sampled.*;

public class AudioCapture01
extends JFrame{

boolean stopCapture = false;
ByteArrayOutputStream
byteArrayOutputStream;
AudioFormat audioFormat;
TargetDataLine targetDataLine;
AudioInputStream audioInputStream;
SourceDataLine sourceDataLine;

public static void main(
String args[]){
new AudioCapture01();
}//end main

public AudioCapture01(){//constructor
final JButton captureBtn =
new JButton("Capture");
final JButton stopBtn =
new JButton("Stop");
final JButton playBtn =
new JButton("Playback");

captureBtn.setEnabled(true);
stopBtn.setEnabled(false);
playBtn.setEnabled(false);

//Register anonymous listeners
captureBtn.addActionListener(
new ActionListener(){
public void actionPerformed(
ActionEvent e){
captureBtn.setEnabled(false);
stopBtn.setEnabled(true);
playBtn.setEnabled(false);
//Capture input data from the
// microphone until the Stop
// button is clicked.
captureAudio();
}//end actionPerformed
}//end ActionListener
);//end addActionListener()
getContentPane().add(captureBtn);

stopBtn.addActionListener(
new ActionListener(){
public void actionPerformed(
ActionEvent e){
captureBtn.setEnabled(true);
stopBtn.setEnabled(false);
playBtn.setEnabled(true);
//Terminate the capturing of
// input data from the
// microphone.
stopCapture = true;
}//end actionPerformed
}//end ActionListener
);//end addActionListener()
getContentPane().add(stopBtn);

playBtn.addActionListener(
new ActionListener(){
public void actionPerformed(
ActionEvent e){
//Play back all of the data
// that was saved during
// capture.
playAudio();
}//end actionPerformed
}//end ActionListener
);//end addActionListener()
getContentPane().add(playBtn);

getContentPane().setLayout(
new FlowLayout());
setTitle("Capture/Playback Demo");
setDefaultCloseOperation(
EXIT_ON_CLOSE);
setSize(250,70);
setVisible(true);
}//end constructor

//This method captures audio input
// from a microphone and saves it in
// a ByteArrayOutputStream object.
private void captureAudio(){
try{
//Get everything set up for
// capture
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo =
new DataLine.Info(
TargetDataLine.class,
audioFormat);
targetDataLine = (TargetDataLine)
AudioSystem.getLine(
dataLineInfo);
targetDataLine.open(audioFormat);
targetDataLine.start();

//Create a thread to capture the
// microphone data and start it
// running. It will run until
// the Stop button is clicked.
Thread captureThread =
new Thread(
new CaptureThread());
captureThread.start();
} catch (Exception e) {
System.out.println(e);
System.exit(0);
}//end catch
}//end captureAudio method

//This method plays back the audio
// data that has been saved in the
// ByteArrayOutputStream
private void playAudio() {
try{
//Get everything set up for
// playback.
//Get the previously-saved data
// into a byte array object.
byte audioData[] =
byteArrayOutputStream.
toByteArray();
//Get an input stream on the
// byte array containing the data
InputStream byteArrayInputStream
= new ByteArrayInputStream(
audioData);
AudioFormat audioFormat =
getAudioFormat();
audioInputStream =
new AudioInputStream(
byteArrayInputStream,
audioFormat,
audioData.length/audioFormat.
getFrameSize());
DataLine.Info dataLineInfo =
new DataLine.Info(
SourceDataLine.class,
audioFormat);
sourceDataLine = (SourceDataLine)
AudioSystem.getLine(
dataLineInfo);
sourceDataLine.open(audioFormat);
sourceDataLine.start();

//Create a thread to play back
// the data and start it
// running. It will run until
// all the data has been played
// back.
Thread playThread =
new Thread(new PlayThread());
playThread.start();
} catch (Exception e) {
System.out.println(e);
System.exit(0);
}//end catch
}//end playAudio

//This method creates and returns an
// AudioFormat object for a given set
// of format parameters. If these
// parameters don't work well for
// you, try some of the other
// allowable parameter values, which
// are shown in comments following
// the declarations.
private AudioFormat getAudioFormat(){
float sampleRate = 8000.0F;
//8000,11025,16000,22050,44100
int sampleSizeInBits = 16;
//8,16
int channels = 1;
//1,2
boolean signed = true;
//true,false
boolean bigEndian = false;
//true,false
return new AudioFormat(
sampleRate,
sampleSizeInBits,
channels,
signed,
bigEndian);
}//end getAudioFormat
//===================================//

//Inner class to capture data from
// microphone
class CaptureThread extends Thread{
//An arbitrary-size temporary holding
// buffer
byte tempBuffer[] = new byte[10000];
public void run(){
byteArrayOutputStream =
new ByteArrayOutputStream();
stopCapture = false;
try{//Loop until stopCapture is set
// by another thread that
// services the Stop button.
while(!stopCapture){
//Read data from the internal
// buffer of the data line.
int cnt = targetDataLine.read(
tempBuffer,
0,
tempBuffer.length);
if(cnt > 0){
//Save data in output stream
// object.
byteArrayOutputStream.write(
tempBuffer, 0, cnt);
}//end if
}//end while
byteArrayOutputStream.close();
}catch (Exception e) {
System.out.println(e);
System.exit(0);
}//end catch
}//end run
}//end inner class CaptureThread
//===================================//
//Inner class to play back the data
// that was saved.
class PlayThread extends Thread{
byte tempBuffer[] = new byte[10000];

public void run(){
try{
int cnt;
//Keep looping until the input
// read method returns -1 for
// empty stream.
while((cnt = audioInputStream.
read(tempBuffer, 0,
tempBuffer.length)) != -1){
if(cnt > 0){
//Write data to the internal
// buffer of the data line
// where it will be delivered
// to the speaker.
sourceDataLine.write(
tempBuffer, 0, cnt);
}//end if
}//end while
//Block and wait for internal
// buffer of the data line to
// empty.
sourceDataLine.drain();
sourceDataLine.close();
}catch (Exception e) {
System.out.println(e);
System.exit(0);
}//end catch
}//end run
}//end inner class PlayThread
//===================================//

}//end outer class AudioCapture01.java

Email with Java and JSP

Hey frnds. I am back with some more codes.

If you want to use mail api in your application or website you can use this code.
I am writing here codes in JAVA and JSP both.

import javax.mail.*;
import java.io.*;
import java.util.*;
import javax.mail.Session;
import javax.mail.Message;
import javax.mail.Transport;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.InternetAddress;
import java.util.Properties;
import javax.mail.internet.*;
import javax.activation.*;

public class TestMail
{
public static void main(String[] args)
{
try
{
String to = "nisha.barthwal@mivas.in";
String cc = "sampan.saini@mivas.in";
String bcc = "dharmesh.mahawar@mivas.in";
String from = "medha.vadi@mivas.in";
String subject = "Hi There...";
String text = "How are you?";

Properties properties = new Properties();
properties.put("mail.trasport.protocol","smtp");
properties.put("mail.smtp.host", "smtpout.secureserver.net");
properties.put("mail.smtp.port", "80");
properties.put("mail.smtp.auth","true");
//Session session = Session.getDefaultInstance(properties, null);
//Session session = Session.getInstance(properties,null);
Session session=Session.getInstance(properties, new MailAuthenticator());
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setRecipient(Message.RecipientType.CC, new InternetAddress(cc));
message.setRecipient(Message.RecipientType.BCC, new InternetAddress(bcc));
message.setSubject(subject);
message.setText(text);

Transport.send(message);
}


catch(MessagingException e)
{
System.out.println("Exception found @ e"+e);
}
catch(IllegalStateException ex)
{
System.out.println("Exception found @ ex"+ex);
}
}//end of main

}//end of class TestMail

class MailAuthenticator extends Authenticator {

public MailAuthenticator() {
}

public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("medha.vadi@mivas.in", "password");
}
}


For this you have to keep 2 jar files inside your jdk/jre/lib/ext and jre6/lib/ext folder
1st jar file is activation.jar file and 2nd file is mail.jar. You can download these jar files from www.findjar.com and www.java2s.com.



Now in JSP

<%@ page import="java.io.*,java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@page import="javax.mail.Authenticator"%>
<%@page import="javax.mail.PasswordAuthentication"%>

<%
String result;

try
{
String host = "smtpout.secureserver.net";
String to="sampan.saini@mivas.in";
String from = "helpdesk@mivas.in";
// String cc = "nisha.barthwal@mivas.in";
String pass = "pass";
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
//props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "80");
props.put("mail.smtp.auth", "true");

Session session1 = Session.getInstance(props, new Authenticator()
{
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("sampan.saini@mivas.in","omsairam");
}
});
MimeMessage message = new MimeMessage(session1);
Address fromAddress = new InternetAddress(from);
Address toAddress = new InternetAddress(to);
// Address ccAddress = new InternetAddress(cc);

message.setFrom(fromAddress);
message.setRecipient(Message.RecipientType.TO, toAddress);
//message.setRecipient(Message.RecipientType.CC, ccAddress);

message.setSubject("Tech Support");
message.setText("Hi,\n Please Give the solution of problem ID: ");
Transport transport = session1.getTransport("smtp");
transport.connect(host, from, pass);
message.saveChanges();
Transport.send(message);
out.println("------Your Mail Sent Successfully-----");
transport.close();

}
catch(Exception ex)
{

out.println("");
out.println("ERROR: " + ex);
out.println("");
}
%>

Wednesday, December 8, 2010

Hey friends here i am writing a simple code of oracle connectivity with VC++.

#include < iostream.h>
#include < windows.h>
#include < stdlib.h>
#include < stdio.h>
#include < string>
#include "ocl.h" // include OCL header

int main(/*int argc, char **argv*/)
{
COraSession session;
COraDataset dataset(session);

//OraCommand cmd(session);
int recordCount = 0;
char* connectString = "content/content@mivas"; // replace ora with your TNS alias
//char* connectString = "id/password@ora"; // replace ora with your TNS alias

try {
session.setConnectString(connectString); // set login information
cout << "Connecting as ...\n"<< connectString;
session.connect(); // establish connection
cout<<"Connected\n";

/*dataset.setSQL("SELECT * FROM tbl_content_mis");

dataset.setCached(true); // noncached mode
dataset.setFetchRows(10);

cout<<"\nOpening ...\n"<< dataset.SQL();
dataset.open(); // query result rows
cout<<"Opened\n\n";

cout<<"Fetching...\n\n";
char* str;
while (!dataset.isEOF()) {
//printf("DeptNo: %-4s DName: %-15s Loc: %s\n",
cout << "hi";
cout<< dataset.field("site_id").getString()< //printf("DeptNo: %-4s DName: %-15s Loc: %s\n",
//dataset.field("con_id").getString();
// dataset.field("Loc").getString());
recordCount++;
dataset.next(); // go to next record
}

cout<<"\nFetched:\n";
cout<<" - rows\n"<< recordCount;
if (dataset.isCached())
cout<< "-cached\n";
else
cout<<" - no cached\n";
cout<<" - fetch rows: \n"<< dataset.fetchRows();

dataset.close(); */

session.disconnect(); // close connection
cout<<"\nDisconnected\n\n";

}
catch (CCRException& E) {
cout<<"Error: %s\n"<< E.message();
}

//cout<<"Press ENTER to exit\n";
//getchar();
//getch();

return 0;
}

You have too do some settings with c++......
Oracle Connectivity with C++
1. Keep the OCL (Oracle Class Library) in oracle\product\10.2.0\db_1\ directory.
2. Include OCI include folder in visual studio project.

3. Include OCL include folder in visual studio project.

4. Include Library files of OCI directory and also include all the folders of which are inside the LIB folder.

5. Include BC and MSVC folder of OCI inside the library files.

6. Include OCL\LIB folder inside library files.
7. Include OCL\LIB\BCB\ folder inside library files.
8. Include OCL\LIB\GNU\ folder inside library files.
9. Include OCL\LIB\MSVC\ folder inside library files.

10. Link the library files into project settings.

11. Write oracore8.lib (for oracle 8i) oraocci10d.lib (for oracle 10g for debug module), ocl.lib oci.lib or oci_w32.lib into object/library modules.
12. Include oraocci10.lib for release module.


For any clearification just comment the question.........

All the best........ :)

Friday, August 20, 2010

On This Rakhi this Poem is dedicated to My Brother

You've been there for me
Through it all
You're always there to catch me
When I start to take a fall.

If I do something bad
You'll take the blame
And for all of that
I am feeling shame.

I never did tell you
All the things I felt
Like how I really love you
And in my heart you'll dwell.

You protected me from the world
That left the bruises on your face
All the tears and scrapes
I wish I could erase.

When my life fell apart
You patched things up
You took care of my heart
When times got rough.

With just the warmth of your touch
You saved me from the world
You loved me so much
But my love for you was not said.

If you knew what I knew
Maybe you'd stay home
If you heard what I didn't say
Maybe I wouldn't be alone.

If you could see the part of me I hid away
Maybe you could see
How much I want you to stay
Here at home with me.

You may think I don't care
Because I never show it
But I'll always be here
And I hope you know it.


Wish we could go back
We can start over again
I don't want to be alone
I need brother I need a friend.

If you think of me
While you're protecting the country
Think of how much you mean to me
And how proud I am of you, Donny.

Remember I will be here
When you're at the battle field
I'll be here for you
As you're love shield.

Do not leave this world
While you're over seas
Do not leave this little girl
Do not leave me.

If you do have to go
Before I say goodbye
Remember I love you so
As you begin to fly.

Remember I will be here
Through and through
Remember I will always care
Just as much as you do.

You've done so much for me
And yet I not for you
I hope you will forgive me
For all the things I didn't do.
HAPPY RAKSHA BANDHAN

Posted via email from medha's posterous

Thursday, May 13, 2010

A New Day Has Come

A new day has...come


I was waiting for so long
For a miracle to come
Everyone told me to be strong
Hold on and don't shed a tear


Through the darkness and good times
I knew I'd make it through
And the world thought I had it all
But I was waiting for you


Hush, love


I see a light in the sky
Oh, it's almost blinding me
I can't believe
I've been touched by an angel with love
Let the rain come down and wash away my tears
Let it fill my soul and drown my fears
Let it shatter the walls for a new, new sun
A new day has...come


Where it was dark now there's light
Where there was pain now there's joy
Where there was weakness, I found my strength
All in the eyes of a boy


Hush, love


I see a light in the sky
Oh, it's almost blinding me
I can't believe
I've been touched by an angel with love
Let the rain come down and wash away my tears
Let it fill my soul and drown my fears
Let it shatter the walls for a new, new sun
A new day has...come


A new day has...come
Ohhh, a light... OOh

Sunday, May 9, 2010

Mother Daughter Relationship

Mother is the epitome of love and care. With the birth of every child, a mother is born. A mother is always attached to her child. That is the reason why mothers have an upper hand over their children. Though a mother shares equally good relationship with her sons as well as her daughters, they have a special rapport with their daughters. It is not that easy to define the relationship that they both share with each other as to some extent they search for themselves in each others. It is a well known fact that most of the daughters grow up to be their mothers and it is the mother who teaches her daughter to live and let others live happily. The training that she gives her daughter from the beginning is enough for any daughter to nurture a good life after she leaves her mother's place. Learn about the beautiful relationship that a mother and a daughter share with each other and why it is called the strongest bond.

Relationship Between Mother And Daughter

"I thought my mom's whole purpose was to be my mom.
That's how she made me feel."- Natasha Gregson Wagner

She was true saying that and at the end of the day, you find your mother living in you. There is always a part of the mother living in every daughter's heart. The mother-daughter bond is truly fragile but unbreakable. Though most women don't acknowledge, they share a very strong bond with their mothers.

Most of the mothers want their daughters to be grown up like them. They watch their daughters grow eagerly worrying about their daughter's survival – physically, psychologically, socially, and even sexually. They watch their daughters grow with great expectations for their life as they give the love and care for their upbringing all their life and hope their daughters wouldn’t have to face a life that they experienced. They train their daughters accordingly as well taking the experiences from their life. The mother, with her wealth of experience offers wise insight and knowledge into her daughter's life that at a point they begin to grow together. Until and unless any girl reaches that period of her life when she has to make a life of her own, little does she understands what her mother was to her. Life is like a roller coaster for every woman, the kind of changes that she faces all through her life is quite Brobdingnagian. Life becomes more complex with her age and the best companion she can age along with is her mother. Mothers teach them to love, respect, encourage and complete a family. Every daughter looks out to her mother while growing up. It is the self-respect and the feel of self-esteem that a mother teaches a daughter that leads to her own well-being.

A Pennsylvania State University has revealed that despite conflicts and complicated emotions, about 80 to 90 per cent of women at midlife reported a good relationship with their mother. It is a great bond that a mother and daughter share with each other and it's so close that everything from health to relationships can be affected by it.

Friday, May 7, 2010

Excellence-a drive from 'Inside'

A gentleman was once visiting a temple under construction. In the temple premises, he saw a sculptor making an idol of God. Suddenly he saw, just a few meters away, another identical idol was lying.

Surprised he asked the sculptor, “Do you need two statutes of the same idol”. “No” said the sculptor. “We need only one, but the first one got damaged at the last stage”.

The gentleman examined the sculptor. No apparent damage was visible. “Where is the damage” asked the gentleman.

“There is a scratch on the nose of the idol.”

“Where are you going to keep the idol”.

The sculptor replied that it will be installed on a pillar 20 feet high. “When the idol will be 20 feet away from the eyes of the beholder, who is going to know that there is scratch on the nose?” The gentleman asked.

“The sculptor looked at the gentleman, smiled and said “God knows it and I know it”.

The desire to excel should be exclusive of the fact whether someone appreciates it or not. Excellence is a drive from ”Inside” not ”Outside”.

Moral:

Excellence is an art won by training and habituation. We do not act rightly because we have virtue or excellence, but we rather have those because we have acted rightly...........