trying to switch sound devices using nircmd and it just doesnt

395 Views Asked by At

i tried both this:

import os

os.system(r"cd C:\daten\super pooper\use\app\nircmd && nircmd setdefaultsounddevice 'BD990P' 1")

where i got no error but the audio device didnt change either and this:

import os

os.system(r"cd C:\daten\super pooper\use\app\nircmd")
os.system("nircmd setdefaultsounddevice 'BD990P' 1")

where i got the error

"Der Befehl "nircmd" ist entweder falsch geschrieben oder konnte nicht gefunden werden."

which basically means that the command "nircmd" wasnt found that makes me think that every command is executed seperately and not taking into account direcotry changes that happened before, but even with my other try where that wouldnt have been an issue it doesnt work, so im kinda lost

2

There are 2 best solutions below

2
MCLP2005 On

The Path has to be set into a string. A space in a name would set it as a seperate parameter. So it should work if you do:

import os

os.system(r"cd C:\daten\'super pooper'\use\app\nircmd")
os.system("nircmd setdefaultsounddevice 'BD990P' 1")
0
Mister Robato On

Try this:

import subprocess

# Replace with the actual path to soundvolumeview.exe
soundvolumeview_path = r"C:\tools\NirLauncher\NirSoft\soundvolumeview.exe"

# Speaker name
speaker_name = "Realtek(R) Audio"

# Construct the command
command = [soundvolumeview_path, "/SetDefault", speaker_name + "\\Device\\Speakers\\Render", "all"]

# Execute the command
subprocess.run(command, shell=True)