Fall 2003 Homework 3 Questions
Questions about your sentences project? Post them here!
Check back often to see answers, and to see answers to others' questions. (Feel free to answer for each other!)
I'm trying to shorten the code. Is there any chance a function can return more than one variable (both "target" and "index")?
I am having trouble playing any of the media in the Speech folder. Windows Media Player is saying something about "codecs" and cannot play the file. What should I do?
| If you record yourself saying some fun word or phrase (e.g., "Georgia Tech" or "Georgia" or "Bulldogs" or "Guzdial"), feel free to post it here as a .wav file for others to download and use in their audio sentences/collages! Mark Guzdial |
Is the sampling rate 22,000 or 44,000? That would make 1/10 of a second silence to be a range of (1,2200), correct? (if the sampling rate is 22,000), which I think it says in the book.
| The sampling rate depends on your sound. getSamplingRate(sound) will tell you what the sampling rate is on THAT sound. Mark Guzdial |
Part of HW3
Done in class today:
def merge():
guzdialsound = makeSound(getMediaPath("guzdial.wav"))
issound = makeSound(getMediaPath("is.wav"))
target = makeSound(getMediaPath("sec3silence.wav"))
index = 1
# Copy in "Guzdial"
for source in range(1,getLength(guzdialsound)):
value = getSampleValueAt(guzdialsound,source)
setSampleValueAt(target,index,value)
index = index + 1
# Copy in 0.1 second pause (silence) (0)
for source in range(1,int(0.1*getSamplingRate(target))):
setSampleValueAt(target,index,0)
index = index + 1
# Copy in "is"
for source in range(1,getLength(issound)):
value = getSampleValueAt(issound,source)
setSampleValueAt(target,index,value)
index = index + 1
normalize(target)
play(target)
return target
def normalize(sound):
largest = 0
for s in getSamples(sound):
if abs(getSample(s)) > largest:
largest = abs(getSample(s))
multiplier = 32767.0 / largest
print "The largest value we saw was:",largest
print "Our multiplier is",multiplier
for s in getSamples(sound):
louder = multiplier * getSample(s)
setSample(s,louder)
And these are the sound files (from 1 pm class). Mark Guzdial
guzdial.wav
is.wav
fallbreak.wav
cs1315.wav
Could you post a longer silence for us to use? I am using the three seconds, but I need to fit one last word. Will the updates for Jes allow me to create any length of silence? If so, how do I do that? #12
| makeEmptySound(10) will create a 10 second sound. Mark Guzdial |
Do we have to record sounds, or can we just use the words that are already recorded in our speech folder?
| See the Homework 3 definition – you are ENCOURAGED to use the words that are in the Speech folder! Mark Guzdial |
By "doubling the amplitude" of the last word, you mean increase the volume one hundred percent, right? And it says to turn in all the sounds we use. My six words were all from the Speech folder. Do I still need to attach them all as I turnin the assignment? #12
| No, that's okay – if they're all from the Speech folder, that's okay. (It's not a mistake if you do turn them in.) Turn in others you use. Yes, by doubling, I mean increasing by 100% – i.e., multiply each sample by 2. Mark Guzdial |
How exactly are you supposed to do the makeEmptySound(10)? Do you put it in place of the sec3silence.wav? Or is it a completely different line? Or do you set it equal to target?
>>> mysound = makeEmptySound(10)
>>> print mysound
Sound of length 220500
>>> play(mysound)
This might be a stupid question, but do we put SetMediaPath() in program area or TAs will set it themselves. I moved all of my sound files into media sources. Another question is, do we need to turn in our final sentence and how do we save it? Thank you.
| Yes, the TA's will know to setMediaPath(). Don't put it in your programs. You don't have to turn in your final sentences, but if you want to post them on the Fall2003 HW3 Sentences page, you simply write out the sound using writeSoundTo – just as you did with writePictureTo. Then upload the wav file. Mark Guzdial |
When Itry to double the amplitude on the last word, I get a little bit of trouble with clipping. It's still intelligible, but also unmistakable. I doubled the amplitude by having the segment of the program that deals with the last function read setSampleValueAt(target,index,value*2) I'm not at my JES computer, so I can't give you the values for amplitude at the clipping, I'm afraid. Jeff Baker
| That's the right thing to do, Jeff. If it clips, it clips. That's okay – as long as it's clear that you did the doubling. Mark Guzdial |
K, well i used the code exactly like u used in class.. and everything worked fine until I added another .1 second pause and the president.wav file. I keep getting this error
I wasn't able to do what you wanted.
The error JavaSoundException has occured
# Copy in "president"
for source in range(1,getLength(president)):
value = getSampleValueAt(president,source)
setSampleValueAt(target,index,value)
index = index + 1
It is refering to te setSampleValue line.
Any ideas whats wrong?
| The index is probably farther than the length of the target. Put in a line just before the setSampleValueAt line "print index,getLength(target)". If the index ever gets larger than the length, that's your reason. "President" is a long word – you may be going too long. Think about using makeEmptySound instead of the 3 seconds of silence. Mark Guzdial |
I am guessing makeEmptySound is a function understood by JES? and do we simply set the target = makeEmptySound.. or am I incorrect?
makeEmptySound is explained about three questions above yours.
I downloaded sound sounds from the net to make a sentence out of. When I play them invidiually in JES they work just fine, but when I try to make a sentence with them, the result is heavily distorted. I have no trouble making a sentence with the samples provided on the CD, but I was trying to be a little wackier with my sentence. Any suggestions? Jeff Baker
Sampling rate?
| The sampling rate shouldn't be an issue when you're moving samples around, I don't think. I don't really know, Jeff. If you want to send me some of the sounds and some sample code, I'll explore and see what I can figure out. Mark Guzdial |
makeEmptySound, and no normalize
Folks, here's the above code using makeEmptySound. N.B. –> YOU DO NOT HAVE TO NORMALIZE THE SOUND! I only did it to make the sound louder in the large Architecture auditorium. This version is fine and doesn't normalize. Mark Guzdial
def merge():
guzdialsound = makeSound(getMediaPath("guzdial.wav"))
issound = makeSound(getMediaPath("is.wav"))
target = makeEmptySound(3)
index = 1
# Copy in "Guzdial"
for source in range(1,getLength(guzdialsound)):
value = getSampleValueAt(guzdialsound,source)
setSampleValueAt(target,index,value)
index = index + 1
# Copy in 0.1 second pause (silence) (0)
for source in range(1,int(0.1*getSamplingRate(target))):
setSampleValueAt(target,index,0)
index = index + 1
# Copy in "is"
for source in range(1,getLength(issound)):
value = getSampleValueAt(issound,source)
setSampleValueAt(target,index,value)
index = index + 1
play(target)
return target
ok so it plays all three words but it does not sound like the last one is twice as loud. I used the setSampleValueAt(sound, index, value2)..basically the same one from the quiz for doubling the sounda and I also did
increaseVolume(worksound)
normalize(target)
play(target)
return target
where I just tried to increase the volume of my last word which was worksound...is this not right?
Do I have to break my sound into thirds according to which word for the range? right now I have the range from (1, getLength(sound)+1)
| Think about what it means to double the VALUE of the SOURCE SAMPLE, then look at your last loop again. You don't hve to use increaseVolume(), and you DEFINITELY don't need normalize(). Mark Guzdial |
Okay.. so i set target as makeEmptySound(10).. and JES gives me this
A local or global name could not be found. You need to define the function or variable before you try to use it in any way.
I thought makeEmptySound was a default function understood by JES.. am i wrong?
how do i get writeSoundTo to work?
| Have you tried the examples in the book? Or perhaps some of the answers to other questions? Or perhaps in the Help built in to JES? If you have a specific question or an error you're getting, I'd be glad to help, but I don't know in general how to add to all those other places where that question is answered. Mark Guzdial |
ok i recorded 2 of my own words for my sentence and when i play them in winamp compared to the given words in speech folder they are of similar volume if not louder. when i put them in my hw3 program they play so quiet compared to the given ones you cant hardly hear it. this happens even after i normalize the whole sound. what is going on??
| Did you record using the MediaTools application or Windows Recorder? Windows Recorder generates incompatible sounds. You have a couple of choices. (a) Re-record your sounds in MediaTools. (b) Use a tool like QuickTime Player (http://www.apple.com/quicktime) to open your sound then export it as WAV. QuickTime can read Microsoft format and generate formats that are compatible with Java and the rest of the universe. You'll need to have purchased QuickTime Pro to be able export sounds from QuickTime Player. There are other audio editing tools available (like Audacity at http://audacity.sourceforge.net/) that might be able to fix Windows Recorder sounds, but I haven't tried those yet. Mark Guzdial |
do you suggest that we setMediaPath to mediasources or speech folder?
| Your choice, but all your sounds should be in the same folder. Mark Guzdial |
Clipping work-around...
I was wondering if this was an acceptable workaround to the clipping problem with the last word. Instead of doing a (value X 2) on the last sound, I did a (value / 2) on all the others and followed that up with a normalize... Doubling the last sound while keeping it under the maximum level. Does this sound acceptable or should I just simply double the last sound and stick with that horrid clipping noise?
Greg Leo
| I don't want to change the assignment now, but you're right – it is horrid. I won't make that requirement in future assignments. But for now, stick with multiplying by two and grimace slightly as it plays. Mark Guzdial |
What if we used sounds with different bitrates? There would be some distortion.
| Bitrates? Or sampling rates? If you use sounds with different sampling rates, yes, you'll get slowdown or speedup when you play your target sound. But you know how to change the sampling, so you can adapt to that. Mark Guzdial |
Big News: Windows Sound Recorder now works in JES!
Go to Course Software (JES) and grab the 10-15 update. Sounds recorded with Windows Sound Recorder will now work! Mark Guzdial
when i try to execute the function, all i get is static in place of the words when it returns the target. what is wrong?
the target = makeEmptySound(10) gives the error "A local or global name could not be found. You need to define the function or variable before you try to use it in any way".... do you have to do something in the command area to get it to work?
| Folks, just downloading the update isn't enough. You have to download the file into the same folder as your JES.exe, then execute it. Click the Unzip button. Then the new update will be installed. Simply downloading the file isn't enough to update your JES. Mark Guzdial |
| If you downloaded a file that ends in .zip, then you've downloaded ALL of JES. You don't have to run it in a particular place, just unzip it to a folder and use that version of JES from now on. You can stop using your old one. If you downloaded a file that ends in .exe, then you have to RUN that program in your JES folder. It upgrades the JES you are currently using. Adam Wilson |
HELP- I cannot even open anything in the speech file. I can open "hello world" in media sources. I keep on getting this message-"Windows Media Player cannot play the file. The File may be formatted with an unsupported codec or the internet security setting on your computer is set too high. Lower your browser security setting". I tried to lower my security setting and nothing happened. Please help!
| Why are you trying to open these in Windows Media Player? Read the book – Windows uses a non-standard form of WAV. Try using WinAmp, or just opening and playing them in JES. It has nothing to do with your security settings. Mark Guzdial |
I'm still having trouble getting the last word to double it's amplitude. I have this under the hw3() function and am using a range, but nothings seems to be happening. It just doesn't make sense.
def doubleAmplitude(sound):
largest = 0
for sampleIndex in range(((getLength(sound)/2)*2),(getLength(sound)+1)):
value = getSampleValueAt(sound,sampleIndex)
setSampleValueAt(sound,sampleIndex,value * 2)
On the same note, where in the hw3() function would be a good place to call for the normalizing of the last word? I would think it would be the same as the example (right above the play command).
| First, YOU DO NOT NEED TO NORMALIZE! I did it once in an example. It is not at all required or even recommended for this assignment. Second, you don't need this function to double the volume of the last word. Do you have a loop where you're copying in the last word into the target, sample-by-sample? Why not just multiple each sample by two then, as you're copying them in? Mark Guzdial |
hmmm...interesting idea...thanks
After you download the update, what "unzip button" are you talking about? Just opening the folder once it's downloaded?? because my program still won't work
| The update is an .exe file. Double-click it. You'll see an Unzip button. Press it. The directions are on the table. Mark Guzdial |
I keep getting this error message, and I have no idea what it means. And why are there four different numbers??
>>> hw3()
>>> hw3()
>>> hw3()
_
>>> hw3()
>>> hw3()
>>> hw3()
_
media.Sound instance at 15102369
| You're returning the sound, that's what you're seeing. Mark Guzdial |
What are the username and password to attach and upload my sentence?
Precisely when is this assignment due?
Is there any way i can use words that are not in the speech folder or recording words myself?
| Yes – did you not see me do this in lecture, or read the notes earlier about recording words with Windows Sound Recorder? Just turn in whatever words you use. Mark Guzdial |
Link to this Page