How to programmatically change Mac's audio output device or invoke the system "dong" sound using Ruby? - ruby

I have an app on the iMac written in Ruby, and it would give out alert sound using
puts 7.chr
(or it can play an mp3 file). But the problem is that sometimes the Mac is changed to output the audio in System Preferences to the HDTV instead of the internal speakers, and the HDTV can be turned off sometimes.
So is there a way to either programmatically change the output device to the internal speakers, or play the "Dong" sound which is the one when the iMac boots up -- the sound that comes from the inside of the machine?

Related

Microsoft SysVAD Virtual Audio Device Driver (SYSVAD) cannot work

This driver (https://github.com/Microsoft/Windows-driver-samples/tree/master/audio/sysvad) is provided by Microsoft. And in its README, the last part, it says:
Locate an MP3 or other audio file on the target computer and
double-click to play it. Then in the Sound dialog box, verify that
there is activity in the volume level indicator associated with the
SYSVAD (with APO Extensions) driver.
But in my target computer, the volume level indicator associated with the SYSVAD (with APO Extensions) driver does not change at all. And the target computer does not make any sound.
The same case to the mic, when set default mic to any of the sysvad mic array, the mic volume level will not change at all.
In my understanding, sysvad driver is virtual driver. So it will not really work. But why Microsoft README says: there is activity in the volume level indicator associated with the SYSVAD (with APO Extensions) driver.
The SYSVAD documentation leaves a lot to be desired. You won't see any activity in the volume level indicator, and you won't hear anything, since the only thing the rendering endpoints do is save a copy of the audio output to file (look for C:\STREAM_HOST_*.wav files).
The capture endpoints (including the "loopback" pins) generate constant sine-wave signals, which you can see if you use an app to record them, and then view them in a sound editor/viewer or play them back out to a real device.
I am working on SysVad too and sure it works, for Mic you can test with vlc player
Try to open the virtual mic from VLC and then you will hear sound, it's a sin wave generated by driver itself

How to mute the audio of a application in ubuntu?

i'm working on a project which produces sound alerts whenever a condition is met. But the problem is if the video player is running the alert sound get mixed with the sound of the video. Is there any way to mute the audio of the running application only using terminal so that the warning can be heard.
My operating system is Ubuntu.

Outputting Audio to the Built-In output device (Not the Default One)

I need to do some system-wide audio processing in my app.
I have installed Soundflower and selected it as my default output device in order to get the system audio. I know that Soundflower merely copies the mix buffer to a ThruBuffer and passes it to the apps so they can get it in their AudioDeviceIOProc callback.
What I don't understand is how to route the audio back to the Built-In output device after I've done the audio processing. I have the Soundflower device as the default, and it produces silence as I try to route the audio to the default output unit. Maybe what I need is to create a Multi-Output device in my program but I'm not sure how to do that.
You can create a multi-output device on osx - they're called "aggregate devices". You can do it manually in Audio MIDI Setup app and use that device in your app, or do it programmatically in your app.
If you do do it in app, example code seems to be rare. I cribbed the info I needed from this blog post.
NB the post is very old, I had to go to the Internet Archive Wayback Machine to find it.

Manually delay audio in chrome or system-wide (Mac OSX)

I got new Bluetooth speakers and inherently they seem to have a delay of about 0.5 to 1s when watching streams or videos online. I already mailed to the manufacturer and I was told that this has to do with how they make use of the Bluetooth protocol (pair of speakers in master-slave mode for stero sound) and how the respective video player is doing encoding/decoding. iTunes for instance seems to be just fine while vlc and all streams in browsers have this delay.
So I was wondering whether there is a way to manually delay audio either just in the browser (chrome) or even system-wide on MacOSX?! It would be great if the possible solution was transient since I do not want the delay when I am not using these speakers.
Additionally it would be just perfect if somebody even knew how to this on iOS although I don't think that it is possible there, that's why I did not include iOS in the title.

Pre-Amplify Audio OS X

There are two apps for OS X that allow you to pre-amplify audio before it gets played by the hardware: Audio Hijack (pre-amplifies output from particular applications) and Boom (pre-amplifies all system audio). These apps work by applying equalization to pre-existing audio streams - with a high pre-amp setting - before they are sent to the sound card.
My question is: how to hijack the system audio stream and then send it along to the sound card. Is this somewhere in an API, or would it require altering a system library ?
1) Create a standard sound device that shows up in audio system preferences. This has to be in the form of a kernel extension (kext). Difficult to create by just reading apple docs - try looking at an app called Soundflower.
2) Once you've loaded the kext and have the new audio device available, select it in preferences as the default output device for system audio.
3) Now you need to alter the audio and pipe it to the real system output. This can be done in an accompanying application that adds callback "IOProc" functions to a) the new device and b) your computer's built-in output device. You can then copy audio buffers from one device to the other, to pipe the audio to your speakers. To increase the volume, multiply all the bytes in the buffer by some factor. See Soundflower's accompanying app.

Resources