This is the two pieces of code I used, output audio and capture audio.
The socket in the constructor is used to accept audio data from the network. Do not do network audio can remove it.
I hope to share our experience with you. 8-)
Import java.io.*;
Import javax.sound.sampled.*;
Import java.net.*;
/**
* Title:voicechat
* Description: Output audio (playback program)
* Copyright:copyright (c) 2001
* Company:
* @author you guess!
* @version 1.0
*/
Class Playback implements Runnable {
Final int bufsize = 16384;
Sourcedataline Line;
Thread thread;
Socket s;
Playback (socket s) {//constructor obtains Socket for network input stream
This.s=s;
}
public void Start () {
thread = new thread (this);
Thread.setname ("Playback");
Thread.Start ();
}
public void Stop () {
thread = NULL;
}
public void Run () {
Audioformat format =new audioformat (8000,16,2,true,true);//audioformat (float samplerate, int samplesizeinbits, int Channels, Boolean signed, Boolean Bigendian)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.