javasound

Playing an audio file on JButton press?

末鹿安然 提交于 2019-11-29 17:42:22
I've looked on Google for a while, searching how to play audio files, and most of the sources I found were with using java.applet.* , but I am trying to look for a way I can put it inside my actionPerformed() method. public void actionPerformed(ActionEvent event) { if(event.getActionCommand().equals("Play")){ //Short Audio File Playing Here } } Andrew Thompson See the JavaSound info. page for the "Playing a Clip" section. You may learn and use javax.sound API. Have a look at tutorial - Playing Back Audio . 来源: https://stackoverflow.com/questions/8997363/playing-an-audio-file-on-jbutton-press

MIDI beginner - need to play one note

我怕爱的太早我们不能终老 提交于 2019-11-29 17:34:46
问题 I don't know very much about Java's MIDI function. In fact, it utterly bewilders me. what I'd like to do however is just build a simple application that will play one note. How to play a single MIDI note using Java Sound? The support for this out on the web is almost nonexistent, and I am totally at a loss. 回答1: I know this is a really old question, but, as a novice programmer, I had a very difficult time figuring out how to do this, so I thought I would share the following hello-world-style

how do I get Mixer channels layout in java

别说谁变了你拦得住时间么 提交于 2019-11-29 12:12:30
I thought I can find anything on this great site but now I seem to face the issue with no answer :) Please help! Thing is, I need to play up to 6 different wav files with 1 channel each into 6 channels supported by system mixer (left, right, surround left, etc). Using 6 different SourceDataLines looks logical but from what I see, Mixer cannot do per-sample synchronisation for them, so I came up with interleaving them in separate thread and use only one SourceDataLine to play it. It works fine for two channels, left and right but for more channels I need to know precise channels layout (may be

How can i remove background noise with java, while recording audio in a crowd zone?

情到浓时终转凉″ 提交于 2019-11-29 09:36:55
问题 When i capture with JavaSound or Third party sound capture tools and record it to a file. Afterwards read the file back to modify it, is there any way to remove the "background noise" with my java application. Such as road traffic/air noises while main person was talking? Thanks 回答1: Removing background noise is very difficult. If it is uniform noise, such as the "white" noise on an airplane, there are algorithms to remove those frequency components. But if the noise is non-uniform and

Audio Clip won't loop continuously

怎甘沉沦 提交于 2019-11-29 06:59:25
Can anyone point me in the right direction as to why this code will not play this audio clip continuously? It plays it once and stops. final Clip clip = AudioSystem.getClip(); final AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File("Alarm_Police.wav")); clip.open(inputStream); clip.loop(Clip.LOOP_CONTINUOUSLY); If you are running a bigger application, this answer may not apply. But for a simple test with only that piece of code, this may help: Clip.loop() starts it's own thread, but that thread will not keep the JVM alive. So to make it work, make sure the clip is not the

JavaSound mixer with both Port(s) and DataLine(s)?

大憨熊 提交于 2019-11-29 05:18:16
The diagrms in the JavaSound API Programmer's Guide appear to imply (pp. 19-20) that a Mixer can in principle have both DataLines and Ports. However, I was wondering if anyone had actually seen this configuration? What I witness is that where relevant, Mixers come in pairs, one with a source/target data line, and then the other with the corresponding Port. Has anyone witnessed a configuration as implied in the Guide, with a mixer having both port and data line (or am I misinterpreting the guide)? It would appear that the intention of the JavaSound API was to allow a Mixer to handle both

javax.sound.sampled.LineUnavailableException : What am I getting this exception?

浪子不回头ぞ 提交于 2019-11-29 05:07:20
As the following method is called : private void beep_player_1() { try { //clip_Player_2.close(); clip_Player_1 = AudioSystem.getClip(); ais = AudioSystem.getAudioInputStream(new File(Constants.Player1_Default_Tone)); // PATH FOR THE .WAV FILE clip_Player_1.open(ais); clip_Player_1.loop(0); // PLAY ONCE }catch(Exception exc) { System.out.println(exc); } } LineUnavailableException get thrown. What could be the reason for this ? javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 24 bit, stereo, 6 bytes/frame, little-endian not supported. What could be the

cutting a wave file

拥有回忆 提交于 2019-11-29 00:41:53
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 proceed ? // another method ? How can i do that ? Suhail Gupta This has originally been answered by Martin

What output and recording ports does the Java Sound API find on your computer? [closed]

半腔热情 提交于 2019-11-28 23:52:47
I'm working with the Java Sound API , and it turns out if I want to adjust recording volumes I need to model the hardware that the OS exposes to Java. Turns out there's a lot of variety in what's presented. Because of this I'm humbly asking that anyone able to help me run the following on their computer and post back the results so that I can get an idea of what's out there. A thanks in advance to anyone that can assist :-) import javax.sound.sampled.*; public class SoundAudit { public static void main(String[] args) { try { System.out.println("OS: "+System.getProperty("os.name")+" "+ System

Clip not playing any sound

99封情书 提交于 2019-11-28 14:39:05
Well, the title says all, I tried playing a wav file using javax.sound and nothing is happening. I have tried many different files without any luck. public static void main(String[] args) throws IOException, UnsupportedAudioFileException, LineUnavailableException { File in = new File("C:\\Users\\Sandra\\Desktop\\music\\rags.wav"); AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(in); Clip play = AudioSystem.getClip(); play.open(audioInputStream); FloatControl volume= (FloatControl) play.getControl(FloatControl.Type.MASTER_GAIN); volume.setValue(1.0f); // Reduce volume by 10