javasound

Playing audio in java using Sun.audio

懵懂的女人 提交于 2019-11-27 15:58:22
I want just to perform a simple task. (I'm a java newbie). I want to play an audio clip when a button is clicked. here's the part of my code(which I did exactly by copying a tutorial from Youtube.) private void btnPlayActionPerformed(java.awt.event.ActionEvent evt) { InputStream in; try{ in=new FileInputStream(new File("C:\\Users\\Matt\\Documents\\dong.wav")); AudioStream timeupsound=new AudioStream(in); AudioPlayer.player.start(timeupsound); } catch(Exception e){ JOptionPane.showMessageDialog(null, e); } } But the problem is, this doesn't work. It throws and IOException saying: "could not

cutting a wave file

我的梦境 提交于 2019-11-27 15:26:29
问题 How can i cut a .wave file using java ? What i want is : when the user presses the button labeled cut it should cut the audio from the previous mark (in nanoseconds) to the current position in nanoseconds. (mark is positioned to the current position in nanoseconds after the sound is cut) After i get that piece of audio,i want to save that piece of audio file. // obtain an audio stream long mark = 0; // initially set to zero //get the current position in nanoseconds // after that how to

How to develop screen capture to video application

丶灬走出姿态 提交于 2019-11-27 10:58:33
I found similar questions in stackoverflow. But I want to be specific. I visited a web site screencast-o-matic . They have a web-application of java applet which capture screen to export as video. I want to develop similar application. What are the knowledge and steps required to do it? Thanks and regards. Edit another website screenr . Andrew Thompson To get a screenshot, use Robot.createScreenCapture(Rectangle) . To get many screenshots, call that in a loop invoked by a (Swing) Timer . Add them to an expandable collection such as an ArrayList . Convert the BufferedImage objects to JPEG

javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file when loading wav file

谁都会走 提交于 2019-11-27 09:19:39
i am using java 6 , and i am trying to load wav file, to get its duration as follows: public static double getAudioFileDuration(File file) { try { AudioInputStream stream = AudioSystem.getAudioInputStream(file); // At present, ALAW and ULAW encodings must be converted // to PCM_SIGNED before it can be played AudioFormat format = stream.getFormat(); if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) { format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(), format.getSampleSizeInBits(), format.getChannels(), format.getFrameSize(), format.getFrameRate(), true);

how can I wait for a java sound clip to finish playing back?

人走茶凉 提交于 2019-11-27 08:58:30
I am using the following code to play a sound file using the java sound API. Clip clip = AudioSystem.getClip(); AudioInputStream inputStream = AudioSystem.getAudioInputStream(stream); clip.open(inputStream); clip.start(); The method call to the Clip.start() method returns immediately, and the system playbacks the sound file in a background thread. I want my method to pause until the playback has completed. Is there any nice way to do it? EDIT: For everyone interested in my final solution, based on the answer from Uri, I used the code below: private final BlockingQueue<URL> queue = new

AudioInputStream is not working

╄→гoц情女王★ 提交于 2019-11-27 08:18:06
问题 I'm trying to play a .wav sound every time the user presses a button, but an exception gets thrown: Exception in thread "Thread-0" java.lang.IllegalArgumentException: Invalid format at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.createStream(PulseAudioDataLine.java:142) at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:99) at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:283) at org.classpath.icedtea.pulseaudio

Wav file convert to byte array in java

喜你入骨 提交于 2019-11-27 08:09:48
My project is 'Speech Recognition of Azeri speech'. I have to write a program that converts wav files to byte array. How to convert audio file to byte[]? Basically as described by the snippet in the first answer, but instead of the BufferedInputStream use AudioSystem.getAudioInputStream(File) to get the InputStream . Using the audio stream as obtained from AudioSystem will ensure that the headers are stripped, and the input file decode to a byte[] that represents the actual sound frames/samples - which can then be used for FFT etc. user1335794 Write this file into ByteArrayOutputStream

Capturing speaker output in Java

萝らか妹 提交于 2019-11-27 05:27:18
Using Java is it possible to capture the speaker output? This output is not being generated by my program but rather by other running applications. Can this be done with Java or will I need to resort to C/C++? Andrew Thompson I had a Java based app. that used Java Sound to tap into the sound flowing through the system to make a trace of it. It worked well on my own (Windows based) machine, but failed completely on some others. It was determined that in order to get it working on those machines, would take nothing short of an audio loop-back in either software or hardware (e.g. connect a lead

Java Program to create a PNG waveform for an audio file

我怕爱的太早我们不能终老 提交于 2019-11-27 04:18:32
How can you convert a Wav file into a PNG waveform image file using Java? java MyProgram.class [path to wav file] [path where to write png file] Expected results: Png saved in path specified is a waveform of the wav file passed in. Below is a java class that will do this very thing. There are certain parameters that I'm hard coding here like width of image, height of image, background color of image, and some more stuff. If you want to pull those out, you could. import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.font

Java raw audio output

北战南征 提交于 2019-11-27 04:08:16
Just wondering if there is a library in Java like the module PyAudiere in Python, that simply allows you to create tones and play them, like this sample Python code: device = audiere.open_device() tone = device.create_tone(500) #create a 500hz tone tone.play() tone.stop() This simply assigns a variable to your default sound device, and then makes a tone for that device and plays it then stops it. Are there any libraries like this that are as simple to use? I appreciate any and all feedback, thanks! :-D It is pretty simple to generate a sound in memory. E.G. The important part of generating the