Exemplo n.º 1
0
def pure_tone(freq, time_in_seconds):
    """ plays a pure tone of frequence freq for time_in_seconds seconds """
    print "Generating tone..."
    samps, sr = gen_pure_tone(freq, time_in_seconds)
    print "Writing out the sound data..."
    writewav( samps, sr, "out.wav" )
    print "Playing new sound..."
    play( 'out.wav' )
Exemplo n.º 2
0
def changeSpeed(filename, newsr):
    """ changeSpeed allows the user to change an audio file's speed
        input: filename, the name of the original file
               newsr, the *new* sampling rate in samples per second
        output: no return value; creates and plays the file 'out.wav'
    """
    samps, sr = readwav(filename)

    print "The first 10 sound-pressure samples are\n", samps[:10]
    print "The original number of samples per second is", sr
    
    newsamps = samps                        # no change to the sound
    writewav( newsamps, newsr, "out.wav" )  # write data to out.wav
    print "\nPlaying new sound..."
    play( 'out.wav' )   # play the new file, 'out.wav'
Exemplo n.º 3
0
def static(filename, probability_of_static):
    """ static introduces random bits of static based on the probability given
        input: filename, the name of the original file
        output: no return value, but
                this creates the sound file 'out.wav'
                and plays it
    """
    print "Playing the original sound..."
    play(filename)
    
    print "Reading in the sound data..."
    samps, sr = readwav(filename)
    
    print "Computing new sound..."
    newsamps = replace_some(samps, probability_of_static)
    newsr = sr                       # no change to the sr
    
    writewav( newsamps, newsr, "out.wav" )
    print "Playing new sound..."
    play( 'out.wav' )
Exemplo n.º 4
0
def volume(filename, scale_factor):
    """ volume increases the volume by the floating-point value scale_value
        input: filename, the name of the original file
        output: no return value, but
                this creates the sound file 'out.wav'
                and plays it
    """
    print "Playing the original sound..."
    play(filename)
    
    print "Reading in the sound data..."
    samps, sr = readwav(filename)
    
    print "Computing new sound..."
    newsamps = [x * scale_factor for x in samps]
    newsr = sr                       # no change to the sr
    
    writewav( newsamps, newsr, "out.wav" )
    print "Playing new sound..."
    play( 'out.wav' )
Exemplo n.º 5
0
def reverse(filename):
    """ reverse reverses the original file
        input: filename, the name of the original file
        output: no return value, but
                this creates the sound file 'out.wav'
                and plays it
    """
    print "Playing the original sound..."
    play(filename)
    
    print "Reading in the sound data..."
    samps, sr = readwav(filename)
    
    print "Computing new sound..."
    newsamps = samps[::-1] # reverse
    newsr = sr                       # no change to the sr
    
    writewav( newsamps, newsr, "out.wav" )
    print "Playing new sound..."
    play( 'out.wav' )
Exemplo n.º 6
0
def flipflop(filename):
    """ flipflop swaps the halves of an audio file
        input: filename, the name of the original file
        output: no return value, but
                this creates the sound file 'out.wav'
                and plays it
    """
    print "Playing the original sound..."
    play(filename)
    
    print "Reading in the sound data..."
    samps, sr = readwav(filename)
    
    print "Computing new sound..."
    # this gets the midpoint and calls it x
    x = len(samps)/2
    newsamps = samps[x:] + samps[:x] # flip flop
    newsr = sr                       # no change to the sr
    
    writewav( newsamps, newsr, "out.wav" )
    print "Playing new sound..."
    play( 'out.wav' )
Exemplo n.º 7
0
def echo(filename, time_delay):
    """ echo takes in a filename and overlays the same sound on itself, shifted by time_delay
        input: filename, the name of the original file
        output: no return value, but
                this creates the sound file 'out.wav'
                and plays it
    """
    print "Playing the original sound..."
    play(filename)
    
    print "Reading in the sound data..."
    samps, sr = readwav(filename)
    
    print "Computing new sound..."
    echosamps = [0]*(time_delay*float(sr)) + samps
    echosamps = echosamps[:len(samps)]
    newsamps = [echosamps[i]+samps[i] for i in xrange(len(samps))]
    newsr = sr                      # no change to the sr
    
    writewav( newsamps, newsr, "out.wav" )
    print "Playing new sound..."
    play( 'out.wav' )
Exemplo n.º 8
0
def overlay(filename1, filename2):
    """ overlay creates a sound that overlays the two given sound files
        input: filename, the name of the original file
        output: no return value, but
                this creates the sound file 'out.wav'
                and plays it
    """
    print "Playing the original sound..."
    play(filename1)
    play(filename2)
    
    print "Reading in the sound data..."
    samps1, sr1 = readwav(filename1)
    samps2, sr2 = readwav(filename2)
    
    print "Computing new sound..."
    newsamps = add_scale_2(samps1, samps2, 0.5, 0.5)
    newsr = (sr1+sr2)/2                      # no change to the sr
    
    writewav( newsamps, newsr, "out.wav" )
    print "Playing new sound..."
    play( 'out.wav' )
Exemplo n.º 9
0
 def save(self, output_filename):
     writewav(self.samps, self.sr, output_filename)
     return self
Exemplo n.º 10
0
 def save(self):
     writewav(self.samps, self.sr, "out.wav")
     return self
Exemplo n.º 11
0
 def play(self):
     writewav(self.samps, self.sr, "temp.wav")
     play("temp.wav")
Exemplo n.º 12
0
 def write( self, filename = 'out.wav'):
     writewav( self.samps, self.sr, filename)
     return self
Exemplo n.º 13
0
def save(sound, filename):
    samps, sr = sound

    writewav(samps, sr, filename)
Exemplo n.º 14
0
def play(sound):
    samps, sr = sound
    writewav(samps, sr, "out.wav")
    play('out.wav')
Exemplo n.º 15
0
# contains samples & sampling rate. The function performs the operation, and 
# returns the new samples and sampling rate. A separate function wraps each 
# modOp. This function takes a filename and additional arguments, opens the 
# file, reads the data, calls the corresponding modOp function, writes the 
# results to an output file, and plays the result.
################################################################################
    
# helper functions

def playNewSound( (data, rate), outputFilename='out.wav'):
    '''Given a (sample, sampling rate) tuple and the name of an output file, 
       the function will write the sound data to the output file and play it.
    '''

    print "Playing new sound..."
    writewav(data, rate, outputFilename)
    play(outputFilename)


def combineFiles(filenames, combinator, outputFilename="out.wav"):
    '''Given a list of sound files, combines the sounds in those files,
       according to the supplied function, and plays the result.

       The function expects one argument: a list of sound data tuples.
    '''
    
    print "Reading in the sound data..."
    data = map(readwav, filenames)
    
    print "Computing new sound..."
    newSound = combinator(data)