Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment you will compose a unique piece of music by playing a sequence of ( given ) sound files stored on your computer.
In this assignment you will "compose" a unique piece of music by playing a sequence of given sound files stored on your computer. The objective of this assignment is to give you practice structuring a program using multiple functions. The fun of this assignment is that you will get to play music. However, given the range of hardware devices that you all are working on playing music may not, in fact, work for you. If you cannot get the music to play on your device, it is fine although not quite as much funyou will not lose marks for this, and you can most certainly do the assignment just the same. A Musikalisches Wrfelspiel is a process for generating music by concatenating a random sequence of precomposed musical fragments. In this exercise, you will compose a Viennese waltz in the style of Mozart by playing a sequence of WAV files sound files that are chosen at random according to the results of throwing dice, as described below. The waltz is composed of two partsthe minuet, followed by the trio. Minuet. The minuet consists of a sequence of N musical phrases numbered to N For the purposes of this assignment, a musical phrase is short musical fragment, approximately two seconds in length. Each minuet phrase is stored in a file on your computer see the attached MusicFiles zip file and is called "minuetiswav" where i is a number between and and s is a number between and A file name which represents the phrase to play will be generated at random and that phrase will be played. To determine which WAV file to play for phrase i roll two dice. If the sum is s then play minuetiswav. For example, if you roll an for phrase then play minuetwav. Note that each roll has possible outcomes through but some outcomes such as are much more likely than others such as or Trio. The trio consists of a sequence of M phrases numbered to M each chosen at random. Trio files are each stored in a file on your computer see the MusicFiles zip file and are called "trioiswav" where i is a number from to and s is a number from to To determine which WAV file to play for phrase i roll one die. If the result is s then play trioiswav. For example, if you roll a for phrase then play triowav. Setup Data files The WAV files are available for download in the MusicFiles zip file in the Quick Links. Save this zip file to a folder directory and unzip it to the same folder that your python program is or will be in It is suggested that you call your python program aMusicPlayer or something else that starts with a so that the python file will appear at the top of the list of the many wav files. It will be easier to find that way. Playing a WAV file Windows: To play a WAV file, use the following: import winsound #play a wav file winsound.PlaySoundminuetwav', winsound.SNDFILENAME You can test this by putting the lines above in a new Python file and try it out. You must have the file called minuetwav in the same directory as your test python file. Macs: Install playsound by opening a terminal window and typing: pip install playsound Play the file using: from playsound import playsound #play a wav file playsoundminuetwav' You can test this by putting the lines above in a new Python file and try it out. You must have the file minuetwav in the same directory as your test python file. If the sound doesn't work for you or you are working on replit.com or another online platform: You can still write the program even if you cannot get the sound to workjust print out the file names that would be played instead of playing them. Add a comment where you would play the file if you were on a different computer. It would be a good idea to have a friend test out your program for you if possible. There will be no points deduction for the sound not playing but you must print the file names if you do not play the sounds. Function Documentation Now that you are writing functions, we expect to see function header comments in addition to the program header. We would like you to follow the convention below for writing your function headers called "docstrings" Please note that this is different than what the book shows. Our method follows the suggested styling found in the pep Python style guide for docstring conventions. A docstring, short for documentation string is a string literal that serves as documentation of the program. Every function should have a docstring that describes what the function's purpose is anything
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started