-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaudio.lua
66 lines (55 loc) · 1.93 KB
/
audio.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
-- Fork of MicMute spoon that turns mute into vol 0 as muting input also results in muting output with my device
hs.loadSpoon('MicMuteFork')
spoon.MicMuteFork:bindHotkeys({ toggle = {modHyper, '`'}}, 0.75)
function setMusicDevice()
local musicDevice
for _, device in pairs(musicDevices) do
if hs.audiodevice.findOutputByName(device) then
musicDevice = device
break
end
end
setAudioOutput(musicDevice)
end
-- Configure audio output device, unless it doesn't exist - then notify
function setAudioOutput(device)
local hardwareDevice = hs.audiodevice.findOutputByName(device)
local currentDevice = hs.audiodevice.defaultOutputDevice()
if hardwareDevice then
if currentDevice ~= hardwareDevice then
hardwareDevice:setDefaultOutputDevice()
notify('Audio Output', 'Switched to ' .. device)
-- talkDevice is replugged often, when plugged in it starts on mute - so turn it up to a reasonable volume
if device == talkDevice then
hardwareDevice:setVolume(40)
setAudioInput(talkDevice)
end
end
else
notify('Audio Output', 'Tried to set invalid audio output! Device: ' .. device)
print('Tried to set invalid audio output: ' .. device)
end
end
-- Configure audio input device, unless it doesn't exist - then notify
function setAudioInput(device)
local hardwareDevice = hs.audiodevice.findInputByName(device)
local currentDevice = hs.audiodevice.defaultInputDevice()
if hardwareDevice then
if currentDevice ~= hardwareDevice then
hardwareDevice:setDefaultInputDevice()
notify('Audio Input', 'Switched to ' .. device)
end
else
notify('Audio Alert', device .. ' is missing!')
end
end
-- Toggle between the two audio devices
function toggleAudio()
local currentDevice = hs.audiodevice.defaultOutputDevice()
if currentDevice:name() == talkDevice then
setMusicDevice()
else
setAudioOutput(talkDevice)
setAudioInput(talkDevice)
end
end