Skip to content

Commit

Permalink
Merge pull request #52 from frgnca/dev_v3.1
Browse files Browse the repository at this point in the history
Dev v3.1
  • Loading branch information
frgnca authored May 28, 2022
2 parents 70d0a8a + 75d0fad commit 8a02ed8
Show file tree
Hide file tree
Showing 5 changed files with 1,348 additions and 162 deletions.
2 changes: 1 addition & 1 deletion EXAMPLE/Toggle-AudioDevice.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#
Copyright (c) 2016-2018 Francois Gendron <[email protected]>
Copyright (c) 2016-2022 Francois Gendron <[email protected]>
MIT License
This file is a script that toggles between two playback audio devices using
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016-2018 Francois Gendron <[email protected]>
Copyright (c) 2016-2022 Francois Gendron <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
132 changes: 90 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ AudioDeviceCmdlets is a suite of PowerShell Cmdlets to control audio devices on
## Features
Get list of all audio devices
Get default audio device (playback/recording)
Get default communication audio device (playback/recording)
Get volume and mute state of default audio device (playback/recording)
Get volume and mute state of default communication audio device (playback/recording)
Set default audio device (playback/recording)
Set default communication audio device (playback/recording)
Set volume and mute state of default audio device (playback/recording)
Set volume and mute state of default communication audio device (playback/recording)


## Installation
Expand All @@ -19,80 +23,124 @@ Install-Module -Name AudioDeviceCmdlets

## Usage
```PowerShell
Get-AudioDevice -List # Outputs a list of all devices as <AudioDevice>
-ID <string> # Outputs the device with the ID corresponding to the given <string>
-Index <int> # Outputs the device with the Index corresponding to the given <int>
-Playback # Outputs the default playback device as <AudioDevice>
-PlaybackMute # Outputs the default playback device's mute state as <bool>
-PlaybackVolume # Outputs the default playback device's volume level on 100 as <float>
-Recording # Outputs the default recording device as <AudioDevice>
-RecordingMute # Outputs the default recording device's mute state as <bool>
-RecordingVolume # Outputs the default recording device's volume level on 100 as <float>
Get-AudioDevice -ID <string> # Get the device with the ID corresponding to the given <string>
Get-AudioDevice -Index <int> # Get the device with the Index corresponding to the given <int>
Get-AudioDevice -List # Get a list of all enabled devices as <AudioDevice>
Get-AudioDevice -PlaybackCommunication # Get the default communication playback device as <AudioDevice>
Get-AudioDevice -PlaybackCommunicationMute # Get the default communication playback device's mute state as <bool>
Get-AudioDevice -PlaybackCommunicationVolume # Get the default communication playback device's volume level on 100 as <float>
Get-AudioDevice -Playback # Get the default playback device as <AudioDevice>
Get-AudioDevice -PlaybackMute # Get the default playback device's mute state as <bool>
Get-AudioDevice -PlaybackVolume # Get the default playback device's volume level on 100 as <float>
Get-AudioDevice -RecordingCommunication # Get the default communication recording device as <AudioDevice>
Get-AudioDevice -RecordingCommunicationMute # Get the default communication recording device's mute state as <bool>
Get-AudioDevice -RecordingCommunicationVolume # Get the default communication recording device's volume level on 100 as <float>
Get-AudioDevice -Recording # Get the default recording device as <AudioDevice>
Get-AudioDevice -RecordingMute # Get the default recording device's mute state as <bool>
Get-AudioDevice -RecordingVolume # Get the default recording device's volume level on 100 as <float>
```
```PowerShell
Set-AudioDevice <AudioDevice> # Sets the default playback/recording device to the given <AudioDevice>, can be piped
-ID <string> # Sets the default playback/recording device to the device with the ID corresponding to the given <string>
-Index <int> # Sets the default playback/recording device to the device with the Index corresponding to the given <int>
-PlaybackMute <bool> # Sets the default playback device's mute state to the given <bool>
-PlaybackMuteToggle # Toggles the default playback device's mute state
-PlaybackVolume <float> # Sets the default playback device's volume level on 100 to the given <float>
-RecordingMute <bool> # Sets the default recording device's mute state to the given <bool>
-RecordingMuteToggle # Toggles the default recording device's mute state
-RecordingVolume <float> # Sets the default recording device's volume level on 100 to the given <float>
Set-AudioDevice <AudioDevice> # Set the given playback/recording device as both the default device and the default communication device, for its type
Set-AudioDevice <AudioDevice> -CommunicationOnly # Set the given playback/recording device as the default communication device and not the default device, for its type
Set-AudioDevice <AudioDevice> -DefaultOnly # Set the given playback/recording device as the default device and not the default communication device, for its type
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
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
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
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
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
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
Set-AudioDevice -PlaybackCommunicationMuteToggle # Set the default communication playback device's mute state to the opposite of its current mute state
Set-AudioDevice -PlaybackCommunicationMute <bool> # Set the default communication playback device's mute state to the given <bool>
Set-AudioDevice -PlaybackCommunicationVolume <float> # Set the default communication playback device's volume level on 100 to the given <float>
Set-AudioDevice -PlaybackMuteToggle # Set the default playback device's mute state to the opposite of its current mute state
Set-AudioDevice -PlaybackMute <bool> # Set the default playback device's mute state to the given <bool>
Set-AudioDevice -PlaybackVolume <float> # Set the default playback device's volume level on 100 to the given <float>
Set-AudioDevice -RecordingCommunicationMuteToggle # Set the default communication recording device's mute state to the opposite of its current mute state
Set-AudioDevice -RecordingCommunicationMute <bool> # Set the default communication recording device's mute state to the given <bool>
Set-AudioDevice -RecordingCommunicationVolume <float> # Set the default communication recording device's volume level on 100 to the given <float>
Set-AudioDevice -RecordingMuteToggle # Set the default recording device's mute state to the opposite of its current mute state
Set-AudioDevice -RecordingMute <bool> # Set the default recording device's mute state to the given <bool>
Set-AudioDevice -RecordingVolume <float> # Set the default recording device's volume level on 100 to the given <float>
```
```PowerShell
Write-AudioDevice -PlaybackMeter # Writes the default playback device's power output on 100 as a meter
-PlaybackSteam # Writes the default playback device's power output on 100 as a stream of <int>
-RecordingMeter # Writes the default recording device's power output on 100 as a meter
-RecordingSteam # Writes the default recording device's power output on 100 as a stream of <int>
Write-AudioDevice -PlaybackCommunicationMeter # Write the default playback device's power output on 100 as a meter
Write-AudioDevice -PlaybackCommunicationStream # Write the default playback device's power output on 100 as a stream of <int>
Write-AudioDevice -PlaybackMeter # Write the default playback device's power output on 100 as a meter
Write-AudioDevice -PlaybackStream # Write the default playback device's power output on 100 as a stream of <int>
Write-AudioDevice -RecordingCommunicationMeter # Write the default recording device's power output on 100 as a meter
Write-AudioDevice -RecordingCommunicationStream # Write the default recording device's power output on 100 as a stream of <int>
Write-AudioDevice -RecordingMeter # Write the default recording device's power output on 100 as a meter
Write-AudioDevice -RecordingStream # Write the default recording device's power output on 100 as a stream of <int>
```


## Build Cmdlet from source

1. Using Visual Studio Community, create new project from SOURCE folder
File -> New -> Project From Existing Code...


<details>
<summary>Build instructions</summary>

1. Install Visual Studio 2022

Workloads: .NET desktop development

2. Create new project from SOURCE folder
File -> New -> Project From Existing Code...

Type of project: Visual C#
Folder: SOURCE
Name: AudioDeviceCmdlets
Output type: Class Library

2. Install System.Management.Automation NuGet package
Project -> Manage NuGet Packages...

Browse: System.Management.Automation
Install: v6.3+

3. Set project properties
Project -> AudioDeviceCmdlets Properties...
Project -> AudioDeviceCmdlets Properties

Assembly name: AudioDeviceCmdlets
Target framework: .NET Framework 4.5+
Target framework: .NET Framework 4.6.1+

4. Set solution configuration
Build -> Configuration Manager...
4. Install System.Management.Automation NuGet legacy package
Project -> Manage NuGet Packages...

Package source: nuget.org
Browse: Microsoft.PowerShell.5.1.ReferenceAssemblies
Install: v1.0.0+

5. Set solution configuration
Build -> Configuration Manager...

Active solution configuration: Release

5. Build Cmdlet
Build -> Build AudioDeviceCmdlets
6. Build Cmdlet
Build -> Build Solution

AudioDeviceCmdlets\bin\Release\AudioDeviceCmdlets.dll
AudioDeviceCmdlets\SOURCE\bin\Release\AudioDeviceCmdlets.dll

6. Import Cmdlet to PowerShell
7. Import Cmdlet to PowerShell on Windows
```PowerShell
$FilePath = "C:\Path\To\AudioDeviceCmdlets\SOURCE\bin\Release\AudioDeviceCmdlets.dll"
New-Item "$($profile | split-path)\Modules\AudioDeviceCmdlets" -Type directory -Force
Copy-Item "C:\Path\to\AudioDeviceCmdlets.dll" "$($profile | split-path)\Modules\AudioDeviceCmdlets\AudioDeviceCmdlets.dll"
Copy-Item $FilePath "$($profile | split-path)\Modules\AudioDeviceCmdlets\AudioDeviceCmdlets.dll"
Set-Location "$($profile | Split-Path)\Modules\AudioDeviceCmdlets"
Get-ChildItem | Unblock-File
Import-Module AudioDeviceCmdlets
```
</details>


## Donation

<details>
<summary>Thank you for considering a donation</summary>

Bitcoin (BTC) 3AffczXX4Jb2iN8QWQhHQAsj9AqGFXgYUF
BitcoinCash (BCH) qraf6a3fklta7xkvwkh49zqn6mgnm2eyz589rkfvl3
Ethereum (ETH) 0xE4EA2A2356C04c8054Db452dCBd6f958F74722dE
</details>


## Attribution

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

0 comments on commit 8a02ed8

Please sign in to comment.