java类javax.sound.sampled.TargetDataLine的实例源码

GSpeechDuplex.java 文件源码 项目:java-google-speech-api 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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;

}
VirtualDrummerMicrophoneInput.java 文件源码 项目:jaer 阅读 24 收藏 0 点赞 0 评论 0
/** 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);

    }
JDK13Services.java 文件源码 项目:OpenJSharp 阅读 23 收藏 0 点赞 0 评论 0
/** 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;
}
JDK13Services.java 文件源码 项目:jdk8u-jdk 阅读 24 收藏 0 点赞 0 评论 0
/** 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;
}
JDK13Services.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
/** 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;
}
LineDefFormat.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
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());
    }
}
JDK13Services.java 文件源码 项目:openjdk9 阅读 20 收藏 0 点赞 0 评论 0
/** 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;
}
SampledSoundRecorder.java 文件源码 项目:screencast4j 阅读 19 收藏 0 点赞 0 评论 0
@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;
 }
JDK13Services.java 文件源码 项目:jdk8u_jdk 阅读 27 收藏 0 点赞 0 评论 0
/** 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;
}
JDK13Services.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 23 收藏 0 点赞 0 评论 0
/** 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;
}
AudioStream.java 文件源码 项目:cloudturbine 阅读 46 收藏 0 点赞 0 评论 0
/**
 * 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();
}
MicrophoneAudio.java 文件源码 项目:Tuntuni 阅读 19 收藏 0 点赞 0 评论 0
@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);
    }
}
GSpeechDuplex.java 文件源码 项目:SpeechRaspberrySmartHouse 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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);
}
GSpeechDuplex.java 文件源码 项目:SpeechRaspberrySmartHouse 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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);
}
GSpeechDuplex.java 文件源码 项目:SpeechRaspberrySmartHouse 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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);
}
GSpeechDuplex.java 文件源码 项目:SpeechRaspberrySmartHouse 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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);
}
GSpeechDuplex.java 文件源码 项目:SpeechRaspberrySmartHouse 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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);
}
GSpeechDuplex.java 文件源码 项目:SpeechRaspberrySmartHouse 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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);
}
GSpeechDuplex.java 文件源码 项目:SpeechRaspberrySmartHouse 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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);
}
GSpeechDuplex.java 文件源码 项目:SpeechRaspberrySmartHouse 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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);
}
GSpeechDuplex.java 文件源码 项目:SpeechRaspberrySmartHouse 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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);
}
JavaSoundSource.java 文件源码 项目:ether 阅读 17 收藏 0 点赞 0 评论 0
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;
}
CommonUtilTest.java 文件源码 项目:JavaVAD 阅读 22 收藏 0 点赞 0 评论 0
/**
     * 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);

        }
    }
MixerTuner.java 文件源码 项目:sdrtrunk 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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 );
}
SampledSoundRecorder.java 文件源码 项目:screencast4j 阅读 20 收藏 0 点赞 0 评论 0
@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;
 }
AudioCapture.java 文件源码 项目:project-bianca 阅读 22 收藏 0 点赞 0 评论 0
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
}
GoogleSTT.java 文件源码 项目:project-bianca 阅读 19 收藏 0 点赞 0 评论 0
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));
    }
}
FreqThread.java 文件源码 项目:KaraOK 阅读 21 收藏 0 点赞 0 评论 0
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();


        }
PitchTracking.java 文件源码 项目:MakamBox 阅读 29 收藏 0 点赞 0 评论 0
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);
    }
}
JDK13Services.java 文件源码 项目:infobip-open-jdk-8 阅读 22 收藏 0 点赞 0 评论 0
/** 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;
}


问题


面经


文章

微信
公众号

扫码关注公众号