javax.sound.sampled

Java: Processing audio in real time from speakers

£可爱£侵袭症+ 提交于 2021-02-08 06:39:39
问题 I'm working on a project that will change the brightness of keyboard lights with PWM signal, according to output sound levels. That trouble is, I need the output stream in real time. So far I used javax.sound.sampled package and I never succeeded grabbing the audio output. However, what have I done was to use targetDataLine and sourceDataLine, which don't look like the way to go, I'm still trying though. What I need is an audio stream provider, which my java app can "hear" and process it. So

How can I loop a sound without using 'clip' in java before writing it into a file

 ̄綄美尐妖づ 提交于 2020-01-05 04:54:09
问题 First of all thanks everyone for helping me with my previous questions. In the following code I am taking two frequencies alternatively and writing them into a .wav format, to run it in my Windows Media Player, for a specific time given by the user. What I want is to understand how to loop those frequencies to run alternatively for that specified time, like the Ambulance's siren, and in my program both frequencies are getting played just once, alternatively. For example, if I am specifying

How to calculate the level/amplitude/db of audio signal in java?

Deadly 提交于 2019-12-17 17:59:10
问题 I want to create a audio level meter in java for the microphone to check how loud the input is. It should look like the one of the OS. I'm not asking about the gui. It is just about calculating the audio level out of the bytestream produced by n = targetDataLine.read( tempBuffer , 0 , tempBuffer.length ); So I already have something that is running, but it is not even close to the levelmeter of my OS (windows) It stucks in the middle. I have values between 0 and 100 that is good but in the

Cannot do anything while writing to a SourceDataLine

我的未来我决定 提交于 2019-12-13 02:08:43
问题 I am somewhat new to audio in Java. What I am trying to do is as I am playing audio, I want to repaint my JComponent , but the SourceDataLine blocks all other lines of code including other Threads. Here is my play() method public void play() { final AudioFormat af =new AudioFormat(Note.SAMPLE_RATE, 8, 1, true, true); SourceDataLine line; try { line = AudioSystem.getSourceDataLine(af); line.open(af, Note.SAMPLE_RATE); line.start(); byte[] arr=data; for(int position=0;position<arr.length

Concatenation of two WAV files failed

狂风中的少年 提交于 2019-12-12 16:30:03
问题 I have this simple code to concatenate two wav files. Its pretty simple and the code runs without any errors. But there is a problem with the output file. The output file generated does not play, and surprisingly its size is only 44 bytes whereas my input files "a.wav" & "b.wav" are both more than 500Kb in size. Here is my code: import java.io.File; import java.io.IOException; import java.io.SequenceInputStream; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled

How to write a generated audio into a .wav format in java

僤鯓⒐⒋嵵緔 提交于 2019-12-11 05:48:37
问题 I am very new in Java Sound and therefore my concepts of it are not that strong. I want to understand that how to write the audio generated by the following code into a file of .wav format. I had read a few posts and some questions on stackoverflow as well, but I am not able to make out the solution out of them. So please help me understand it. Thanks. import javax.sound.sampled.*; import java.nio.ByteBuffer; import java.util.Scanner; public class Audio { //Alternating Tones public static

Play 2 different frequencies alternatively in Java

依然范特西╮ 提交于 2019-12-10 10:11:24
问题 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

Java Voice Server Not Working

两盒软妹~` 提交于 2019-12-08 03:49:33
问题 I am trying to make a voice server and the server is throwing this error "javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 8000.0 Hz, 8 bit, mono, 1 bytes/frame, not supported." . Here is my code, Thank you in advance public class VoiceUser extends Thread { // CHAT USER private ObjectOutputStream clientOutput; public VoiceUser(Socket sv) { try { System.out.println("VSTART"); clientOutput = new ObjectOutputStream(sv.getOutputStream()); outputArray.add(clientOutput); }

Java AudioSystem: Reading 32 Bit Wav Files

自闭症网瘾萝莉.ら 提交于 2019-12-08 01:24:32
问题 I'm reading in audio files in 16 and 24 bit sampling bit depths and parsing them to determine their lengths without difficulty. However when reading a 32 bit file, I get javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1170) ... The 32 bit test file is manually encoded in the same manner as the others (linear PCM). I'm wondering if AudioSystem doesn't support 32 bit Wavs,

Java Voice Server Not Working

喜你入骨 提交于 2019-12-06 17:37:32
I am trying to make a voice server and the server is throwing this error "javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 8000.0 Hz, 8 bit, mono, 1 bytes/frame, not supported." . Here is my code, Thank you in advance public class VoiceUser extends Thread { // CHAT USER private ObjectOutputStream clientOutput; public VoiceUser(Socket sv) { try { System.out.println("VSTART"); clientOutput = new ObjectOutputStream(sv.getOutputStream()); outputArray.add(clientOutput); } catch (IOException e) { System.out.println("Can't create stable connection between server and client");