当前位置: 首页>>代码示例>>Java>>正文


Java TargetDataLine.start方法代码示例

本文整理汇总了Java中javax.sound.sampled.TargetDataLine.start方法的典型用法代码示例。如果您正苦于以下问题:Java TargetDataLine.start方法的具体用法?Java TargetDataLine.start怎么用?Java TargetDataLine.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sound.sampled.TargetDataLine的用法示例。


在下文中一共展示了TargetDataLine.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: upChannel

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
/**
 * Streams data from the TargetDataLine to the API.
 * 
 * @param urlStr
 *            The URL to stream to
 * @param tl
 *            The target data line to stream from.
 * @param af
 *            The AudioFormat to stream with.`
 * @throws LineUnavailableException
 *             If cannot open or stream the TargetDataLine.
 */
private Thread upChannel(String urlStr , TargetDataLine tl , AudioFormat af) throws LineUnavailableException {
	final String murl = urlStr;
	final TargetDataLine mtl = tl;
	final AudioFormat maf = af;
	if (!mtl.isOpen()) {
		mtl.open(maf);
		mtl.start();
	}
	Thread upChannelThread = new Thread("Upstream Thread") {
		public void run() {
			openHttpsPostConnection(murl, mtl, (int) maf.getSampleRate());
		}
	};
	upChannelThread.start();
	return upChannelThread;
	
}
 
开发者ID:goxr3plus,项目名称:java-google-speech-api,代码行数:30,代码来源:GSpeechDuplex.java

示例2: start

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
/**
 * Implementation of the abstract start() method from DataStream
 */
public void start() throws Exception {
	if (queue != null) { throw new Exception("ERROR in AudioStream.start(): LinkedBlockingQueue object is not null"); }
	// Make sure we can open the audio line
	try {
		format = getFormat();
		DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
		line = (TargetDataLine) AudioSystem.getLine(info);
		line.open(format);
		line.start();
	} catch (LineUnavailableException e) {
		throw new Exception("Audio stream error, could not open the audio line:\n" + e.getMessage());
	}
	bIsRunning = true;
	// Make sure there is no other audio capture running
	stopAudio();
	queue = new LinkedBlockingQueue<TimeValue>();
	// start the audio capture
	audioThread = new Thread(this);
	audioThread.start();
	updatePreview();
}
 
开发者ID:cycronix,项目名称:cloudturbine,代码行数:25,代码来源:AudioStream.java

示例3: captureAudio

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
public 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) {
		Logging.logError(e);
	}// end catch
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:21,代码来源:AudioCapture.java

示例4: captureAudio

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
public void captureAudio() {
	try {
		audioFormat = getAudioFormat();
		log.info("sample rate         " + sampleRate);
		log.info("channels            " + channels);
		log.info("sample size in bits " + sampleSizeInBits);
		log.info("signed              " + signed);
		log.info("bigEndian           " + bigEndian);
		log.info("data rate is " + sampleRate * sampleSizeInBits / 8 + " bytes per second");
		// create a data line with parameters
		DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
		// attempt to find & get an input data line with those parameters
		targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
		targetDataLine.open(audioFormat);
		targetDataLine.start();

		// create buffer for root mean square level detection
		buffer = new FloatSampleBuffer(targetDataLine.getFormat().getChannels(), bufferSize, targetDataLine.getFormat().getSampleRate());

		// capture from microphone
		captureThread = new CaptureThread(this);
		captureThread.start();
	} catch (Exception e) {
		log.error(Service.stackToString(e));
	}
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:27,代码来源:GoogleSTT.java

示例5: FreqThread

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
public FreqThread(){

            
            try
            {
                    target = (TargetDataLine) AudioSystem.getLine(info);
                    target.open(format);
                    target.toString();
            }
            catch (LineUnavailableException e)
            {
                    System.out.print("unable to get a recording line");
                    e.printStackTrace();
                    System.exit(1);
            }



            // Begin audio capture.
            target.start();

  
        }
 
开发者ID:kara71,项目名称:KaraOK,代码行数:24,代码来源:FreqThread.java

示例6: captureAudio

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
public void captureAudio() {									
	try {														
		bufferSize = 2048;  										// Define Buffer size
		buffer = new byte[bufferSize];								// Buffer array
		info = new DataLine.Info(TargetDataLine.class, format);		// Dataline info
		recLine = (TargetDataLine) AudioSystem.getLine(info);		// Getting mixer line from driver (system selected)
		recLine.open(format);										// Opening recording line (make connection)
		recLine.start();											// Start draining line
		runner();													// Create new runner for thread
		captureThread = new Thread(runner);							// Define new thread
		captureThread.start();										// Start for capture, invoke thread
	} catch (LineUnavailableException e) {
		System.err.println("Line unavailable: " + e);
		System.exit(-2);
	}
}
 
开发者ID:miracatici,项目名称:MakamBox,代码行数:17,代码来源:PitchTracking.java

示例7: start

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
@Override
public void start() {
    DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
    if (!AudioSystem.isLineSupported(info)) {
        // Handle the error.
        logger.severe("JavaSoundInputStream - not supported." + format);
    } else {
        try {
            line = (TargetDataLine) getDataLine(info);
            int bufferSize = calculateBufferSize(suggestedInputLatency);
            line.open(format, bufferSize);
            logger.fine("Input buffer size = " + bufferSize + " bytes.");
            line.start();
        } catch (Exception e) {
            e.printStackTrace();
            line = null;
        }
    }
}
 
开发者ID:philburk,项目名称:jsyn,代码行数:20,代码来源:JavaSoundAudioDevice.java

示例8: captureAudio

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
public 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) {
    Logging.logError(e);
  } 
  broadcastState();
  // end catch
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:23,代码来源:AudioCapture.java

示例9: upChannel

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
/**
 * Streams data from the TargetDataLine to the API.
 * @param urlStr The URL to stream to
 * @param tl The target data line to stream from.
 * @param af The AudioFormat to stream with.
 * @throws LineUnavailableException If cannot open or stream the TargetDataLine.
 */
private void upChannel(String urlStr, TargetDataLine tl, AudioFormat af) throws LineUnavailableException{
	final String murl = urlStr;
	final TargetDataLine mtl = tl;
	final AudioFormat maf = af;
	if(!mtl.isOpen()){
		mtl.open(maf);
		mtl.start();
	}
	new Thread ("Upstream Thread") {
		public void run() {
			openHttpsPostConnection(murl, mtl, maf);
		}

	}.start();

}
 
开发者ID:CMPE272Project,项目名称:SpeakJava,代码行数:24,代码来源:GSpeechDuplex.java

示例10: run

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
public void run() {
    try {
        AudioFormat format = getAudioFormat();
        DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
        if (!AudioSystem.isLineSupported(info)) {
            NewJFrame.jTextArea1.append("\nError: Line not supported");
            calibrateTextArea();
        } else {
            line = (TargetDataLine) AudioSystem.getLine(info);
            line.open(format);
            line.start();
            NewJFrame.jTextArea1.append("\nRecording has started.");
            calibrateTextArea();
            AudioInputStream ais = new AudioInputStream(line);
            File wavFile = new File(temp_file);
            AudioSystem.write(ais, fileType, wavFile);
        }
    } catch (Exception recording) {
        NewJFrame.jTextArea1.append("\n" + recording.getMessage());
    }
}
 
开发者ID:rusher81572,项目名称:cloudExplorer,代码行数:22,代码来源:SoundRecorderThread.java

示例11: CallRecorder

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
public CallRecorder(Contact contact, OutputStream out) throws LineUnavailableException,
		UnknownDefaultValueException {
	super(contact);
	this.out = out;

	AudioFormat audioFormat = Microphones.getSelectedFormat().getAudioFormat();
	Util.log(contact, "Recorder: start.");
	Util.log(contact, "Recorder: target audio format: " + audioFormat);

	// DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class,
	// audioFormat);
	// throws LineUnavailableException
	// line = (TargetDataLine) AudioSystem.getLine(dataLineInfo);

	Microphone microphone = Microphones.getCurrentMicrophone();
	Util.log(contact, "Recorder: microphone: " + microphone);
	line = (TargetDataLine) microphone.getLine();
	line.open(audioFormat, Config.BUFFER_SIZE_CALLS.getIntegerValue());

	line.start();
}
 
开发者ID:tobiasschulz,项目名称:voipcall,代码行数:22,代码来源:CallRecorder.java

示例12: record

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
private byte[] record() throws LineUnavailableException {
    AudioFormat format = AudioUtil.getAudioFormat(audioConf);
    DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);

    // Checks if system supports the data line
    if (!AudioSystem.isLineSupported(info)) {
        LOGGER.error("Line not supported");
        System.exit(0);
    }

    microphone = (TargetDataLine) AudioSystem.getLine(info);
    microphone.open(format);
    microphone.start();

    LOGGER.info("Listening, tap enter to stop ...");

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    int numBytesRead;
    byte[] data = new byte[microphone.getBufferSize() / 5];

    // Begin audio capture.
    microphone.start();

    // Here, stopped is a global boolean set by another thread.
    while (!stopped) {
        // Read the next chunk of data from the TargetDataLine.
        numBytesRead = microphone.read(data, 0, data.length);
        // Save this chunk of data.
        byteArrayOutputStream.write(data, 0, numBytesRead);
    }

    return byteArrayOutputStream.toByteArray();
}
 
开发者ID:mautini,项目名称:google-assistant-java-demo,代码行数:34,代码来源:AudioRecorder.java

示例13: run

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
@Override
public void run() {

    try {
        AudioFormat af = SoundPacket.defaultFormat;
        DataLine.Info info = new DataLine.Info(TargetDataLine.class, null);
        mic = (TargetDataLine) (AudioSystem.getLine(info));
        mic.open(af);
        mic.start();
    } catch (Exception e) {
        System.out.println("Microfone não detectado.");
        JOptionPane.showMessageDialog(rootPane, "Microfone não detectado.", "AVISO: ", JOptionPane.INFORMATION_MESSAGE);
    }
    for (;;) {
        Utils.sleep(10);
        if (mic.available() > 0) {
            byte[] buff = new byte[SoundPacket.defaultDataLenght];
            mic.read(buff, 0, buff.length);
            long tot = 0;
            for (int i = 0; i < buff.length; i++) {
                tot += MicThread.amplification * Math.abs(buff[i]);
            }
            tot *= 2.5;
            tot /= buff.length;
            micLev.setValue((int) tot);
        }
    }
}
 
开发者ID:lucas-dolsan,项目名称:tcc-rpg,代码行数:29,代码来源:TelaConfigurarSom.java

示例14: MicThread

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
public MicThread(ObjectOutputStream toServer) throws LineUnavailableException {
    this.toServer = toServer;
    //open microphone line, an exception is thrown in case of error
    AudioFormat af = SoundPacket.defaultFormat;
    DataLine.Info info = new DataLine.Info(TargetDataLine.class, null);
    mic = (TargetDataLine) (AudioSystem.getLine(info));
    mic.open(af);
    mic.start();
}
 
开发者ID:lucas-dolsan,项目名称:tcc-rpg,代码行数:10,代码来源:MicThread.java

示例15: call

import javax.sound.sampled.TargetDataLine; //导入方法依赖的package包/类
@Override
public void call(final Subscriber<? super byte[]> child) {

	DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);

	// checks if system supports the data line
	if (!AudioSystem.isLineSupported(info)) {
		child.onError(new RuntimeException("line not supported for format "
				+ format));
		return;
	}

	try {
		TargetDataLine line = (TargetDataLine) AudioSystem.getLine(info);
		line.open(format);
		System.out.println("Starting capture...");
		line.start();
		byte[] buffer = new byte[bufferSize];
		while (!child.isUnsubscribed() && line.isOpen()) {
			int count = line.read(buffer, 0, bufferSize);
			if (count > 0)
				child.onNext(Arrays.copyOf(buffer, count));
		}
		child.onCompleted();
		line.close();
	} catch (LineUnavailableException e) {
		child.onError(e);
	}
}
 
开发者ID:davidmoten,项目名称:audio-recognition,代码行数:30,代码来源:MicrophoneOnSubscribe.java


注:本文中的javax.sound.sampled.TargetDataLine.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。