mmngreco
3/5/2018 - 8:36 AM

play_sound_python.md

play_sound_python.md

source : https://stackoverflow.com/posts/16573339/

On Windows

import winsound
duration = 1000  # millisecond
freq = 440  # Hz
winsound.Beep(freq, duration)

Where freq is the frequency in Hz and the duration is in milliseconds.

On Linux (and Mac)

import os
duration = 1  # second
freq = 440  # Hz
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % (duration, freq))

In order to use this example, you must install sox.

On Debian/Ubuntu/LinuxMint you need to run in your terminal:

sudo apt install sox

Here is the macports way of doing that...run this is your terminal:

sudo port install sox

Speech on Mac

And something really cool if you're using a mac in terminal, maybe can do the same in windows, but I only know for sure for mac, this will tell you it's done:

import os
os.system('say "your program has finished"')

Speech on Linux

import os
os.system('spd-say "your program has finished"')

You need to install the speech-dispatcher package in Ubuntu (or the corresponding package on other distributions):

sudo apt install speech-dispatcher