Page 1 of 1

You are to write a Python program which edits audio files, specifically .wav files. You will take an input audio file ca

Posted: Wed Apr 27, 2022 3:33 pm
by answerhappygod
You are to write a Python program which edits audio files,
specifically .wav files. You will take an input audio file called
inp.wav, perform some transformations, and create a new audio file
called out.wav.
You will not be writing the code to deal with the .wav file
directly. You will make use of the code that I give you (which, in
turn, makes use of the built-in Python "wave" module). After the
midterm, we will learn what the code does that I give you. For now,
you do not need to understand it, only to make use of it.
An audio wave can be represented as a list of floats ranging
from -1.0 to 1.0. Loud sounds oscillate closer to -1.0 and 1.0
while quieter sounds oscillate close to 0.0. High-pitched sounds
oscillate very quickly, while low-pitched sounds oscillate more
slowly.
You are to do 2 transformations on the audio:
Amplification
You will ask the user for an amplification factor, which is a
float. An amplification factor of 1.0 would mean that the volume
stays exactly the same between input file and output file. An
amplification factor of 0.5 would mean that the output file will be
quieter (50% as loud) compared to the input file. An amplification
factor of 2.0 would mean that the output file will be louder (200%
as loud) compared to the input file.
When amplifying, you need to multiply each value in the list by
the amplification factor. You will also have to "clip" the audio to
ensure that it never goes above 1.0 or below -1.0. If any value,
after amplification, is above 1.0, cap it at 1.0. Similarly, if any
value, after amplification, goes below -1.0, cap it at -1.0.
Speed-up
You will ask the user for a speed factor, which is a float. A
speed factor of 0.5 would mean that the output file would be slowed
down, with a lower pitch. The output file would also be twice as
long as the input file.
A speed factor of 2.0 would mean that the output file would be
sped up, with a higher pitch, sounding a bit like a chipmunk. The
output file would also be only half as long as the input file.
To translate an index from the output audio into an index in the
input audio, multiply by the speed factor. For example, if the
speed factor is 1.5 and the index in the output audio is 10, then
the corresponding index in the input audio is 15.
Note: I will post a video here later today giving a more
detailed explanation of what I mean.
When building the list for the output audio, you will need to
calculate the index for the input audio. What if it is not an
integer? If you are satisfied with 90% in this assignment, you may
simply round down (e.g., using the int() type-conversion function).
If you want 100% on this assignment, you will need to implement
"linear interpolation". This means that, for example, if your index
into the input audio is 7.2, you will mix 80% of the value from
index 7 with 20% of the value from index 8.
My code
Here is the code that I have written. Please copy-and-paste this
code at the top of your file:
You do not need to understand it.
Your code
Below my code, you will implement the rest of the function. You
will:
Then, listen to out.wav to ensure that your code worked
correctly.
I have given you a sample inp.wav (Red Velvet's Wendy saying
that she is from Canada) that you can use for testing. I have also
given you a sample out.wav, which corresponds to an amplification
factor of 2.0 and a speed factor of 1.5. If you would like more
sample data to work with, please let me know.