Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Joseph Fuller
Joseph Fuller
1,155 Points

Making a metronome. (Need help with the sound part)

Here's my code for a text based metronome:

import time tempo = input("What tempo would you like your beeps in? ") print("Outputting the word \"Beep\" at {} times per minute".format(tempo)) count = 1 while 1 == 1: print("Beep number: {}".format(count)) time.sleep(60 / int(tempo)) count += 1

so it takes the input value tempo through a question, then has a count that increases each time and outputs this Beep number: 1 Beep number: 2

and so on until 1 stops equaling 1 which is never.How would I add a sound to this code so when the beep comes the computer will output a sound? links or directions to where to learn about this would be much appreciated. using python 3. Thanks

1 Answer

Steven Parker
Steven Parker
229,744 Points

The mechanism for sound creation might depend on your operating system. But if you're on windows, you can make use of the windsound library. A very short duration "Beep" might sound much like a metronome tick.