0

I have a program that I would like to play a set frequency sound from constantly without gaps until I tell it to stop. I have seen this answer but this requires an external module (I am working in an offline environment so this is not possible).

Also, this answer is also not very practical as it will have playback gaps (creating the file is possible though). I hope what I am asking for is not impossible but I have a feeling it is.

Thanks in advance.

Minion Jim
  • 1,239
  • 13
  • 30

1 Answers1

1

I am sure I have made that from an stdlib module, just don't remember how or in what platform. But this looks pretty much what you want (for windows, at least), , from the python help:

winsound.Beep(frequency, duration)

Beep the PC’s speaker. The frequency parameter specifies frequency,
in hertz, of the sound, and must be in the range 37 through 32,767.
The duration parameter specifies the number of milliseconds the sound
should last.
If the system is not able to beep the speaker, RuntimeError is raised.
progmatico
  • 4,714
  • 1
  • 16
  • 27
  • This is perfect. Thank you! – Minion Jim Feb 20 '18 at 11:15
  • Is there a way to do this until I tell it to stop? – Minion Jim Feb 20 '18 at 17:39
  • Well I am unware of the maximum duration, after that you'll have to loop and that will gap the sound, Besides that, the function call is blocking so you'll have to somehow setup a way of taking it down. That makes up for another good question, but see here https://stackoverflow.com/questions/492519/timeout-on-a-function-call for a related one. You can take some ideas from there. Search SO more starting from there I am sure it has been asked before about some other blocking function. Maybe launching and killing another process. – progmatico Feb 20 '18 at 17:58