javasound

Can Java Sound be used to control the system volume?

风格不统一 提交于 2019-11-26 09:54:48
问题 Java Sound offers FloatControl instances for various sound line functionality, and both a MASTER_GAIN & VOLUME control type. Can these controls be used to change the system volume? 回答1: No, it cannot. Here is source adapted from an answer to Adjusting master volume on coderanch. The source iterates the available lines, checks if they have a control of the right type, and if so, puts them in a GUI attached to a JSlider import java.awt.*; import javax.swing.*; import javax.sound.sampled.*;

Audio volume control (increase or decrease) in Java

浪尽此生 提交于 2019-11-26 09:51:12
问题 How do I increase the volume of an outgoing wav audio stream using Java? I\'m having issues with various Java TTS engines and the output volume of the synthesized speech. Is there an API call or a doo-hickey.jar I can use to pump up the volume? 回答1: If you're using the Java Sound API, you can set the volume with the MASTER_GAIN control. import javax.sound.sampled.*; AudioInputStream audioInputStream = AudioSystem.getAudioInputStream( new File("some_file.wav")); Clip clip = AudioSystem.getClip

How do you play a long AudioClip?

允我心安 提交于 2019-11-26 05:38:29
问题 I have written a simple class to play audio files in a simple game. It works fine for small sounds like a gunshot or explosion, but when I tried to use it for background music I got this error: \'Failed to allocate clip data: Requested buffer too large.\' I am assuming this means that the file is too large, but how can I get around this? Source: import java.io.File; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; public

How do I use audio sample data from Java Sound?

六眼飞鱼酱① 提交于 2019-11-26 04:22:03
问题 This question is usually asked as a part of another question but it turns out that the answer is long. I\'ve decided to answer it here so I can link to it elsewhere. Although I\'m not aware of a way that Java can produce audio samples for us at this time, if that changes in the future, this can be a place for it. I know that JavaFX has some stuff like this, for example AudioSpectrumListener, but still not a way to access samples directly. I\'m using javax.sound.sampled for playback and/or

Join two WAV files from Java?

做~自己de王妃 提交于 2019-11-26 02:14:23
问题 What\'s the simplest way to concatenate two WAV files in Java 1.6? (Equal frequency and all, nothing fancy.) (This is probably sooo simple, but my Google-fu seems weak on this subject today.) 回答1: Here is the barebones code: import java.io.File; import java.io.IOException; import java.io.SequenceInputStream; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; public class WavAppender { public static void main(String[

Playing MP3 using Java Sound API

谁说胖子不能爱 提交于 2019-11-26 01:00:52
问题 Can you please suggest that how can i write a piece that plays a song.? I tried the following snippet but i get the this exception: import sun.audio.*; import java.io.*; class tester { public static void main(String args[]) throws Exception { InputStream in=new FileInputStream(\"tester.mp3\"); AudioStream as=new AudioStream(in); AudioPlayer.player.start(as); } } 回答1: As mentioned, Java Sound does not support MP3 by default. For the types it does support in any specific JRE, check AudioSystem

Playing MP3 using Java Sound API

为君一笑 提交于 2019-11-25 22:41:23
Can you please suggest that how can i write a piece that plays a song.? I tried the following snippet but i get the this exception: import sun.audio.*; import java.io.*; class tester { public static void main(String args[]) throws Exception { InputStream in=new FileInputStream("tester.mp3"); AudioStream as=new AudioStream(in); AudioPlayer.player.start(as); } } As mentioned, Java Sound does not support MP3 by default. For the types it does support in any specific JRE, check AudioSystem.getAudioFileTypes() . One way to add support for reading MP3 is to add the JMF based mp3plugin.jar 1 to the