-
Guys can any one tell me some way through which i will be able to record my voice via web browser and upload it to web server0
-
Administrator • Dec 31, 2010
Hi Goyal,
I found this article:
#-Link-Snipped-#
Contents of that article:
This isn't so tough, but my concern with the wording of this question is that the user thinks that perhaps it's possible to record the microphone client side and then save it on the server.
If by chance that is the case, then it isn't really possible. The best you can do in that area with just flash is to buffer a lot and then have the flash player "upload" it to the server. But in reality, it's not saving it anywhere in hard memory and is deleted if you close the flash player. The reason you might want to do something like this is if you are concerned that the user's bandwidth is much lower than they may need to stream the audio up to the server. So you buffer it on the client side (usually if it's under 30 seconds of audio you should be ok) and then flush the buffer when it reaches the limit.
So, how about some code then:
I won't cover making a net connection to the server and all that because I've talked about that in the past and there really are lots of examples of it (every FMS app needs to connect to the server..)
Once a connection has been made to the server, let's call a function called getMic()
Assuming the netConnection object is "nc", netstream to publish the mic is "ns" and the microphone object is "mic"
//this function will get the microphone object and set some parameters for it
function getMic(){
//first we need a netstream object to connect the mic to
ns = new NetStream(nc);
//set a small buffer
ns.setBufferTime(2);
//we need the microphone object now, get the default mic by passing in nothing in the parantheses
mic = Microphone.get();
//set the quality of the microphone, this can be set to 5, 8, 11, 22, or 44
mic.setRate(22);
//attach the microphone object to the netstream
ns.attachAudio(mic);
//and publish it to the server by passing in the file name and record command. If you want a live stream, then just pass in "LIVE" instead of "RECORD"
ns.publish("myMicrophone", "RECORD");
}
and that's it really. There are a few other options for the microphone which can be seen #-Link-Snipped-#.Are you sure? This action cannot be undone. -
Member • Dec 31, 2010
How if you use java to do this.
I am currently working on voice recording using java.It's not too hard to do.
In which format you want to save it(mp3 or wav) ?Are you sure? This action cannot be undone. -
Member • Jan 1, 2011
any format buddy
Do you have any java applet through which users voice recording is possible ?
Please give me the code if possibleAre you sure? This action cannot be undone. -
Member • Jan 1, 2011
I will try to do this in consol but i got an file format not supported exception check this.
.
java.lang.IllegalArgumentException: could not write audio file: file type not supported: null
The codes are like this
at javax.sound.sampled.AudioSystem.write(AudioSystem.java:1363)
at pp.run(pp.java:30)
import java.io.*;
Once you done with consol its easy to implement in Applet or in your own created frame.
import javax.sound.sampled.*;
public class pp extends Thread
{
TargetDataLine tdl;
AudioFileFormat.Type afft;
AudioInputStream ais;
File f1;
public pp(TargetDataLine l,AudioFileFormat.Type t,File f2)
{
tdl=l;
ais=new AudioInputStream(tdl);
afft=t;
f1=f2;
}
public void start()
{
tdl.start();
super.start();
}
public void sr()
{
tdl.stop();
tdl.close();
}
public void run()
{
try
{
AudioSystem.write(ais,afft,f1);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception caught ");
}
}
public static void main(String args[])
{
String s=args[0];
File f=new File(s);
AudioFormat ff=new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,44100.0F, 16, 2, 4, 44100.0F, false);
DataLine.Info inf=new DataLine.Info(TargetDataLine.class,ff);
TargetDataLine td=null;
try
{
td=(TargetDataLine)AudioSystem.getLine(inf);
td.open(ff);
}
catch(Exception e)
{
//e.printStackTrace();
System.out.println("Exception caught ");
}
AudioFileFormat.Type t5=AudioFileFormat.Type.AIFC;
pp p=new pp(td,t5,f);
System.out.println("enter to start recording");
try
{
System.in.read();
}
catch(Exception e)
{
System.out.println("exception caught ");
}
p.start();
System.out.println("enter to stop recording");
try
{
System.in.read();
}
catch(Exception e)
{
System.out.println("exception caught ");
}
p.sr();
System.out.println("recording stoped");
}
}
You can create the event on JSlider.
Hope it will help you.I will try to fix this exception.Once i done i will make an applet page for you.Are you sure? This action cannot be undone. -
Member • Jan 2, 2011
@ above
i m working on project which is some like yahoo messenger (MULTI USER CHAT WITH VOICE & VIDEO ) BASED ON JAVA CAN U PLAESE HELP ME IN multi chat & also in voice and video implementation
PLEASE ITS VERY URGENT AND IMPORTANTAre you sure? This action cannot be undone. -
Member • Jan 2, 2011
@bhargava I don't think you have to record the voice for that.You have to take the input from user and put your output streams on the network for the other user to take the input from them.You need socket programming for that.
I didn't handled any project till now but i think this is the main theme on which you have to work on.
.
May i know up to what you have done...?Are you sure? This action cannot be undone. -
Member • Jan 2, 2011
Lets divide your project into threes parts.
1.>designing of applet.
2.>communication between applets.
3.>do the socket programming for that.
Just start your project with the first one.It's not hard to do.Post your quarries if you found any problem.Are you sure? This action cannot be undone. -
Member • Jan 3, 2011
@mohit
thanxAre you sure? This action cannot be undone. -
Member • Jan 3, 2011
@ mohit
but i have to add voice & video feature in that
like YAHOO MESSENGER but i dont know how it will implement
please i dont find any exact help from net..
if u can do any thing then pls tryAre you sure? This action cannot be undone. -
Member • Jan 3, 2011
Check these two programs.
for client....
import java.awt.*;
for client....
import javax.swing.*;
import java.io.*;
import java.net.*;
import java.awt.event.*;
/*<Applet code="sas" height=400 width=800></applet>*/
public class sas extends JApplet implements ActionListener
{
JTextArea t;
JButton b;
public void init()
{
t=new JTextArea(10,20);
b=new JButton("open");
setLayout(new FlowLayout());
add(t);
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e)
{
byte b[]=new byte[60];
try
{
Socket s=new Socket("127.0.0.1",4444);
InputStream bis=s.getInputStream();
BufferedInputStream bi=new BufferedInputStream(bis);
bis.read(b);
String str=new String(b);
t.setText(str);
}
catch(Exception ee)
{
ee.printStackTrace();
System.out.println("exception caught ");
}
}
}
.
import java.awt.*;
.
import javax.swing.*;
import java.io.*;
import java.net.*;
import java.applet.*;
import java.awt.event.*;
/*<Applet code="xx" height=400 width=400></applet>*/
public class xx extends JApplet implements ActionListener
{
JTextArea t;
JButton b;
public void init()
{
t=new JTextArea(10,20);
b=new JButton("submit");
setLayout(new FlowLayout());
add(t);
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e)
{
byte b[]=new byte[60];
String str;
byte b1[]=new byte[60];
try
{
ServerSocket s=new ServerSocket(4444);
Socket s1=s.accept();
str=t.getText();
b1=str.getBytes();
ByteArrayInputStream bai=new ByteArrayInputStream(b1);
BufferedInputStream bis=new BufferedInputStream(bai);
bis.read(b);
OutputStream os=s1.getOutputStream();
os.write(b);
//System.out.println(t.getText());
}
catch(Exception ee)
{
System.out.println("Exception caught ");
}
}
}
try to execute this it may give you some idea.Are you sure? This action cannot be undone. -
Member • Jan 3, 2011
As i said previously You have to take the input from user and put your output streams on the network for the other user to take the input from them.You need socket programming for that.
you may take the help of JMF.It will provide some additional packages for you.Are you sure? This action cannot be undone.