0

I've used AudioKit.inputDevice, Audiotkit.outputDevice, and friends to get get all input and output devices on my Mac, and to get/set default input and output device.

I wish to read the current volume of these devices, and to be able to set it myself, but I can't find the correct AudioKit API for doing so.

Does anyone know how to do this?

Andy Ibanez
  • 12,104
  • 9
  • 65
  • 100
Alexander
  • 59,041
  • 12
  • 98
  • 151
  • This looks like what you are trying to do: https://stackoverflow.com/questions/7255006/get-system-volume-ios – ekscrypto Jul 31 '18 at 19:00
  • 1
    @ekscrypto `AVAudioSession` is iOS only. – Alexander Jul 31 '18 at 19:14
  • oh my bad, didn’t notice the macos tag – ekscrypto Jul 31 '18 at 21:59
  • 1
    It looks like setting output volume could be accomplished in much the same way as it is done [here](https://stackoverflow.com/questions/27290751/how-to-set-systems-master-volume-from-a-swift-app-in-osx). Just replace the line `var defaultOutputDeviceID = AudioDeviceID(0)` with `var defaultOutputDeviceID = AudioKit.outputDevice!.deviceID` (probably using `if let` instead of force unwrapping). This doesn't seem to update the sound icon in the menu bar, but it does change the system volume on my machine. – aaplmath Jul 31 '18 at 23:07
  • @aaplmath Looks promising, I'll give this a shot! – Alexander Jul 31 '18 at 23:30
  • Possible duplicate of [How to set systems master volume from a swift app in osx](https://stackoverflow.com/questions/27290751/how-to-set-systems-master-volume-from-a-swift-app-in-osx) – Jake3231 Aug 01 '18 at 02:00

1 Answers1

0

You will want to use a library similar to https://github.com/InerziaSoft/ISSoundAdditions

Changing sound volume becomes as simple as:

[NSSound setSystemVolume:0.5]

-- Duplicate of: Change Volume on Mac programmatically

ekscrypto
  • 3,718
  • 1
  • 24
  • 38
  • That only seems to work on the default output device, I'm afraid. – Alexander Jul 31 '18 at 23:32
  • Seems rather easy to target any specific device, check the code in https://github.com/InerziaSoft/ISSoundAdditions/blob/master/ISSoundAdditions.m – ekscrypto Jul 31 '18 at 23:33