コード例 #1
0
ファイル: hw3pr1.py プロジェクト: JustisAllen/fluency-lab
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' )
コード例 #2
0
ファイル: hw3pr1.py プロジェクト: JustisAllen/fluency-lab
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'
コード例 #3
0
ファイル: hw3pr1.py プロジェクト: cheshireAce/fluency-lab
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' )
コード例 #4
0
ファイル: hw3pr1.py プロジェクト: cheshireAce/fluency-lab
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' )
コード例 #5
0
ファイル: hw3pr1.py プロジェクト: cheshireAce/fluency-lab
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' )
コード例 #6
0
ファイル: hw3pr1.py プロジェクト: JustisAllen/fluency-lab
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' )
コード例 #7
0
ファイル: hw3pr1.py プロジェクト: cheshireAce/fluency-lab
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' )
コード例 #8
0
ファイル: hw3pr1.py プロジェクト: cheshireAce/fluency-lab
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' )
コード例 #9
0
ファイル: hw3pr1.py プロジェクト: JustisAllen/fluency-lab
def test():
    """ a test function that plays swfaith.wav
        You'll need swfailt.wav in this folder.
    """
    play( 'swfaith.wav' )
コード例 #10
0
ファイル: hw3pr1.py プロジェクト: ZoabKapoor/fluency-lab
 def play(self):
     writewav(self.samps, self.sr, "temp.wav")
     play("temp.wav")
コード例 #11
0
ファイル: hw3pr1.py プロジェクト: hmc-aozdemir/fluency-lab
 def play( self):
     self.write(filename = 'temp.wav')
     play('temp.wav')
     os.remove('temp.wav')
     return self
コード例 #12
0
ファイル: hw3pr1.py プロジェクト: aputman/fluency-lab
def play(sound):
    samps, sr = sound
    writewav(samps, sr, "out.wav")
    play('out.wav')
コード例 #13
0
ファイル: hw3pr1.py プロジェクト: bwiedermann/fluency-lab
# 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)