javasound

java.io.IOException: mark/reset not supported Java Audio Input Stream / Buffered Input Stream

别来无恙 提交于 2019-12-06 11:31:52
I'm in the process of creating a 2D Java Platform Game and I'm trying to get audio to play from a .wav file while the game is running... Below is an AudioPlayer class I created to take care of loading the resource into an Audio Input Stream import javax.sound.sampled.*; import java.io.*; import java.util.*; import java.net.*; public class AudioPlayer { private Clip clip; public AudioPlayer(String s) { try { /************/ InputStream is = getClass().getResourceAsStream(s); AudioInputStream ais; BufferedInputStream bis = new BufferedInputStream(is); ais = AudioSystem.getAudioInputStream(bis); /

Working with audio in Java

ⅰ亾dé卋堺 提交于 2019-12-06 11:12:44
I went over Java's tutorial on sounds but somehow it is way too complex for a beginner. It is here My aim is this: Detect all the audio input and output devices let the user select a audio input device capture what the user says output it to the default audio output device Now how do I go about doing that? Is there a better tutorial available? What I have tried: import javax.sound.sampled.*; public class SoundTrial { public static void main(String[] args) { Mixer.Info[] info = AudioSystem.getMixerInfo(); int i =0; for(Mixer.Info print : info){ System.out.println("Name: "+ i + " " + print

Clip plays WAV file with bad lag in Java

自作多情 提交于 2019-12-06 05:00:47
问题 I've written a code that read a WAV file (size is about 80 mb) and plays that. The problem is that sound plays badly (extreme lags). Can you please tell me what's the problem? Here's my code: (I call the doPlay function inside a Jframe constructor) private void doPlay(final String path) { try { stopPlay(); InputStream is = new FileInputStream(path); InputStream bufferedIn = new BufferedInputStream(is); AudioInputStream ais = AudioSystem.getAudioInputStream(bufferedIn); AudioFormat format =

Play 2 different frequencies alternatively in Java

你离开我真会死。 提交于 2019-12-06 03:53:28
I am a newbie in Java Sounds. I want to play 2 different frequencies alternatively for 1 second each in a loop for some specified time. Like, if I have 2 frequencies 440hz and 16000hz and the time period is 10 seconds then for every 'even' second 440hz gets played and for every 'odd' second 16000hz, i.e. 5 seconds each alternatively. I have learned a few things through some examples and I have also made a program that runs for a single user specified frequency for a time also given by the user with the help of those examples. I will really appreciate if someone can help me out on this. Thanks.

Java Exception Reading Stream from Resource .wav

删除回忆录丶 提交于 2019-12-05 20:43:46
I guess my code is okay, and my .jar file its okay with the .wav inside it.. But when I try to load it using getResourceAsStream I get a error.. this is my error: java.io.IOException: mark/reset not supported at java.util.zip.InflaterInputStream.reset(Unknown Source) at java.io.FilterInputStream.reset(Unknown Source) at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unkno wn Source) at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at operation.MainWindowOperations.prepareAudio(MainWindowOperations.java :92) at operation.MainWindowOperations.<init>

Simulate microphone Input

和自甴很熟 提交于 2019-12-05 17:25:04
I am trying to write a little program that reads a wav file and sends the output as if it would come from my microphone. Unfortunately I do not have much experience with the sound API. Background: What I am basically trying to realize is a program that plays a sound while I am in a voicechat (i.e Teamspeak, Ventrilo). To get that to work now I would have to switch the recording device to "What you hear", play the sound and then switch back to microphone. The program should simulate input from the microphone. So far I could not get any further than just playing the sound. I guess I just need a

Downsampling audio from 44.1kHz to 16kHz in Java

喜夏-厌秋 提交于 2019-12-05 10:57:33
I have an application that records a speech sample from the user's microphone and uploads it to a server which then does some stuff with it. It seems I must record with the following parameters to avoid an IllegalArgumentException : Encoding encoding = AudioFormat.Encoding.PCM_SIGNED; float sampleRate = 44100.0F; int sampleSizeInBits = 16; int channels = 2; int frameSize = 4; float frameRate = 44100.0F; boolean bigEndian = false; But I need to have it recorded at 16khz, not 44.1, (sampleRate and framerate both, I assume) and it must be in mono (1 channel). The PCM signed is also mandatory, so

Java detecting an audio file (mp3)

不问归期 提交于 2019-12-05 03:24:19
问题 I have this code that reads an mp3 file import java.io.File; import java.io.IOException; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.UnsupportedAudioFileException; public class Sound { public static void main(String[] args) { File sampleFile = new File("test.mp3"); try { AudioSystem.getAudioFileFormat(sampleFile); } catch (UnsupportedAudioFileException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch

How to capture sound from microphone with java sound API?

走远了吗. 提交于 2019-12-05 00:44:47
问题 The tutorial http://download.oracle.com/javase/tutorial/sound/capturing.html does not cover how to select microphone. I am enumerating mixers with the following code System.out.println("Searching for microphones"); for(Mixer.Info mixerinfo : AudioSystem.getMixerInfo()) { mixer = AudioSystem.getMixer(mixerinfo); //System.out.println(mixerinfo.toString()); if( mixer.isLineSupported(Port.Info.MICROPHONE) ) { mixers.add(mixer); System.out.println(Integer.toString(mixers.size()) + ": " + mixerinfo

How to get Note On/Off messages from a MIDI sequence?

被刻印的时光 ゝ 提交于 2019-12-05 00:33:32
问题 I am hoping to get notifications of note on/off events in a playing MIDI sequence to show the notes on a screen based (piano) keyboard. The code below adds a MetaEventListener and a ControllerEventListener when playing a MIDI file, but only shows a few messages at the start and end of the track. How can we listen for note on & note off MIDI events? import java.io.File; import javax.sound.midi.*; import javax.swing.JOptionPane; class PlayMidi { public static void main(String[] args) throws