I have trouble waking up in the morning, so I want to make an alarm clock with python that'll force me to get up.
I currently use my computer with a pair of headphones plugged into an audio jack on my monitor, which is connected to my computer via HDMI.
I would like to play an audio file every morning through my laptop's speakers, rather than through my headphones. And I don't want to go through the hassle of unplugging my headphones every night.
Is this possible to do?
I'm not looking for being able to switch the default speakers. I just want to play a sound through a speaker that isn't the default speaker, which I KNOW is possible, because it happens from time to time with programs.
I'm unsure if you can select what audio device to output to with winsound, but PyAudio is cross-platform and can output the sound to whichever device you want. PyAudio is available on pip through:
pip install --allow-external pyaudio --allow-unverified pyaudio pyaudio
In particular, the pyAudio.PyAudio().open() function takes an argument with the "input_device_index" – Index of Input Device to use. Unspecified (or None) uses default device. Ignored if input is False.
Docs and example: https://people.csail.mit.edu/hubert/pyaudio/docs/
Finding which device: List all audio devices with Python's pyaudio (portaudio binding)
As an alternative to PyAudio you could try python-sounddevice, which also uses PortAudio (like PyAudio) but it is probably easier to install and use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With