Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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
216,175 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.