Search in sources :

Example 11 with TargetDataLine

use of javax.sound.sampled.TargetDataLine in project aws-doc-sdk-examples by awsdocs.

the class BidirectionalStreaming method get.

// snippet-end:[transcribe.java2.bidir_streaming.main]
public static TargetDataLine get() throws Exception {
    AudioFormat format = new AudioFormat(16000, 16, 1, true, false);
    DataLine.Info datalineInfo = new DataLine.Info(TargetDataLine.class, format);
    TargetDataLine dataLine = (TargetDataLine) AudioSystem.getLine(datalineInfo);
    dataLine.open(format);
    return dataLine;
}
Also used : TargetDataLine(javax.sound.sampled.TargetDataLine) DataLine(javax.sound.sampled.DataLine) AudioFormat(javax.sound.sampled.AudioFormat) TargetDataLine(javax.sound.sampled.TargetDataLine)

Example 12 with TargetDataLine

use of javax.sound.sampled.TargetDataLine in project java-google-speech-api by goxr3plus.

the class GSpeechDuplex method upChannel.

/**
 * 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;
}
Also used : AudioFormat(javax.sound.sampled.AudioFormat) TargetDataLine(javax.sound.sampled.TargetDataLine)

Aggregations

TargetDataLine (javax.sound.sampled.TargetDataLine)12 DataLine (javax.sound.sampled.DataLine)9 AudioFormat (javax.sound.sampled.AudioFormat)8 LineUnavailableException (javax.sound.sampled.LineUnavailableException)4 IOException (java.io.IOException)2 AudioInputStream (javax.sound.sampled.AudioInputStream)2 SourceDataLine (javax.sound.sampled.SourceDataLine)2 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)2 RecognizeOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognizeOptions)1 SpeechRecognitionResults (com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechRecognitionResults)1 BaseRecognizeCallback (com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.BaseRecognizeCallback)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 ShortBuffer (java.nio.ShortBuffer)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 AudioSystem (javax.sound.sampled.AudioSystem)1 Line (javax.sound.sampled.Line)1 Mixer (javax.sound.sampled.Mixer)1 MpegAudioFormat (javazoom.spi.mpeg.sampled.file.MpegAudioFormat)1 CanvasFrame (org.bytedeco.javacv.CanvasFrame)1