Silent Night….In Python

19 Dec

Was looking at the Python documentation, you can always find some cool stuff you have never notices, and found ‘winsound.’ There is a function called Beep(). So, being Christmas,  I wrote silent night using winsound.Beep(). I got the notes from Google, there are a couple of low notes I don’t like, but this was just a quick test for fun.

Here is the code:

import winsound

winsound.Beep(392,600)
winsound.Beep(440,400)
winsound.Beep(392,400)
winsound.Beep(329,700)

winsound.Beep(392,600)
winsound.Beep(440,400)
winsound.Beep(392,400)
winsound.Beep(329,700)

winsound.Beep(587,600)
winsound.Beep(587,400)
winsound.Beep(494,700)

winsound.Beep(523,600)
winsound.Beep(523,400)
winsound.Beep(392,700)

winsound.Beep(440,600)
winsound.Beep(440,600)
winsound.Beep(523,700)
winsound.Beep(494,400)
winsound.Beep(440,600)
winsound.Beep(392,700)
winsound.Beep(440,400)
winsound.Beep(349,700)
winsound.Beep(329,800)

winsound.Beep(440,600)
winsound.Beep(440,600)
winsound.Beep(523,700)
winsound.Beep(494,400)
winsound.Beep(440,600)
winsound.Beep(392,700)
winsound.Beep(440,400)
winsound.Beep(349,700)
winsound.Beep(329,800)

winsound.Beep(587,800)
winsound.Beep(587,800)
winsound.Beep(698,700)
winsound.Beep(587,800)
winsound.Beep(494,400)
winsound.Beep(523,800)
winsound.Beep(659,800)

winsound.Beep(523,800)
winsound.Beep(392,800)
winsound.Beep(329,700)
winsound.Beep(392,800)
winsound.Beep(349,400)
winsound.Beep(293,800)
winsound.Beep(261,900)

Advertisements

5 Responses to “Silent Night….In Python”

  1. alessandro February 11, 2013 at 8:10 pm #

    i have a question for you:
    i cannot run this program on python because if I copy all the program in the compilator, python tell me that there is a syntax errore

    this is an example:
    >>> import winsound
    >>> winsound.Beep(392,600)
    winsound.Beep(440,400)
    winsound.Beep(392,400)
    winsound.Beep(329,700)
    SyntaxError: multiple statements found while compiling a single statement

    do you know how can i create a sound sequence on python?
    can you write me the code to doing this?

    sorry, i’m a beginner with programing and so my question could seems quite stupid,
    for the same reason i ask you to answer me like you answer a child…

    Thanks

    🙂

    • paulcrickard February 11, 2013 at 8:18 pm #

      It looks like you are copying and pasting in to Python (from the >>> in your comment). After the second line, it looks like the code is being put in one command. you either need to save it in notepad with .py extension or copy and past line by line. There should be a >>> before each line. That should fix it.

      • alessandro February 11, 2013 at 8:35 pm #

        oh! thanks a lot!!! now it works !!!

        i would also ask you if it is possible to insert some silent duration between sound…

      • paulcrickard February 11, 2013 at 9:21 pm #

        You can put the program to sleep.
        import time
        time.sleep(1) # would sleep for a second

      • alessandro February 11, 2013 at 9:25 pm #

        Thanks a lot

        best,

        alessandro

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: