2

I'd like to generate a bell ring, or any kind of audio sound with Python. In particular, I am assuming I have an open ssh session into another computer, but I want the audio to be heard locally.

Is that even possible? I tried

print '\a'  

and that does not work, not even locally, even if my sound card is working.

Bob
  • 553
  • 1
  • 5
  • 10
  • 1
    Ringing a bell on a BEL character is entirely up to your terminal (whether that's Mac Terminal.app, Windows cmd.exe, gnome-terminal, Putty, whatever). Your Python code is printing the BEL character, and if your terminal is ignoring it, there's nothing Python can do about that. – abarnert May 05 '15 at 19:47

1 Answers1

2

There are 2 difference issues here:

  1. Making an audible noise using Python.

This depends on the system you're running your code on.

Here's an example taken from this answer:

#windows
import winsound
winsound.Beep(300,2000)
#where a is the frequency and b is the duration in miliseconds

#linux

import os
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % ( a, b))
  1. Playing sound remotely through SSH.

If you want to play a remote sound locally, you need for forward the sound, much like X Forwarding, see this detailed SuperUser answer for how to do that. You need a separate application called paprefs that will do that.

If you want to just emit the noise remotely, it should work just fine when you execute the script, depending on which shell session has control of the audio (what if another user is logged on and using the speakers to play music?) this is a related Unix/Linux question on that.

Community
  • 1
  • 1
matrixanomaly
  • 6,627
  • 2
  • 35
  • 58