3

I tried this, but it didn't made more than an empty line :

import os
a=300
b=2000
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % ( a, b))
Turcsi
  • 145
  • 1
  • 2
  • 5
  • Change the `os.system` to `print`, then run the code and copy and paste the string to your terminal. Does this then play the sound you want? – Stephen Rauch May 10 '17 at 23:34
  • The run still gives an empty line. In the terminal the string just prints it. – Turcsi May 11 '17 at 07:16

1 Answers1

7

Easy ways to play a beep sound of given frequency and duration in Python:

frequency = 1000 # Hertz
duration  = 2000 # milliseconds

On Windows:

import winsound
winsound.Beep(frequency, duration)

On Linux:

# SoX must be installed using 'sudo apt-get install sox' in the terminal
import os
os.system('play -n synth %s sin %s' % (duration/1000, frequency))

On macOS:

# First install Homebrew (https://brew.sh/) 
# and then SoX using 'brew install sox' in the terminal
import os
os.system('play -n synth %s sin %s' % (duration/1000, frequency))

Cross-platform:

Using PyAudio module and a bit of coding: https://stackoverflow.com/a/27978895

Community
  • 1
  • 1
Josselin
  • 2,593
  • 2
  • 22
  • 35