Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module AudioDeviceCmdlets
- $preferredOutputDevice = "" # ID for default speakers
- $preferredInputDevice = "" # ID for default microphone
- $steamLinkOutputDevice = "" # ID for VR speakers
- $steamLinkInputDevice = "" # ID for VR microphone
- $steamVRProcessName = "vrmonitor"
- function IsSteamVRActive {
- try {
- $process = Get-Process -Name $steamVRProcessName -ErrorAction Stop
- return $true
- } catch {
- return $false
- }
- }
- $audioSetForVR = $false
- $audioSetForNormal = $false
- while ($true) {
- try {
- $steamVRActive = IsSteamVRActive
- if ($steamVRActive) {
- if (-not $audioSetForVR) {
- Start-Sleep -Seconds 5
- Write-Host "Attempting to switch to VR devices..." -ForegroundColor Cyan
- try {
- Set-AudioDevice -ID $steamLinkOutputDevice
- Set-AudioDevice -ID $steamLinkInputDevice
- Write-Host "Successfully switched to VR devices." -ForegroundColor Green
- $audioSetForVR = $true
- $audioSetForNormal = $false
- } catch {
- Write-Host "Failed to switch to VR devices, will retry..." -ForegroundColor Yellow
- }
- }
- } else {
- if (-not $audioSetForNormal) {
- Write-Host "Attempting to switch back to preferred devices..." -ForegroundColor Cyan
- try {
- Set-AudioDevice -ID $preferredOutputDevice
- Set-AudioDevice -ID $preferredInputDevice
- Write-Host "Successfully switched to preferred devices." -ForegroundColor Green
- $audioSetForNormal = $true
- $audioSetForVR = $false
- } catch {
- Write-Host "Failed to switch to preferred devices, will retry..." -ForegroundColor Yellow
- }
- }
- }
- } catch {
- Write-Host "Unexpected error during monitoring: $_" -ForegroundColor Magenta
- }
- Start-Sleep -Seconds 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement