Question: mozart _ walz _ generator playwaltz . py , line 4 6 , in stdaudio.playFile ( filename ) File . . .

mozart_walz_generator\playwaltz.py", line 46, in
stdaudio.playFile(filename)
File "...stdaudio.py", line 64, in playFile
a = read(f)
^^^^^^^
File "...stdaudio.py", line 101, in read
temp.append(float(samples[i])/ float(0x7fff))
^^^^^^^^^^^^^^^^^
TypeError: only length-1 arrays can be converted to Python scalars
import stdio
import stdaudio
import sys
# readAllInts is already a list, store our input in measures
measures = stdio.readAllInts()
# write an if statement if the input is no equal to 32-- also use len(measures) to check the number of input
# if not equal to 32, print the message by using sys.exit()
if len(measures)!=32:
# write the message if not equal to 32
sys.exit(str("A waltz must contain exactly 32 measures"))
# write for i in range from measures[0] to measures[15], because we want to check the first 16 value is from minuet measure
for i in range(16):
# write if is not between 1 and 176
if not (1= measures[i]=176):
# if not , we print a status say it must between 1 and 176
sys.exit(str("A minuet measure must be from [1,176]"))
# write for loop i in range form 16 to 32 the last 16 elements that we want to access
for i in range(16,32):
# we use if statement to check is the value between 1 and 96
if not (1= measures[i]=96):
# if not between, we print a status say it must between 1 and 96
sys.exit(str("A trio measure must be from [1,96]"))
# set a for loop v in range from [0] to [15], we want at to have the first 16 value
for v in range(16):
# we store the value in waltz each time
waltz = measures[v]
# we set the file name
filename = f"data\\M{waltz}"
# we use stdaudio.playFile to play the music which choose from M.wav
stdaudio.playFile(filename)
# set a for loop v in range from [16] to [31], we want at to have the last 16 value
for v in range(16,32):
# we store the value in trio each time
trio = measures[v]
# we set the file name
filename = f"data\\T{trio}"
# we use stdaudio.playFile to play the music which choose from T.wav
stdaudio.playFile(filename)
Part II (Mozart Waltz Generator)\(\cdot \) Problem 7(Playing the Waltz)
playwaltz.py
Standard input
a sequence of 32 measures of a waltz
Standard audio the waltz
```
~/workspace/mozart_waltz_generator
python3 generatewaltz.py data/mozart.txt | python3 playwaltz.py
``` Part II (Mozart Waltz Generator)\(\cdot \) Problem 7(Playing the Waltz)
Set measures to a list of ints (representing measures of a waltz) read from standard input (use stdio.readAliInts())
Exit the program with the message "A waltz must contain exactly 32 measures" if measures does not contain 32 values (use sys.exit())
Exit the program with the message "A minuet measure must be from \([1,176]\)" if the any of the first 16 values of measures is not from the interval [1,176](use sys.exit())
Exit the program with the message "A trio measure must be from [1,96]" if the any of the last 16 values of measures is not from the interval \([1,96]\)(use sys.exit())
For each \( v \) of the first 16 values in measures
- Set filename to "data/M"\(+v \)
- Play the audio file with the name filename (use stdaudio.playFile())
For each \( v \) of the last 16 values in measures
- Set filename to "data/T"\(+v \)
- Play the audio file with the name filename (use stdaudio.playFile())
mozart _ walz _ generator \ playwaltz . py " ,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!