Skip to content

Commit a017d2e

Browse files
Default Communication Device (#30)
* change version number * change version number * set-audiodevice by object, ID, or index no longer sets as communication device * add bare version of cmdlet AudioDeviceCommunication * spacing * change installation instructions (#45) * change copyright year * change copyright year * Update build from source instructions The System.Management.Automation package is only compatible with .NET Core. The legacy version is bundled with Microsoft.PowerShell.5.1.ReferenceAssemblies * Add PlaybackOnly parameter to Set-AudioDevice Used when setting default audio device to only set it as default playback and not also default communication device * Add CommunicationOnly parameter to Set-AudioDevice The opposite of PlaybackOnly, only set the default communication device, and not default playback device. * Rename PlaybackOnly to DeafultOnly * revert to version without additional cmdlet * Revert "set-audiodevice by object, ID, or index no longer sets as communication device" This reverts commit b16518d. * change version number * set-audiodevice by object, ID, or index no longer sets as communication device * add bare version of cmdlet AudioDeviceCommunication * spacing * change copyright year * change copyright year * revert to version without additional cmdlet * Revert "set-audiodevice by object, ID, or index no longer sets as communication device" This reverts commit b16518d. * update copyright year * update build instructions * fix new line in build instructions * change attribution * add DefaultCommunication attribute to AudioDevice class change List parameter to support new AudioDevice * change AudioDevice creation in remaining parameters to support DefaultCommunication fix typo * add support for parameters PlaybackCommunication and RecordingCommunication * remove duplicate step in build instructions * add support in get cmdlet for parameters PlaybackCommunicationMute and RecordingCommunicationMute fix typo * add support in get cmdlet for parameters PlaybackCommunicationVolume and RecordingCommunicationVolume * add support in get cmdlet for parameters PlaybackCommunicationMuteToggle and RecordingCommunicationMuteToggle * add suggestion by @ImportTaste * add new features descriptions * update Usage section * add parameters PlaybackCommunicationMute and RecordingCommunicationMute to Set cmdlet * fix comment typo * Update README.md * add parameters PlaybackCommunicationMeter, PlaybackCommunicationStream, RecordingCommunicationMeter, and RecordingCommunicationStream to Write cmdlet * remove file added by mistake * fix typo * add parameters PlaybackCommunicationVolume and RecordingCommunicationVolume to Set cmdlet Co-authored-by: Øyvind Heddeland Instefjord <instefjord@outlook.com>
1 parent 0c5aded commit a017d2e

File tree

6 files changed

+692
-108
lines changed

6 files changed

+692
-108
lines changed

EXAMPLE/Toggle-AudioDevice.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<#
2-
Copyright (c) 2016-2018 Francois Gendron <fg@frgn.ca>
2+
Copyright (c) 2016-2022 Francois Gendron <fg@frgn.ca>
33
MIT License
44
55
This file is a script that toggles between two playback audio devices using

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016-2018 Francois Gendron <fg@frgn.ca>
3+
Copyright (c) 2016-2022 Francois Gendron <fg@frgn.ca>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 82 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ AudioDeviceCmdlets is a suite of PowerShell Cmdlets to control audio devices on
55
## Features
66
Get list of all audio devices
77
Get default audio device (playback/recording)
8+
Get default communication audio device (playback/recording)
89
Get volume and mute state of default audio device (playback/recording)
10+
Get volume and mute state of default communication audio device (playback/recording)
911
Set default audio device (playback/recording)
12+
Set default communication audio device (playback/recording)
1013
Set volume and mute state of default audio device (playback/recording)
14+
Set volume and mute state of default communication audio device (playback/recording)
1115

1216

1317
## Installation
@@ -19,66 +23,104 @@ Install-Module -Name AudioDeviceCmdlets
1923

2024
## Usage
2125
```PowerShell
22-
Get-AudioDevice -List # Outputs a list of all devices as <AudioDevice>
23-
-ID <string> # Outputs the device with the ID corresponding to the given <string>
24-
-Index <int> # Outputs the device with the Index corresponding to the given <int>
25-
-Playback # Outputs the default playback device as <AudioDevice>
26-
-PlaybackMute # Outputs the default playback device's mute state as <bool>
27-
-PlaybackVolume # Outputs the default playback device's volume level on 100 as <float>
28-
-Recording # Outputs the default recording device as <AudioDevice>
29-
-RecordingMute # Outputs the default recording device's mute state as <bool>
30-
-RecordingVolume # Outputs the default recording device's volume level on 100 as <float>
26+
Get-AudioDevice -ID <string> # Get the device with the ID corresponding to the given <string>
27+
Get-AudioDevice -Index <int> # Get the device with the Index corresponding to the given <int>
28+
Get-AudioDevice -List # Get a list of all enabled devices as <AudioDevice>
29+
Get-AudioDevice -PlaybackCommunication # Get the default communication playback device as <AudioDevice>
30+
Get-AudioDevice -PlaybackCommunicationMute # Get the default communication playback device's mute state as <bool>
31+
Get-AudioDevice -PlaybackCommunicationVolume # Get the default communication playback device's volume level on 100 as <float>
32+
Get-AudioDevice -Playback # Get the default playback device as <AudioDevice>
33+
Get-AudioDevice -PlaybackMute # Get the default playback device's mute state as <bool>
34+
Get-AudioDevice -PlaybackVolume # Get the default playback device's volume level on 100 as <float>
35+
Get-AudioDevice -RecordingCommunication # Get the default communication recording device as <AudioDevice>
36+
Get-AudioDevice -RecordingCommunicationMute # Get the default communication recording device's mute state as <bool>
37+
Get-AudioDevice -RecordingCommunicationVolume # Get the default communication recording device's volume level on 100 as <float>
38+
Get-AudioDevice -Recording # Get the default recording device as <AudioDevice>
39+
Get-AudioDevice -RecordingMute # Get the default recording device's mute state as <bool>
40+
Get-AudioDevice -RecordingVolume # Get the default recording device's volume level on 100 as <float>
41+
3142
```
3243
```PowerShell
33-
Set-AudioDevice <AudioDevice> # Sets the default playback/recording device to the given <AudioDevice>, can be piped
34-
-ID <string> # Sets the default playback/recording device to the device with the ID corresponding to the given <string>
35-
-Index <int> # Sets the default playback/recording device to the device with the Index corresponding to the given <int>
36-
-PlaybackMute <bool> # Sets the default playback device's mute state to the given <bool>
37-
-PlaybackMuteToggle # Toggles the default playback device's mute state
38-
-PlaybackVolume <float> # Sets the default playback device's volume level on 100 to the given <float>
39-
-RecordingMute <bool> # Sets the default recording device's mute state to the given <bool>
40-
-RecordingMuteToggle # Toggles the default recording device's mute state
41-
-RecordingVolume <float> # Sets the default recording device's volume level on 100 to the given <float>
44+
Set-AudioDevice <AudioDevice> # Set the given playback/recording device as both the default device and the default communication device, for its type
45+
Set-AudioDevice <AudioDevice> -CommunicationOnly # Set the given playback/recording device as the default communication device and not the default device, for its type
46+
Set-AudioDevice <AudioDevice> -DefaultOnly # Set the given playback/recording device as the default device and not the default communication device, for its type
47+
Set-AudioDevice -ID <string> # Set the device with the ID corresponding to the given <string> as both the default device and the default communication device, for its type
48+
Set-AudioDevice -ID <string> -CommunicationOnly # Set the device with the ID corresponding to the given <string> as the default communication device and not the default device, for its type
49+
Set-AudioDevice -ID <string> -DefaultOnly # Set the device with the ID corresponding to the given <string> as the default device and not the default communication device, for its type
50+
Set-AudioDevice -Index <int> # Set the device with the Index corresponding to the given <int> as both the default device and the default communication device, for its type
51+
Set-AudioDevice -Index <int> -CommunicationOnly # Set the device with the Index corresponding to the given <int> as the default communication device and not the default device, for its type
52+
Set-AudioDevice -Index <int> -DefaultOnly # Set the device with the Index corresponding to the given <int> as the default device and not the default communication device, for its type
53+
Set-AudioDevice -PlaybackCommunicationMuteToggle # Set the default communication playback device's mute state to the opposite of its current mute state
54+
Set-AudioDevice -PlaybackCommunicationMute <bool> # Set the default communication playback device's mute state to the given <bool>
55+
Set-AudioDevice -PlaybackCommunicationVolume <float> # Set the default communication playback device's volume level on 100 to the given <float>
56+
Set-AudioDevice -PlaybackMuteToggle # Set the default playback device's mute state to the opposite of its current mute state
57+
Set-AudioDevice -PlaybackMute <bool> # Set the default playback device's mute state to the given <bool>
58+
Set-AudioDevice -PlaybackVolume <float> # Set the default playback device's volume level on 100 to the given <float>
59+
Set-AudioDevice -RecordingCommunicationMuteToggle # Set the default communication recording device's mute state to the opposite of its current mute state
60+
Set-AudioDevice -RecordingCommunicationMute <bool> # Set the default communication recording device's mute state to the given <bool>
61+
Set-AudioDevice -RecordingCommunicationVolume <float> # Set the default communication recording device's volume level on 100 to the given <float>
62+
Set-AudioDevice -RecordingMuteToggle # Set the default recording device's mute state to the opposite of its current mute state
63+
Set-AudioDevice -RecordingMute <bool> # Set the default recording device's mute state to the given <bool>
64+
Set-AudioDevice -RecordingVolume <float> # Set the default recording device's volume level on 100 to the given <float>
4265
```
4366
```PowerShell
44-
Write-AudioDevice -PlaybackMeter # Writes the default playback device's power output on 100 as a meter
45-
-PlaybackSteam # Writes the default playback device's power output on 100 as a stream of <int>
46-
-RecordingMeter # Writes the default recording device's power output on 100 as a meter
47-
-RecordingSteam # Writes the default recording device's power output on 100 as a stream of <int>
67+
Write-AudioDevice -PlaybackCommunicationMeter # Write the default playback device's power output on 100 as a meter
68+
Write-AudioDevice -PlaybackCommunicationStream # Write the default playback device's power output on 100 as a stream of <int>
69+
Write-AudioDevice -PlaybackMeter # Write the default playback device's power output on 100 as a meter
70+
Write-AudioDevice -PlaybackStream # Write the default playback device's power output on 100 as a stream of <int>
71+
Write-AudioDevice -RecordingCommunicationMeter # Write the default recording device's power output on 100 as a meter
72+
Write-AudioDevice -RecordingCommunicationStream # Write the default recording device's power output on 100 as a stream of <int>
73+
Write-AudioDevice -RecordingMeter # Write the default recording device's power output on 100 as a meter
74+
Write-AudioDevice -RecordingStream # Write the default recording device's power output on 100 as a stream of <int>
4875
```
4976

5077

5178
## Build Cmdlet from source
5279

53-
1. Using Visual Studio Community, create new project from SOURCE folder
54-
File -> New -> Project From Existing Code...
55-
80+
1. Install Visual Studio 2022
81+
82+
Workloads: .NET desktop development
83+
84+
2. Create new project from SOURCE folder
85+
File -> New -> Project From Existing Code...
86+
5687
Type of project: Visual C#
5788
Folder: SOURCE
5889
Name: AudioDeviceCmdlets
5990
Output type: Class Library
6091

61-
2. Install System.Management.Automation NuGet package
62-
Project -> Manage NuGet Packages...
63-
64-
Browse: System.Management.Automation
65-
Install: v6.3+
66-
6792
3. Set project properties
68-
Project -> AudioDeviceCmdlets Properties...
93+
Project -> AudioDeviceCmdlets Properties
6994

7095
Assembly name: AudioDeviceCmdlets
71-
Target framework: .NET Framework 4.5+
96+
Target framework: .NET Framework 4.6.1+
97+
98+
4. Install System.Management.Automation NuGet legacy package
99+
Project -> Manage NuGet Packages...
100+
101+
Package source: nuget.org
102+
Browse: Microsoft.PowerShell.5.1.ReferenceAssemblies
103+
Install: v1.0.0+
72104

73-
4. Set solution configuration
74-
Build -> Configuration Manager...
105+
5. Set solution configuration
106+
Build -> Configuration Manager...
75107

76108
Active solution configuration: Release
77109

78-
5. Build Cmdlet
79-
Build -> Build AudioDeviceCmdlets
110+
6. Build Cmdlet
111+
Build -> Build Solution
80112

81-
AudioDeviceCmdlets\bin\Release\AudioDeviceCmdlets.dll
113+
AudioDeviceCmdlets\SOURCE\bin\Release\AudioDeviceCmdlets.dll
114+
115+
7. Import Cmdlet to PowerShell on Windows
116+
```PowerShell
117+
$FilePath = "C:\Path\To\AudioDeviceCmdlets\SOURCE\bin\Release\AudioDeviceCmdlets.dll"
118+
New-Item "$($profile | split-path)\Modules\AudioDeviceCmdlets" -Type directory -Force
119+
Copy-Item $FilePath "$($profile | split-path)\Modules\AudioDeviceCmdlets\AudioDeviceCmdlets.dll"
120+
Set-Location "$($profile | Split-Path)\Modules\AudioDeviceCmdlets"
121+
Get-ChildItem | Unblock-File
122+
Import-Module AudioDeviceCmdlets
123+
```
82124

83125
6. Import Cmdlet to PowerShell
84126
```PowerShell
@@ -92,7 +134,7 @@ Write-AudioDevice -PlaybackMeter # Writes the default playback device's power o
92134

93135
## Attribution
94136

95-
Based on code posted to Code Project by Ray Molenkamp with comments and suggestions by MadMidi
137+
Based on code originally posted to Code Project by Ray Molenkamp with comments and suggestions by MadMidi
96138
http://www.codeproject.com/Articles/18520/Vista-Core-Audio-API-Master-Volume-Control
97-
Based on code posted to GitHub by Chris Hunt
139+
Based on code originally posted to GitHub by Chris Hunt
98140
https://github.com/cdhunt/WindowsAudioDevice-Powershell-Cmdlet

0 commit comments

Comments
 (0)