## CS 111 - Introduction to Computing

### Lab 14

In this lab, you will take the Sound File preamble.wav and create a new sentence from those words.

The sentence you are to create is:

We common people promote united tranquility.

The entire text of the Preamble is:

We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defense, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.

The following words begin at the given sample numbers in the file:

• 7519 We
• 15235 the
• 18742 people
• 29767 of
• 32457 the
• 34045 United
• 40527 States
• 54838 in
• 58653 order
• 64386 to
• 67561 form
• ????? a - not sure if this is actually spoken in the sound
• 74859 more
• 78894 perfect
• 86744 union
• 101363 establish
• 116027 justice
• 132829 ensure
• 142134 domestic
• 152012 tranquility
• 174240 provide
• 185130 for
• 189122 the
• 189189 common
• 196112 defense
• 212000 promote
• etc....
You will need to read in the sound file, separate out the needed words, and then join the word together into a single sound. The code to separate out the needed words can be found in lect0419c.py, while the code to join them together is found in lect0419d.py.

You may want to include some break/silence between the words of your newly created sentence, but this is not a requirement.

### Using a Loop

You are to build up the final sound using a loop similar to what was done in lect0426b.py.

To help with the loop, you can create two lists of integer values that contain the starting indexes of the words in one list and the ending indexes of the words in the other list. When you are building the i-th word for the sentence, you can use the loop counter with the lists to get the start and end indexes as needed for the parameters for the makeSoundByte( ) function.

For this loop, the two lists could be set up as follows:

# indexes for the sentence: People establish order to provide justice

# This is sentence you are to create for this lab!

# So these are NOT the actual values that you should be using for this lab!
startIndexList = [ 18742, 101363, 58653, 64386, 174240, 116027 ]
endIndexList = [ 29767, 116027, 64386, 67561, 185130, 132829 ]

### Notes on the two needed functions

To separate out a specify word from a longer sound:

• First determine the starting and ending sample index of the needed word.
• Next create a new sound of the length between the starting and ending indices. (Subtract the starting index from the ending index).
• Copy the sample values from the starting index to the ending index place them in the new sound beginning at index position 0.
To join two sound objects together into a new sound:
• First determine the length of the two original sound objects. The length of the new/joined sound object will be these two lengths added together.
• Next copy all of the samples from first original sound object into the new/joined sound object (where the first original sound object's sample is placed into the first sample of the new/joined sound object).
• Final copy all of the samples from the second original sound object into the new/joined sound object but the position needs to be shifted by the length of the first original sound object.

### Lab Assignment 14

Due: Wednesday 5/2/2018 by 11:59 pm

Create a Python program that will be written using good programming style, which includes using:

• Multiple Methods
• Meaningful variable names
• In-line commenting
• Proper indentation of program statements
• Use of blank lines to separate blocks of code
• Header Block Commenting for the entire program
• Header Block Commenting for each method
• Net-ID,
• Course Name,
• Assignment Name,
• Day and time of the CS 111 lab section (i.e. Monday at 11:00 am)
• A short description of the assignment
• A description of the purpose of the method
• A listing of the name, type, and purpose of every parameter
• A description of the return value and its type
Required Methods for the Lab Assignment:
• Your program is to contain the main() method that will:
• Prompt the use for the sound file to be used for input for this lab.
• Use a loop to build up the final sound similar to what was done in: lect0426b.py.
• Create each i-th word needed by using a call to the "make sound bite" method specified below.
• Join those i-th words to the final sentence using a call to the join sound method specified below.
• Play (or explore) the sound.
• Prompt the user for a name and save it.

• Your program is to contain a method called makeSoundByte() that will:
• take a sound as its first parameter,
• take two integer values as its second and third parameters
• verify that the second and third parameters contain valid values:
• the value of the second parameter is greater than or equal to zero
• the value of the second parameter is less than or equal to the third parameter
• the value of the third parameter is less than or equal to the length of the sound given as the first parameter.
• create a newly created sound that contains only those samples found between the index positions indicated by the integer values given as the second and third parameters
• return the newly created sound from the method

• Your program is to contain a method called joinSounds() that will:
• take two sound objects as parameters and
• return a newly created sound object.
• The newly created sound object will contain the first sound object followed by the second sound object. (This is similar to the makeCollage() methods we created for pictures.)
You are also to submit the Python file electronically via the assignment link for Lab 14 in BLackboard.
Topic revision: r1 - 2018-04-26 - 21:01:55 - Main.troy

 Copyright 2016 The Board of Trustees of the University of Illinois.webmaster@cs.uic.edu WISESTHelping Women Faculty AdvanceFunded by NSF