/** * Sets the InputStream from which this StreamDataSource reads. * * @param inputStream the InputStream from which audio data comes * @param streamName the name of the InputStream */ public void setInputStream(AudioInputStream inputStream, String streamName) { dataStream = inputStream; streamEndReached = false; utteranceEndSent = false; utteranceStarted = false; AudioFormat format = inputStream.getFormat(); sampleRate = (int) format.getSampleRate(); bigEndian = format.isBigEndian(); String s = format.toString(); logger.finer("input format is " + s); if (format.getSampleSizeInBits() % 8 != 0) throw new Error("StreamDataSource: bits per sample must be a multiple of 8."); bytesPerValue = format.getSampleSizeInBits() / 8; // test whether all files in the stream have the same format AudioFormat.Encoding encoding = format.getEncoding(); if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED)) signedData = true; else if (encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED)) signedData = false; else throw new RuntimeException("used file encoding is not supported"); totalValuesRead = 0; }
private static void listTargetDataLines() { out("Available Mixers:"); Mixer.Info[] aInfos = AudioSystem.getMixerInfo(); for (int i = 0; i < aInfos.length; i++) { Mixer mixer = AudioSystem.getMixer(aInfos[i]); // mixer.open(); Line.Info[] lines = mixer.getTargetLineInfo(); out(aInfos[i].getName()); for (int j = 0; j < lines.length; j++) { out(" " + lines[j].toString()); if (lines[j] instanceof DataLine.Info) { AudioFormat[] formats = ((DataLine.Info) lines[j]).getFormats(); for (int k = 0; k < formats.length; k++) { out(" " + formats[k].toString()); } } } } }
private static void listTargetDataLines() { out("Available Mixers:"); Mixer.Info[] aInfos = AudioSystem.getMixerInfo(); for (int i = 0; i < aInfos.length; i++) { Mixer mixer = AudioSystem.getMixer(aInfos[i]); // mixer.open(); Line.Info[] lines = mixer.getTargetLineInfo(); out(aInfos[i].getName()); for (int j = 0; j < lines.length; j++) { out(" " + lines[j].toString()); if (lines[j] instanceof DataLine.Info) { AudioFormat[] formats = ((DataLine.Info) lines[j]).getFormats(); for (int k = 0; k < formats.length; k++) { out(" " + formats[k].toString()); } } } } }
private static void listTargetDataLines() { out("Available Mixers:"); Mixer.Info[] aInfos = AudioSystem.getMixerInfo(); for (int i = 0; i < aInfos.length; i++) { Mixer mixer = AudioSystem.getMixer(aInfos[i]); // mixer.open(); Line.Info[] lines = mixer.getTargetLineInfo(); out(aInfos[i].getName()); for (int j = 0; j < lines.length; j++) { out(" " + lines[j].toString()); if (lines[j] instanceof DataLine.Info) { AudioFormat[] formats = ((DataLine.Info) lines[j]).getFormats(); for (int k = 0; k < formats.length; k++) { out(" " + formats[k].toString()); } } } } }
private static void listTargetDataLines() { out("Available Mixers:"); Mixer.Info[] aInfos = AudioSystem.getMixerInfo(); for (int i = 0; i < aInfos.length; i++) { Mixer mixer = AudioSystem.getMixer(aInfos[i]); // mixer.open(); Line.Info[] lines = mixer.getTargetLineInfo(); out(aInfos[i].getName()); for (int j = 0; j < lines.length; j++) { out(" " + lines[j].toString()); if (lines[j] instanceof DataLine.Info) { AudioFormat[] formats = ((DataLine.Info) lines[j]).getFormats(); for (int k = 0; k < formats.length; k++) { out(" " + formats[k].toString()); } } } } }
private static final void checkFormat(AudioFormat af) { if (!af.matches(SC_AUDIO_FORMAT)) { throw new IllegalArgumentException( "Unsupported audio format.\nReceived: " + af.toString() + "\nExpected: " + SC_AUDIO_FORMAT); } } }
@Override public synchronized AudioFormat getFormatFromUniqueName(String name) { for (AudioFormat fmt : getFormats()) if (fmt.toString().contentEquals(name)) return fmt; System.err.println("Failed to find matching format for "+name); return null; } @Override
@Override public void itemStateChanged(ItemEvent e) { if(e.getStateChange() != ItemEvent.SELECTED) return; try{ //Repopulate format list final AudioOutput selectedPort = getSelectedPort(); final AudioFormat [] formats = selectedPort.getFormats(); final DefaultComboBoxModel formatLM = (DefaultComboBoxModel)audioFormatCB.getModel(); formatLM.removeAllElements(); for( AudioFormat format : formats ) formatLM.addElement(format.toString()); }catch(Exception ex) {ex.printStackTrace();} }});
public AudioInputStream getAudioInputStream(AudioFormat targetFormat, AudioInputStream sourceStream) { AudioFormat inputFormat = sourceStream.getFormat(); AudioFormat outputFormat = targetFormat; if (isConversionSupported(inputFormat, outputFormat)) { JSSRCResampler resampler = new JSSRCResampler(inputFormat, outputFormat, sourceStream); // set sample size from source stream if possible long length = AudioSystem.NOT_SPECIFIED; if (AudioSystem.NOT_SPECIFIED != sourceStream.getFrameLength()) { length = (long) (sourceStream.getFrameLength() * targetFormat.getSampleRate() / inputFormat.getSampleRate()); } return new AudioInputStream(resampler, outputFormat, length); } throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetFormat.toString()); }
public AudioInputStream getAudioInputStream(AudioFormat targetFormat, AudioInputStream sourceStream) { AudioFormat inputFormat = sourceStream.getFormat(); AudioFormat outputFormat = targetFormat; if (isConversionSupported(inputFormat, outputFormat)) { JSSRCResampler resampler = new JSSRCResampler(inputFormat, outputFormat, sourceStream); // set sample size from source stream if possible long length = AudioSystem.NOT_SPECIFIED; if (AudioSystem.NOT_SPECIFIED != sourceStream.getFrameLength()) { length = (long) (sourceStream.getFrameLength() * targetFormat.getSampleRate() / inputFormat.getSampleRate()); } return new AudioInputStream(resampler, outputFormat, length); } throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetFormat.toString()); }
System.out.print("no support for " + wav.toString() );
System.out.println(" " + format.toString());
for (AudioFormat format : formats) System.out.println(" " + format.toString());
+ type.toString() + " format " + format.toString() + " and bufferSize " + bufferSize + ".\n" + "The reason is " + badarg.getMessage());
URL url = new URL( "https://sssss/xxxxx/playback.php?access=subscriber&login=501%40mix&domain=mix.nms.mixnetworks.net&user=501&type=vmail&file=vm-20130109213243000082_mixnetworks_net.wav&time=20130110170638&auth=c43ff32546e126be9b895bbf225b2e75&submit=PLAY"); AudioInputStream fis = AudioSystem.getAudioInputStream(url); System.out.println("File AudioFormat: " + fis.getFormat()); AudioInputStream ais = AudioSystem.getAudioInputStream( AudioFormat.Encoding.PCM_SIGNED,fis); AudioFormat af = ais.getFormat(); System.out.println("AudioFormat: " + af.toString()); int frameRate = (int)af.getFrameRate(); System.out.println("Frame Rate: " + frameRate); int frameSize = af.getFrameSize(); System.out.println("Frame Size: " + frameSize); SourceDataLine line = AudioSystem.getSourceDataLine(af); line.addLineListener(new MyLineListener()); line.open(af); int bufSize = line.getBufferSize(); System.out.println("Buffer Size: " + bufSize); line.start(); byte[] data = new byte[bufSize]; int bytesRead; while ((bytesRead = ais.read(data,0,data.length)) != -1) line.write(data,0,bytesRead); line.drain(); line.stop(); line.close();
/** * Sets the InputStream from which this StreamDataSource reads. * * @param inputStream the InputStream from which audio data comes * @param streamName the name of the InputStream */ public void setInputStream(AudioInputStream inputStream, String streamName) { dataStream = inputStream; streamEndReached = false; utteranceEndSent = false; utteranceStarted = false; AudioFormat format = inputStream.getFormat(); sampleRate = (int) format.getSampleRate(); bigEndian = format.isBigEndian(); String s = format.toString(); logger.finer("input format is " + s); if (format.getSampleSizeInBits() % 8 != 0) throw new Error("StreamDataSource: bits per sample must be a multiple of 8."); bytesPerValue = format.getSampleSizeInBits() / 8; // test whether all files in the stream have the same format AudioFormat.Encoding encoding = format.getEncoding(); if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED)) signedData = true; else if (encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED)) signedData = false; else throw new RuntimeException("used file encoding is not supported"); totalValuesRead = 0; }
/** */ public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream) { if (isConversionSupported(targetEncoding, sourceStream.getFormat())) { AudioFormat sourceFormat = sourceStream.getFormat(); AudioFormat targetFormat = new AudioFormat(targetEncoding, sourceFormat.getSampleRate(), sourceFormat.getSampleSizeInBits(), sourceFormat.getChannels(), sourceFormat.getFrameSize(), sourceFormat.getFrameRate(), sourceFormat.isBigEndian()); return getAudioInputStream(targetFormat, sourceStream); } else { throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetEncoding.toString()); } }
/** */ public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream) { if (isConversionSupported(targetEncoding, sourceStream.getFormat())) { AudioFormat sourceFormat = sourceStream.getFormat(); AudioFormat targetFormat = new AudioFormat(targetEncoding, sourceFormat.getSampleRate(), sourceFormat.getSampleSizeInBits(), sourceFormat.getChannels(), sourceFormat.getFrameSize(), sourceFormat.getFrameRate(), sourceFormat.isBigEndian()); return getAudioInputStream(targetFormat, sourceStream); } else { throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetEncoding.toString()); } }