Applescript / Java - Detecting microphone input sound level - java

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.

Related

Use Java or other languages in a Flutter Application

Since I got no answer and not much feedback on this question: Android Flutter Analyze Audio Waveform
and found nothing online about what I'm looking for, I'll simply ask a broader question, since a comment on that answer told me to use native code and use a platform channel to connect it to flutter but when I asked some clarifications I got nothing.
So my question is If I can do operations in Java (which has been around since a much longer time, and thus has a way bigger documentation), and then use the outcome in Flutter.
More precisely, could I do these things in Java and Flutter:
1) Analyse Audio waveform and find peak points in specific frequencies, and use the timestamp to display them in flutter;
Edit 1:
What Are Peak Points?
This Is the waveform of different frequencies ranges (The Orange one is bass (80-255Hz)), and the Points circled in black are Peak Points. I should analyze the audio specter of a song and Find the peak points in certain frequencies. Then When I Find the Peaks I need to save the timestamps, for example, 16 seconds in and so on.
2) Edit 2:
I need to Edit some photos in a video, like a video collage, for which each frame of a 30 or 60fps video is an image.
3) Edit 3:
I need to add basic frame specific effects to the video, for example a blur that will change frame to frame, or a glare.
4) Adding Music to that video and save it to an mp4 or avi or any format.
5) Edit 4: Most Important thing, I don't want to this all in real time, but more like an After Effect like Render process, in which all the frames are rendered together. The Only thing that would be nice is a sort of progress bar telling the user that the Render is at frame, for example, 200 of 300, but I don't want to display any of the frames or the video, just to render it in background and then save it to an mp4 video that can be viewed after.
As You can see it's a difficult process to do in a language to which you hardly find a tutorial on how to play music due to its early state. But Uis and some other things in flutter are way easier to do and Flutter is also Multi-Platform. So I prefer to stick to Flutter language.
Edit 5:
I took a look at Qt and JUCE, and found out that Qt seems a valid alternative but it seems for what understood more like a "closed" system, I mean, for example I looked the multimedia library but for what I've understood, you can do basic stuff, for example play a video, but not collage frames and save it. (Don't know if I explained myself well). JUCE On the other side, looks better but it seems more for PC audio VST than for mobile applications including video rendering. And another thing is that these two are not free and open source like Flutter is.
Then There is Kivy, which could and could not be the best, because it is a Python port for Mobile Devices and I have a lot of experience with Python And I think it's one of the easier language to learn, but on the other side, it hasn't got that much UI power. and as you mentioned there could be problem using libraries on Android.
You stated I could use C++ or Java With Flutter, but with C++ you told that it's a difficult process. So My question turned out to be Could I write the process in java with a Normal Android Application And Then in some way use the functions in a Flutter App?
Edit 6:
I found a possivle alternative:
Kha (http://kha.tech/). But again found nothing on how to use it with Flutter. Could it be a good Idea?
I'm asking more of a confirmation on if I could use Java or any other language to do what I need in a Flutter Application. And If yes if it's complicated or not that much. (I'm a beginner sorta). But Some tutorial or links to kickstart the code would be helpful aswell!
Flutter at this time is great for building UIs but as you've mentioned, it doesn't have a lot of power or compatibility with libraries yet. A good part of the reason for that is that it doesn't have easy integration with c++, but I won't get into that now.
What you're asking is most likely possible but it's not going to be simple at all to do. First, it sounds like you're wanting to pull particular frames from a video, and display them - that's going to be an additional complication. And don't forget that on a mobile device you have somewhat limited processing power - things will have to be very asynchronous which can actually cause problems for flutter unless you're careful.
As to your points:
This is a very general ask. I'd advise looking up android audio processing libraries. I'm almost sure it's possible, but SO questions are not meant for asking advise on which framework to use. Try https://softwarerecs.stackexchange.com/.
Once again, fairly general and a bit unclear about what you're asking... Try sofwarerecs. I assume you're wanting to take several frames and make them into a video?
Some of those effects (i.e. zoom) you could definitely do with flutter using a Transform. But that would just be while playing in flutter rather then adding to the video files themselves. To do that, you'll have to use the video library in android/java code.
Once again, the video library should do this.
This should also be part of the video library.
I do know of one audio/video library off the top of my head called Processing that may do what you need, but not for sure. It does have an android sdk though. OpenCV would be another but only for video/image processing and I haven't used it directly with Java so I'm not sure how easy it is to use.
For how you'd actually go about implementing this along with flutter... you're going to need to use Platform Channels. I mentioned them in the comment to your other answer but figured you could look that up yourself. The documentation does do a much better job of explaining how that works and how to set it up than I can. But the TLDR is that essentially, what they allow you to do is to send serialized data from native code (java/kotlin/swift etc) to flutter code (dart) and vice-versa, which gets translated into similar data structures in the target language. You can set up various 'channels' upon which the data flows, and within those channels set up 'methods' which get called at either end, or simply send events back and forth.
The complication I mentioned at the beginning is that sending images back and forth across the channels between flutter and dart isn't all that optimal. You most likely won't get a smooth 24/30/60fps of images being sent from java to dart, and it might slow down the rest of the flutter ui significantly. So what you'll want to use for the actual viewport is instead a Texture, which simply displays data from the android side. You'll have to figure out how to write to a texture from android yourself, but there's lots of information available for that. Controls, the visualization of the audio, etc can be done directly in flutter with data that is retrieved from native.
What you'll have is essentially a remote control written in dart/flutter, which sends various commands to a audio/video processing library & wrapper code in Java.
If all that sounds complicated, that's because it is. And as much as flutter is very nice to build UIs in, I have doubts as to whether it's going to be worth the extra complications if you're only targeting android.
Not really related to the answer but rather some friendly advice:
There is one other thing I'll mention - I don't know your level of proficiency with programming and with different languages, but video/audio processing and such are generally not done in java but rather in actual native code (i.e. c/c++). As such, there are actually two levels of abstraction you're going to have to be dealing with here (to some degree as it will probably be abstracted somewhat or a lot depending on the library you're using) - c/c++ to java and java to dart.
You may want to cut out the middlemen and work more directly with native - in that case I'd recommend at least taking a look at Qt or JUCE as they may be more suitable than flutter for your particular use case. There's also Kivy (uses python) which may work well as there's a ton of image/video/audio processing libraries for Python somehow... although they may not all work on android and still have the c++ => python translation to some degree. You'll have to look into licensing etc though - Qt has a broad enough OS licence for most android apps, but JUCE you'd have to pay for unless you're doing open source. I'd have to recommend Qt slightly more than the others as it actually has native decoding of video frames etc, although you'd probably want to incorporate OpenCV or something for the more complicated effects you are talking about. But it would probably be on the same level of complicated as simply writing in java code, but with a slightly different UI style & easier integration with c++ libraries.

Capture the soundcard's output?

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.

How to detect which program is playing sound on windows 7?

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.

Recording System Sounds With Java

How does one obtain the system sound, (beeps and such), and then record it and output to a sound file? I can get sound from a line - in mic, but I can't figure out how to get the actual system sound.
Any assistance?
This has been a long unanswered question which has been frustrating me as well.
I found a way to capture/record Windows' audio output, but it is more of a hack job rather then an actual solution. Disclaimer: This is my blog. I say this because from what I have found Java doesn't capture the data from a specified audio device [See the official Accessing Audio System Resources Java tutorial (although you can list out all of the audio I/O devices/audio ports, See: Programming JavaSound), instead it just takes the default device (which is how I 'solved' the problem).
This, however, introduces a problem where because the default recording device is no longer the microphone, you can no longer record from the microphone as another input; Although, using the Port.Info class to capture the microphone might be a possible solution to this side effect.
I hope this will help.

How to make a noise on the PC speaker with Java

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!

Categories

Resources