I want to alert the user in a Swing application of certain events with an old fashioned PC Speaker beep (NOT the soundcard), since not on every PC there is a soundcard with an attached speaker, or volume might be turned to zero, or a headphone might be connected... How can I do this?
UPDATE:
java.awt.Toolkit.getDefaultToolkit().beep() seems usually to generate a sound on the soundcard. It only uses the speaker if there is no active soundcard.
To print an ASCII value 7 works only if the application is launched in a terminal, which at least a Swing app usually isn't.
So the question is still open.
Toolkit.getDefaultToolkit().beep();
Try this:
java.awt.Toolkit.getDefaultToolkit().beep();
It worked for me, although I'm not sure whether this was the PC Speaker beep or some OS-generated beep.
I read somewhere that you need to use a C/C++ dll and connect it with JNI, to make that work,.. link is offline
Ok I found what you're looking for
http://pyx4j.com/pyx4j-native/index.html
he pyx4j-native project is a collection of java wrappers for windows functions like time and beep. Now only works on windows.
NativeThreadDump - Send CtrlBreak Event to current process
Beep - Make a sound using PC speaker
FileUtil - Access and modify file creation time. Used in com.pyx4j.log.RollingFileAppender
NativeTimer - System high-resolution performance counter used before Java 5
Other than the beep sound you can try
JFugue.
JFugue is an open-source Java API for programming music without the complexities of MIDI.
ASCII value 7 is a beep. So just print that character.
{
If (whatever you named the file) = true
Then
Process.Start ("C:\Windows\Media\{whatever you named the file})
}
I use that in C#. It's late for me the code is not exactly accurate before people bash this post. Put a write directory to name a folder and declare it the default location. Move the sound of your choice to this folder and it will play the audio tone. Set the timer in Java to loop the sound every 2 seconds to get the persons attention. Hope this helps as I'm learning my self!
Related
I'm trying to get the data that the soundcard is outputting. Unfortunately, from my understanding of the Java Sound API, SourceDataLine does not support the read method, and there is no way to listen for raw data. I want to stick to Java for this, rather than C++, so if anyone knows how to listen for audio output on the soundcard that would be great.
Thanks very much!
Sorry if this post is confusing, just woke up.
I've researched this a while, and determined any implementation using only java sound will not work with any reliability on multiple audio cards.
There are a few solutions though. Hopefully one of these helps you.
Bite the bullet, write some C++ code to allow this functionality on different operating systems.
Use Java Sound to capture audio from a virtual audio recorder adapter which loops back the system audio output.
Create a loopback yourself using cables to feed a sound output port into a sound input port.
I recommend option 1 if you're developing this for a professional application as installation will be cleaner.
Go with option 2 if you've a short amount of time, and you expect to spend more time with your users, or your users are tech savvy.
Use option 3 if this is just a hobby, or some one-off project for a client.
After extensive searches I can't find any information on how to detect the microphone sound level input in mac OSX using either Applescript or Java.
The purpose of this is to write an automatic volume adjust script based on the sound level detected by the built in microphone.
I know that commercial solutions exist but I'm interested simply as an exercise.
Just in case people think I'm posting on here just to make a statement I'm informed that I should add something to which a question mark can be added or people won't understand that it's a question.
I am after some example code in either java or applescript to show how to detect the microphone input sound level. Can anyone help with this?
set currentVolume to output volume of (get volume settings)
This is from a MacScripter thread that will probably answer some more of your questions on this project as well.
I'm trying to write a little background program that stops music playing Winamp when another program plays sounds. The part about the accessing Winamp through Java is already solved now I need a way to detect which program plays the currently played sound (probably I want to allow some programs to play their sound without stopping my music). Although I'm doing this in Java (+ the winapi) everything in any language would help.
[edit] as I just got the first downvote on my first question here is some more detail: I already figured out how to use the winapi (but I don't know it) and capture things like volume levels and stuff. What still makes trouble is the mentioned detection of the origin of a sound that is played and aslo which program plays sounds. Is there anything in the winapi that could help me to do this?[/edit]
As Deanna mentioned, you can enumerate audio playback sessions just like Volume Mixer application (started from system tray icon) does and obtain per-session meters indicating session status.
You can find a C++ application that does it in this answer: Peak meters for individual programs on Windows 7. The meters are per-session and an audio-enabled application might have one or more sessions in it, but eventually as long as you enumerate them, you can figure out if there is any active playback there.
I believe the Windows Core Audio API in Vista+ allows you to get the VU levels for each application (After all, the mixer shows it). This should allow you to turn down one application when another is playing, etc.
I have written a few hundred line app in Clojure that uses the JLayer Java library for audio where I run mp3s in the background. This works fine but as soon as I run any other music, YouTube etc in the background (I'm running Arch Linux) the sounds in my app completely stop.
I have wasted the last two hours and tried dozens of things to fix this so any advice is appreciated.
Since you have stated that you're on Linux, the problem could be on your ALSA driver.
Check whether this article will help you fix the problem.
Though I have no personal coding experience with sound in Java, it is my understanding that there are some mismatched assumptions and/or incomplete APIs when it comes to Linux sound services and also with Java sound interfaces. Mix the two together and you get what you've run into. While playing with FreeTTS, I rand into similar, possibly same problem:
FreeTTS, Java, Linux: Workaround for "LINE UNAVAILABLE: Format is ..."
I've had problems with PulseAudio and Jack fighting for control of sound card before.
Have you considered that? Can you check whether the two apps are fighting each other in that way?
Let me first state that I do not know Java. I'm a .NET developer with solid C# skills, but I'm actually attempting to learn Java and the Android SDK at the same time (I know it's probably not ideal, but oh well, I'm adventurous :))
That said, my end goal is to write a streaming media player for Android that can accept Windows Media streams. I'm okay with restricting myself to Android 2.0 and greater if I need to. My current device is a Motorola Droid running Android 2.0.1. There is one online radio service I listen to religiously on my PC that only offers Windows Media streaming, and I'd like to transcode the stream so my Android device can play it.
Is such a thing possible? If so, would it be feasible (i.e., would it be too CPU intensive and kill the battery)? Should I be looking into doing this with the NDK in native code instead of Java? I'm not opposed to writing some sort of service in between that runs on a desktop computer (even in C#), but ideally I'd like to explore purely device-based options first. Where should I start?
Thanks in advance for any insight you can provide!
Having a proxy on your PC that captures windows audio output, encodes it, and sends it to your phone is perfectly possible. I had something like that 8 years ago on a linux-based PDA (sharp zaurus). The trick is that you're not trying to decode or access the XM radio stream directly, you're simply capturing what is being sent to the speakers on your desktop and re-sending it. There will be a minor hit in audio quality due to the re-encode, but shouldn't be too bad.
I've done cloud-to-phone transcoding using an alpha version of Android Cloud Services. The transcoding is transparently done on a server and the resulting stream is streamed on the phone. Might worth having a look. http://positivelydisruptive.blogspot.com/2010/08/streaming-m4a-files-using-android-cloud.html