本文整理匯總了Java中javax.sound.sampled.TargetDataLine類的典型用法代碼示例。如果您正苦於以下問題:Java TargetDataLine類的具體用法?Java TargetDataLine怎麽用?Java TargetDataLine使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TargetDataLine類屬於javax.sound.sampled包,在下文中一共展示了TargetDataLine類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: VirtualDrummerMicrophoneInput
import javax.sound.sampled.TargetDataLine; //導入依賴的package包/類
/** Creates a new instance of test. Opens the microphone input as the target line.
* To start the reporting, {@link #start} the thread.
* @throws LineUnavailableException if microphone input is not available
*/
public VirtualDrummerMicrophoneInput () throws LineUnavailableException{
// getAudioInfo(); // prints lots of useless information
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,sampleRate,8,1,1,sampleRate,false);
DataLine.Info dlinfo = new DataLine.Info(TargetDataLine.class,
format);
if ( AudioSystem.isLineSupported(dlinfo) ){
targetDataLine = (TargetDataLine)AudioSystem.getLine(dlinfo);
}
targetDataLine.open(format,bufferSize);
bufferSize=targetDataLine.getBufferSize();
gui = new DrumSoundDetectorDemo();
gui.setVirtualDrummerMicrophoneInput(this);
}
示例2: getDefaultProvider
import javax.sound.sampled.TargetDataLine; //導入依賴的package包/類
/** Obtain the value of a default provider property.
@param typeClass The type of the default provider property. This
should be one of Receiver.class, Transmitter.class, Sequencer.class,
Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
Clip.class or Port.class.
@return The complete value of the property, if available.
If the property is not set, null is returned.
*/
private static synchronized String getDefaultProvider(Class typeClass) {
if (!SourceDataLine.class.equals(typeClass)
&& !TargetDataLine.class.equals(typeClass)
&& !Clip.class.equals(typeClass)
&& !Port.class.equals(typeClass)
&& !Receiver.class.equals(typeClass)
&& !Transmitter.class.equals(typeClass)
&& !Synthesizer.class.equals(typeClass)
&& !Sequencer.class.equals(typeClass)) {
return null;
}
String name = typeClass.getName();
String value = AccessController.doPrivileged(
(PrivilegedAction<String>) () -> System.getProperty(name));
if (value == null) {
value = getProperties().getProperty(name);
}
if ("".equals(value)) {
value = null;
}
return value;
}
示例3: 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;
}
示例4: getDefaultProvider
import javax.sound.sampled.TargetDataLine; //導入依賴的package包/類
/** Obtain the value of a default provider property.
@param typeClass The type of the default provider property. This
should be one of Receiver.class, Transmitter.class, Sequencer.class,
Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
Clip.class or Port.class.
@return The complete value of the property, if available.
If the property is not set, null is returned.
*/
private static synchronized String getDefaultProvider(Class<?> typeClass) {
if (!SourceDataLine.class.equals(typeClass)
&& !TargetDataLine.class.equals(typeClass)
&& !Clip.class.equals(typeClass)
&& !Port.class.equals(typeClass)
&& !Receiver.class.equals(typeClass)
&& !Transmitter.class.equals(typeClass)
&& !Synthesizer.class.equals(typeClass)
&& !Sequencer.class.equals(typeClass)) {
return null;
}
String name = typeClass.getName();
String value = AccessController.doPrivileged(
(PrivilegedAction<String>) () -> System.getProperty(name));
if (value == null) {
value = getProperties().getProperty(name);
}
if ("".equals(value)) {
value = null;
}
return value;
}
示例5: doMixerTDL
import javax.sound.sampled.TargetDataLine; //導入依賴的package包/類
private static void doMixerTDL(Mixer mixer, AudioFormat format) {
if (mixer==null) return;
try {
System.out.println("TDL from mixer "+mixer+":");
DataLine.Info info = new DataLine.Info(
TargetDataLine.class,
format);
if (mixer.isLineSupported(info)) {
TargetDataLine tdl = (TargetDataLine) mixer.getLine(info);
doLine1(tdl, format);
doLine2(tdl, format);
} else {
System.out.println(" - Line not supported");
}
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
}
}
示例6: setUp
import javax.sound.sampled.TargetDataLine; //導入依賴的package包/類
@Override
public String setUp() {
String result;
result = super.setUp();
if (result == null) {
m_AudioFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
m_Frequency, 16, 2, 4, m_Frequency, false);
m_DataLineInfo = new DataLine.Info(TargetDataLine.class, m_AudioFormat);
try {
m_TargetDataLine = (TargetDataLine) AudioSystem.getLine(m_DataLineInfo);
m_TargetDataLine.open(m_AudioFormat);
}
catch (Exception e) {
return "Unable to get recording line: " + Utils.throwableToString(e);
}
m_AudioInputStream = new AudioInputStream(m_TargetDataLine);
}
return result;
}
示例7: 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();
}
示例8: start
import javax.sound.sampled.TargetDataLine; //導入依賴的package包/類
@Override
public void start() {
try {
// start target line
mTargetInfo = new DataLine.Info(
TargetDataLine.class, VideoFormat.getAudioFormat());
mTargetLine = (TargetDataLine) AudioSystem.getLine(mTargetInfo);
mTargetLine.open(VideoFormat.getAudioFormat());
// start audio thread
mAudioThread = new Thread(this);
mAudioThread.setDaemon(true);
mAudioThread.start();
} catch (LineUnavailableException ex) {
Logs.error(getClass(), "Failed to open. {0}", ex);
}
}
示例9: recognize
import javax.sound.sampled.TargetDataLine; //導入依賴的package包/類
/**
* This method allows you to stream a continuous stream of data to the API.
* <p>
* Note: This feature is experimental.</p>
*
* @param tl
* @param af
* @throws IOException
* @throws LineUnavailableException
*/
public void recognize(TargetDataLine tl, AudioFormat af) throws IOException, LineUnavailableException {
//Generates a unique ID for the response.
final long PAIR = MIN + (long) (Math.random() * ((MAX - MIN) + 1L));
//Generates the Downstream URL
final String API_DOWN_URL = GOOGLE_DUPLEX_SPEECH_BASE + "down?maxresults=1&pair=" + PAIR;
//Generates the Upstream URL
final String API_UP_URL = GOOGLE_DUPLEX_SPEECH_BASE
+ "up?lang=" + language + "&lm=dictation&client=chromium&pair=" + PAIR
+ "&key=" + API_KEY + "&continuous=true&interim=true"; //Tells Google to constantly monitor the stream;
//Opens downChannel
this.downChannel(API_DOWN_URL);
//Opens upChannel
this.upChannel(API_UP_URL, tl, af);
}
示例10: getSources
import javax.sound.sampled.TargetDataLine; //導入依賴的package包/類
public synchronized static String[] getSources() {
if(sources.isEmpty()) {
for(Mixer.Info mixerInfo : AudioSystem.getMixerInfo()) {
try(Mixer mixer = AudioSystem.getMixer(mixerInfo)) {
for(Line.Info lineInfo : mixer.getTargetLineInfo()) {
if(TargetDataLine.class.isAssignableFrom(lineInfo.getLineClass()))
sources.add(new Pair<>(mixerInfo, lineInfo));
}
}
}
}
String[] result = new String[sources.size()];
int idx = 0;
for(Pair<Mixer.Info, Line.Info> src : sources)
result[idx++] = src.first.getName();
return result;
}
示例11: testGetAudioFormatMp3
import javax.sound.sampled.TargetDataLine; //導入依賴的package包/類
/**
* Test method for {@link com.deb.vad.utility.CommonUtil#getAudioFormatMp3()}.
*/
public final void testGetAudioFormatMp3() {
// package com.ibm.emb.test.mfb; study this package.
// Not working [PCM_SIGNED, PCM_UNSIGNED, ALAW, ULAW]
// interface TargetDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 16000 bytes/frame, 16.0 frames/second, big-endian
// Working
// interface TargetDataLine supporting format PCM_SIGNED 16000.0 Hz, 8 bit, mono, 1 bytes/frame,
AudioFormat mp3Format = CommonUtil.getAudioFormatMp3();
Encoding[] encoding = AudioSystem.getTargetEncodings(mp3Format);
System.out.println(Arrays.toString(encoding));
DataLine.Info info = new DataLine.Info(TargetDataLine.class, mp3Format);
System.out.println(info.toString());
if (!AudioSystem.isLineSupported(info)) {
assertFalse("Line not supported. Sorry I am leaving...",true);
}
}
示例12: MixerTuner
import javax.sound.sampled.TargetDataLine; //導入依賴的package包/類
/**
* Wrapper class to add basic Tuner functionality to the ComplexMixer.
* Subclasses should couple this functionality with a tuner controller class
* to support tuning.
*/
public MixerTuner( String name,
TunerController tunerController,
MixerTunerType mixerTunerType,
TargetDataLine targetDataLine,
ISampleAdapter sampleAdapter )
{
super( name, tunerController );
mMixerTunerType = mixerTunerType;
mComplexMixer = new ComplexMixer( targetDataLine,
mMixerTunerType.getAudioFormat(),
name,
sampleAdapter,
(Listener<ComplexBuffer>)this );
}
示例13: 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
}
示例14: 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));
}
}
示例15: 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();
}