Beispiel #1
0
def play(wav, fs=44100):
    """
    play(wav, fs=44100)

    Play WAV at sampling rate FS.
    """
    audiolab.play(wav.T, fs)
Beispiel #2
0
    def __play_character(self, character):
        """Play a character through the audio device

        :param character: (str) Character to be played
        :raise TypeError: If a single character is not passed
        """
        play(character)
Beispiel #3
0
    def read_wav(self, sample_path):

        sample = Sndfile(cwd + sample_path, 'r')
        sampling_rate = sample.samplerate
        channels = sample.channels
        encoding = sample.encoding
        frames_count = sample.nframes

        frames = sample.read_frames(frames_count, dtype=np.float32)
        sample.close()
        del sample

        if channels == 1:
            text_type = 'mono'
            sample_type = 0
        elif channels == 2:
            text_type = 'stereo'
            sample_type = 0b01100100
        else:
            text_type = '{0}-channels'.format(channels)

        if OPTIONS['verbose'] > 1:
            print "*", encoding, text_type, 'sample "', sample_path, '"', 4 * frames_count, 'kB'

        if OPTIONS['play_sound']:
            play(frames.astype(np.float64).T, sampling_rate)

        self.update({
            'sample_data': frames,
            'sample_type': sample_type,
            'channels': 2,
            'sample_bittype': 4
        })
Beispiel #4
0
	def playTone(self, freq):

		t = np.arange(0, 0.5, 1./self.fs)
		s = np.sin(2*np.pi*freq*t)

		s_ramp = self._ramped(s, self.fs)

		al.play(s_ramp, self.fs)
Beispiel #5
0
 def on_pick(event):
     try:
         i = artists.index(event.artist)
         print i
         play(pieces[i])
     except:
         return True
     return True
 def play(self):
     if have_sk_audiolab and have_sk_samplerate:
         play(
             np.array(resample(self.data, 44100. / self.fs, 'sinc_best'),
                      dtype=np.float64))
     else:
         print(
             'Warning: scikits.audiolab and scikits.samplerate are required to play audiofiles.'
         )
Beispiel #7
0
def main():
    x, fs, nbits = audiolab.wavread(argv[0])
    audiolab.play(x, fs)
    N = 38*fs    # four seconds of audio
    X = scipy.fft(x[:N])
    Xdb = 20*scipy.log10(scipy.absolute(X))
    f = scipy.linspace(0, fs, N, endpoint=False)
    pylab.plot(f, Xdb)
    pylab.xlim(0, 48000)   # view up to 5 kHz

    Y = X*H
    y = scipy.real(scipy.ifft(Y))
Beispiel #8
0
def play_sin_beep(secs = DEFAULT_SECONDS, notefreq = DEFAULT_FREQUENCY,
        delay = DEFAULT_DELAY):

    # define the length of the beep
    fs = 44100
    vectorstep  = 1/float(fs)

    # create the sinusoidal vector
    sin_vect = sin([2 * pi * notefreq * x for x in arange(0, secs, vectorstep)])
    normalization_const = max(sin_vect)

    beep = array([x/normalization_const for x in sin_vect])

    a.play(beep, fs=fs)
    time.sleep(delay)
Beispiel #9
0
def generate():
    ccipca = CCIPCAProcessor((8193, 200), plot=False)
    ccipca.output_ccipca = CCIPCA(divisi2.load('chess.eigs'))
    pipe = ronwtools.Pipeline(
        ronwtools.AudioSource('../koyaanisqatsi.ogg'),
        ronwtools.Mono(),
        ronwtools.STFT(nfft=16384, nhop=4096, winfun=np.hanning),
        ccipca,
        ronwtools.ISTFT(nfft=16384, nhop=4096, winfun=np.hanning),
        ronwtools.Framer(1048576)
    )
    for segment in pipe:
        print np.max(segment)
        segment /= np.max(segment)
        audiolab.play(segment)
Beispiel #10
0
def learnit():
    ccipca = CCIPCAProcessor((8193, 400), plot=False, amnesia=1.0)
    pipe = ronwtools.Pipeline(
        ronwtools.AudioSource('../chess.ogg'),
        ronwtools.Mono(),
        ronwtools.STFT(nfft=16384, nhop=4096, winfun=np.hanning),
        ccipca,
        ronwtools.ISTFT(nfft=16384, nhop=4096, winfun=np.hanning),
        ronwtools.Framer(524288)
    )
    for segment in pipe:
        segment /= np.max(segment)
        print np.max(segment)
        audiolab.play(segment)
    divisi2.save(ccipca.ccipca.matrix, 'chess2.eigs')
Beispiel #11
0
def audio_test():
    aud = Audio.objects.first()

    print 'Frames: %i' % aud.frames
    print 'Encoding: %s' % aud.encoding
    print 'Rate: %i' % aud.rate
    print 'Channels: %i' % aud.ch
    print 'Speaker: %s' % Speaker.objects.with_id(aud.speaker).name
    print 'Filename: %s' % aud.filename
    print 'Speaker Name: %s' % aud.speaker_name

    fname_out = self_extract(aud.data, aud.filename + '.' + aud.encoding)
    sfile = audio.Sndfile(fname_out, 'r')
    sndvec = sfile.read_frames(aud.frames)

    audio.play(sndvec, aud.rate)
Beispiel #12
0
def al_play(snd, fs):
    import scikits.audiolab as al
    import numpy as np
    from scipy.signal import resample
    if len(snd.shape) == 2:
        if snd.shape[1] == 2 or snd.shape[1] == 1:
            snd = snd.T
        elif snd.shape[0] != 2 and snd.shape[0] != 1:
            print "sound must either a vector or a rank 2 matrix"
            return
        N = snd.shape[1]
    else:
        N = snd.shape[0]
        snd = snd.reshape(-1, N)
    rsmple = resample(snd, N * 44100.0 / (1.0 * fs), axis=1)
    al.play(rsmple, fs=44100)
def audio_test():
    aud = Audio.objects.first()
    
    print 'Frames: %i' % aud.frames
    print 'Encoding: %s' % aud.encoding
    print 'Rate: %i' % aud.rate
    print 'Channels: %i' % aud.ch
    print 'Speaker: %s' % Speaker.objects.with_id(aud.speaker).name
    print 'Filename: %s' % aud.filename
    print 'Speaker Name: %s' % aud.speaker_name
    
    fname_out = self_extract(aud.data, aud.filename+'.'+aud.encoding)
    sfile = audio.Sndfile(fname_out, 'r')
    sndvec = sfile.read_frames(aud.frames)
        
    audio.play(sndvec, aud.rate)  
Beispiel #14
0
 def PlayKosAlertSound(self):
   global winsound
   if winsound:
     try:
       winsound.PlaySound("SystemQuestion", winsound.SND_ALIAS)
     except:
       # such as when there's no SystemQuestion sound, reported by some users.
       winsound = False
   elif play and options.sound_file:
     data = None
     if options.sound_file.endswith("ogg"):
       data, fs, _ = oggread(options.sound_file)
     elif options.sound_file.endswith("wav"):
       data, fs, _ = wavread(options.sound_file)
     if data is not None:
       play(data.T, fs)
Beispiel #15
0
def correlate():
    ccipca = CCIPCAProcessor((8193, 200), plot=False, amnesia=1.0)
    ccipca.ccipca = CCIPCA(divisi2.load('chess.eigs'))
    ccipca.ccipca.iteration = 100000
    ccipca.output_ccipca = ccipca.ccipca
    pipe = ronwtools.Pipeline(
        ronwtools.AudioSource('../chess.ogg'),
        ronwtools.Mono(),
        ronwtools.STFT(nfft=16384, nhop=4096, winfun=np.hanning),
        ccipca,
        ronwtools.ISTFT(nfft=16384, nhop=4096, winfun=np.hanning),
        ronwtools.Framer(1048576)
    )
    for segment in pipe:
        print np.max(segment)
        segment /= np.max(segment)
        audiolab.play(segment)
Beispiel #16
0
def play_rand(file, name):
    sound = audiolab.sndfile(file)
    limit = sound.get_nframes()
    frames = sound.read_frames(sound.get_nframes()) * 0.8
    if limit < size: return
    for i in range(5):
        start = random.randint(0, limit - size)
        print("Is this a voice? [(y)es, (n)o, " +
              "(s)kip/significant-portions-of-both/can't-tell, (r)eplay]")
        audiolab.play(frames[start:start + size][:, 0])
        while True:
            input = raw_input()
            if input == "r":
                audiolab.play(frames[start:start + size][:, 0])
            elif input in ["y", "n", "s"]:
                break
        print >> outfile, name, start, start + size, input
Beispiel #17
0
def play_rand(file, name):
    sound = audiolab.sndfile(file)
    limit = sound.get_nframes()
    frames = sound.read_frames(sound.get_nframes()) * 0.8
    if limit < size: return
    for i in range(5):
        start = random.randint(0, limit - size)
        print("Is this a voice? [(y)es, (n)o, " +
            "(s)kip/significant-portions-of-both/can't-tell, (r)eplay]")
        audiolab.play(frames[start: start + size][:,0])
        while True:
            input = raw_input()
            if input == "r":
                audiolab.play(frames[start: start + size][:,0])
            elif input in ["y", "n", "s"]:
                break
        print >> outfile, name, start, start + size, input
Beispiel #18
0
 def play(self,start="0m0s",end="0m0s"):
     sm = ss = m = s = 0
     if 'm' in start:
         sm = int(start[:start.find('m')])
     if 'm' in end:
         m = int(end[:end.find('m')])
     if 's' in end:
         s = int(end[end.find('m')+1:end.find('s')])
     if 's' in start:
         ss = int(start[start.find('m')+1:start.find('s')])
     frames = (m*60+s)*self.freq
     sf = (sm*60+ss)*self.freq
     if frames>self.frames or frames==0:
         frames = self.frames
     if sf > self.frames:
         sf = 0
     aulab.play(self.data[sf:frames],fs=self.freq)
Beispiel #19
0
def test_callback(samples, rtlsdr_obj):
    #print(samples)
    mpl.clf()
    #dataset.extend(samples)
    x = samples
    yb1 = signal.convolve(x, filterB1)
    #mpl.psd(yb1, NFFT=1024, Fc=0, Fs=48e3)
    yn1 = downsample(yb1, 10)
    #mpl.psd(yn1, NFFT=1024, Fc=0, Fs=sdr.rs/10)
    zdis = discrim(yn1)
    #mpl.psd(zdis, NFFT=1024, Fc=0, Fs=sdr.rs/10)

    zb2 = signal.convolve(zdis, filterB2)
    zn2 = downsample(zb2, 5)
    mpl.psd(x)
    mpl.psd(zn2, NFFT=1024, Fc=0, Fs=48e3)
    mpl.plot(zdis)
    mpl.pause(0.0001)
    mpl.show(block=False)
    zn2 /= npmax(abs(zn2),axis=0)
    # complex2wav("teste.wav",48e3,zn2)
    play(zn2, fs=48e3)
Beispiel #20
0
from scikits.audiolab import play, wavread

data, fs, enc = wavread('test.wav')
# There is a discrepency between wavread (one column per channel) and play
# convention (one row per channel). Audiolab will be fully converted to 'numpy
# conventions' (last axis per default) after version 0.9
play(data.T, fs)
Beispiel #21
0
 def _play(self,start=0,frames=0):
     if frames == 0:
         frames = self.frames
     aulab.play(self.data[start:frames],fs=self.freq)
Beispiel #22
0
def playwave(f, tf=1, timber=harmonic):
    """plays sine wave with frequency f and duration tf"""
    t = time_arr(tf, fs)
    y = timber(f, t)
    al.play(y, fs=fs)
Beispiel #23
0
 def start_music(conn, play_args):
     conn.send(None)
     conn.close()
     audiolab.play(*play_args)
Beispiel #24
0
# Encoding with matching pursuit
X = np.zeros((Y.shape[0], D_multi.shape[0]))
for idx in range(Y.shape[0]):
    X[idx, :] = matching_pursuit(Y[idx, :], D_multi)

# Reconstruction of the signal
out = np.zeros(int((np.ceil(len(y) / resolution) + 1) * resolution))
for k in range(0, len(X)):
    idx = range(k * (resolution - overlap),
                k * (resolution - overlap) + resolution)
    out[idx] += np.dot(X[k], D_multi)
squared_error = np.sum((y - out[0:len(y)])**2)

# Play the original signal and the reconstructed for comparison
play(y, fs=16000)
play(out, fs=16000)

# Plotting results

# 1st plot: original signal/reconstructed signal/residuals
arr = np.array(range(length_sound)) / float(fs)
plt.figure(1)
plt.subplot(311)
plt.plot(arr, y, 'b', label="Input Signal")
plt.legend()
plt.subplot(312)
plt.plot(arr, out[0:len(y)], 'r', label="Recontruction")
plt.legend()
plt.subplot(313)
plt.plot(arr, (y - out[0:len(y)])**2, 'g', label="Residual")
Beispiel #25
0
import numpy as np
from scikits.audiolab import play

# output one second of stereo gaussian white noise at 48000 hz
play(0.05 * np.random.randn(2, 48000))
Beispiel #26
0
 def play(self, norm=True):
     if norm:
         samples = normrange(self.samples)
     else:
         samples = self.samples
     AL.play(samples, self.samplerate)
 def play(self):
     play(self.signal, fs=self.samplerate)
Beispiel #28
0
y,fstmp,fmt = audiolab.wavread('glockenspiel.wav')
#y = np.sum(y,1)/y.shape[1] # make mono
y = samplerate.resample(y, fs/fstmp,'sinc_best') # resample for faster computation

# setup
scales = [256,512,1024,2048, 4096] # window sizes to use
L = np.ceil(len(y)/float(np.max(scales)))*np.max(scales) # calc block boundary
y = np.hstack((y,np.zeros(L-len(y)))) # pad input to block boundary

# Build multi-scale Gabor dictionary
D = DictionaryUnion(*[GaborBlock(L,s) for s in scales])

# Analysis (basis pursuit denoising: min ||x||_1 s.t. ||y-Dx||_2<e)
x = BPDN(D,y,maxerr=1e-12,maxits=1000)

# Plots
parts = D.parts(x)

for i,p in enumerate(parts):
    pylab.figure()
    freqsup = range(0,D[i].fftLen/2+1)
    pylab.imshow(20*np.log10(np.abs(p[:,freqsup].transpose())), aspect='auto', interpolation='bilinear', origin='lower')

# Sounds
synth = [np.array(samplerate.resample(np.real(D[i].dot(p)), fstmp/fs, 'sinc_best'), dtype='float64') for i,p in enumerate(parts)]

for s in synth:
    audiolab.play(s)

pylab.show()
Beispiel #29
0
def play_audio():
    for dtype, inverted_vocab in get_inverse_vocabs().iteritems():
        if dtype != TIMBRE_GROUP:
            continue
        for i, vec in enumerate(inverted_vocab):
            play(gen_timbre(vec))
Beispiel #30
0
# extract and print the number of channels
nc = f.channels
print "number of channels: ", nc

# extract and print the encoding format
enc = f.encoding
print "encoding format: ", enc

# extract the number of frames - single samples for
# mono and pairs of samples for stereo
num_samples = f.nframes

#################################################
######## READ AUDIO SAMPLES FROM THE FILE #######
#################################################

# we can read audio samples using the read_frame method
samples = f.read_frames(num_samples)

#################################################
############# PLAYING AN AUDIO FILE #############
#################################################

# play the audio file data in 'samples' at the sampling frequency 'fs'
play(samples, fs)

#################################################
#################################################
#################################################
Beispiel #31
0
 def play(self):
     audiolab.play(self.signal.T)
#wname = mktemp('.wav')

#print(wname)

#check_call(['avconv', '-i', flacfile, wname])
#sig, fs, enc = flacread(wname)
sig, fs, enc = flacread(flacfile)

#os.unlink(wname)

# bandpass filter
bands = np.array([0, 3500, 4000, 5500, 6000, fs / 2.0]) / fs
desired = [0, 1, 0]
b = remez(513, bands, desired)
sig_filt = lfilter(b, 1, sig)
sig_filt /= 1.05 * max(abs(sig_filt))  # normalize

subplot(211)
specgram(sig, Fs=fs, NFFT=1024, noverlap=0)
axis('tight')
axis(ymax=8000)
title('Original')
subplot(212)
specgram(sig_filt, Fs=fs, NFFT=1024, noverlap=0)
axis('tight')
axis(ymax=8000)
title('Filtered')
show()

play(sig_filt, fs)
Beispiel #33
0
def play_segment(segment):
    audiolab.play(segment["raw"].mean(axis=1))
Beispiel #34
0
    def play(self, example):
        sound = audiolab.sndfile(self.base + example.file)
        frames = sound.read_frames(sound.get_nframes()) * 0.8

        audiolab.play(frames[example.start:example.stop][:, 0])
Beispiel #35
0
    contours2 = cv2.findContours(mask2.copy(), cv2.RETR_EXTERNAL,
                                 cv2.CHAIN_APPROX_SIMPLE)[-2]
    note, note2 = np.array([]), np.array([])
    if len(contours) > 0:
        c1 = max(contours, key=cv2.contourArea)
        if cv2.contourArea(c1) > MIN_OBJECT_AREA:
            m = cv2.moments(c1)
            center = (int(m['m10'] / m['m00']), int(m['m01'] / m['m00']))
            center_x = center[0]
            note = pick_note(center_x, t, FRAME_SPLIT)
    if len(contours2) > 0:
        c2 = max(contours2, key=cv2.contourArea)
        if cv2.contourArea(c2) > MIN_OBJECT_AREA:
            m = cv2.moments(c2)
            center = (int(m['m10'] / m['m00']), int(m['m01'] / m['m00']))
            center_x = center[0]
            note2 = pick_note(center_x, t, FRAME_SPLIT)
    if note.size and note2.size:
        audiolab.play(note + note2)
    elif note.size:
        audiolab.play(note)
    elif note2.size:
        audiolab.play(note2)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    cv2.imshow('image2', mask)
    # When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
 def play(self):
     au.play(
         self.data.astype(float) / self.data.max(),
         fs=self.params['sample_rate'])
Beispiel #37
0
 def play(self, speed_scale=None):
     if speed_scale is not None:
         fs = self.samplerate * speed_scale
     else:
         fs = self.samplerate
     audiolab.play(self.waveform, fs)
Beispiel #38
0
 def play(self):
     play(self.signal, fs=self.samplerate)
Beispiel #39
0
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    mask = cv2.inRange(hsv, lower, upper)
    mask = cv2.erode(mask, None, iterations=2)
    mask = cv2.dilate(mask, None, iterations=2)

    contours = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
                                cv2.CHAIN_APPROX_SIMPLE)[-2]

    if len(contours) > 0:
        c1 = max(contours, key=cv2.contourArea)
        m = cv2.moments(c1)
        center = (int(m['m10'] / m['m00']), int(m['m01'] / m['m00']))
        center_x = center[0]
        if center_x < FRAME_SPLIT:
            audiolab.play(a)
        elif center_x < FRAME_SPLIT * 2:
            audiolab.play(g)
        elif center_x < FRAME_SPLIT * 3:
            audiolab.play(e)
        elif center_x < FRAME_SPLIT * 4:
            audiolab.play(d)
        elif center_x < FRAME_SPLIT * 5:
            audiolab.play(c)
    if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cv2.imshow('image2', mask)
        # When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
Beispiel #40
0
        [-12, 59.0207, 0.0501209, 0.000840648, 5.48635, 2554.66, 503.88, 0.79761, 1.83648, 1.58787, 1.03476, 0.896911, 0.996907, 1.24554, 0.845971, 0.148589],
        [-12, 61.0691, -0.0588209, -0.00162663, 5.50909, 2433.82, 496.385, 0.801913, 1.90018, 1.45739, 0.653615, 1.00535, 1.29864, 1.52989, 0.585408, 0.104115],
        [-12, 58.398, 0.0678559, 0.00801878, 5.49513, 2584.1, 503.088, 0.798411, 1.90384, 1.44329, 0.612329, 1.01709, 1.30643, 1.5384, 0.560051, 0.102344],
        [-12, 58.1282, -0.0770835, 0.0391217, 5.49927, 2374.82, 497.716, 0.801403, 1.88149, 1.43979, 0.625468, 1.01567, 1.28775, 1.51369, 0.586579, 0.0976503],
        [-12, 43.657, 0.0862755, 0.201883, 5.52524, 2865.47, 501.169, 0.798652, 1.75618, 1.45495, 0.770813, 0.987832, 1.03016, 1.25533, 0.740417, 0.102236],
        [-12, 10.3548, -0.0950456, 0.680794, 5.79356, 5315.03, 500.314, 0.801417, 1.40392, 1.48089, 1.14573, 0.919835, 0.385726, 0.587562, 1.20079, 0.0979321],
        [-12, -0.394881, 0.102688, 0.780489, 5.79459, 5594.09, 497.703, 0.798394, 1.31567, 1.48965, 1.24365, 0.900246, 0.203358, 0.406455, 1.2852, 0.101868],
        [-12, 1.30799, -0.107779, 0.822941, 5.81101, 5389.04, 505.148, 0.80191, 1.31808, 1.49677, 1.26002, 0.900181, 0.215266, 0.413344, 1.2873, 0.0983526],
        [-12, -1.52704, 0.107008, 0.668792, 5.77274, 5679.06, 489.624, 0.797668, 1.34557, 1.53307, 1.32862, 0.8885, 0.221463, 0.42741, 0.784301, 0.101409],
        [-12, 2.02356, -0.090766, -0.0265786, 6.19917, 4187.48, 575.678, 0.802868, 1.42662, 1.62262, 1.48196, 0.874043, 0.302706, 0.511677, 0.0893865, 0.0988436],
        [-12, -3.41672, 0.0162316, 0.0680242, 7.12928, 1914.69, 707.314, 0.796474, 1.50667, 1.71846, 1.65847, 0.846687, 0.354325, 0.575671, 0.140095, 0.100891],
        [-12, 16.0217, 2.36331, 0.151462, 6.2577, 2295.98, 614.831, 0.80431, 1.60145, 1.8245, 1.8373, 0.832248, 0.444953, 0.671848, 0.664881, 0.0993871],
        [-12, 55.8366, 0.591923, -0.02722, 5.34712, 2513.69, 460.645, 0.794764, 1.64483, 1.87722, 1.94201, 0.80983, 0.469025, 0.701948, 1.36649, 0.100323],
        [-12, 58.5214, -0.448925, 0.013885, 5.60332, 2498.36, 539.471, 0.806323, 1.6737, 1.90901, 1.98537, 0.817279, 0.501886, 0.740232, 1.45146, 0.0999809],
        [-12, 59.9655, 0.438486, -0.00911093, 5.40836, 2497.41, 452.571, 0.792391, 1.64345, 1.88704, 1.97305, 0.810446, 0.454063, 0.720752, 1.4588, 0.0996983],
        [-12, 49.3266, -0.465215, 0.00669799, 5.59228, 2506.42, 562.858, 0.809152, 1.60705, 1.87666, 1.96538, 0.849748, 0.391025, 0.759315, 1.30988, 0.100646],
        [-12, 18.1282, 0.520405, -0.00501896, 5.39967, 2488.55, 406.339, 0.78894, 1.4451, 1.77875, 1.89589, 0.887862, 0.141397, 0.75315, 1.01718, 0.0989738],
        [-12, 2.22709, -0.615666, 0.0025473, 5.64094, 2518.53, 1187.9, 0.813524, 1.40047, 1.77117, 1.89445, 0.943704, 0.0548771, 0.806182, 0.839183, 0.101466],
        [-12, 0.733967, 0.793145, 0.0172693, 5.45811, 2471.1, 2316.01, 0.78307, 1.34412, 1.72004, 1.85292, 0.921577, -0.00849037, 0.762973, 0.802398, 0.0979881],
        [-12, -0.201343, -1.21956, 0.164671, 5.77113, 2545.27, 2798.41, 0.822155, 1.35851, 1.7255, 1.83304, 0.951667, 0.0887088, 0.849571, 0.742676, 0.102774],
        [-12, 0.0790298, 4.48401, 0.144665, 5.31437, 2424.68, 1322.22, 0.768336, 1.22142, 1.53669, 1.60628, 0.870119, 0.188809, 0.836472, 0.620848, 0.0959391]
        ])
    w = numpy.array(f)
    w /= abs(w).max()
    play(w, 22050)

    for target in 'music oi'.split():
        print 'synthesizing %s.gnuspeech' % target
        lmj.trm.synthesize(target + '.gnuspeech', target + '.wav')
        subprocess.call(['aplay', target + '.wav'])
from scikits.audiolab import wavread
from scikits.audiolab import play

# specify a file name
filename = "viola.wav"

# extract audio from file
samples, fs, enc = wavread(filename)     

# print out the first 50 samples
print samples[0:50]


#################################################
############# PLAYING AN AUDIO FILE #############
#################################################

# play the audio file data in 'data' at 44100Hz
play(samples,fs=44100)


#################################################
#################################################
#################################################
Beispiel #42
0
	def playSound(self):

		al.play(self._ramped(self.s2, self.fs), self.fs)
overtones = [2,3,4,5,6,7,8]
overamps = [0.08,0.05,0.01,0.005,0.001,0.0001,0.00001]

tune = np.zeros((2,len(melody)*(samples)))

for j in range(len(melody)):
	tone = melody[j]
	f_sin = NOTES[tone]
	ground = np.sin(f_sin/f_sample*np.arange(samples))
	sig = ground
	for i in np.arange(len(overtones)):
		n = overtones[i]
		relamp = overamps[i]
		overtone = relamp*np.sin(f_sin*n/f_sample*np.arange(samples))
		sig = np.add(sig,overtone)
	sig = amplitude*np.multiply(sig,tone_shape)

	tstart = j*samples
	tstop = (j+1)*samples
	tune[0,tstart:tstop] = sig
	tune[1,tstart:tstop] = sig

print f_sample
print len(tune[0])/len(melody)

#plt.plot(tune[0])
#plt.show()

al.play(tune[0],f_sample)
Beispiel #44
0
 def play(self, index):
     if index < 0:
         self.train.mixdown()
         al.play(self.train.sound.wav, self.train.sound.rate)
     else:
         al.play(self.sounds[index].wav, self.sounds[index].rate)
Beispiel #45
0
def play(f, fs):
    """TODO: filter high frequencies or raise error when f > 800 Hz"""
    # if spectrum(f)
    return al.play(f, fs)
Beispiel #46
0
#!/usr/bin/env python

from utils import imfcc
import numpy as np
from scikits.audiolab import wavwrite, play

CLUSTER_FILE = '../old_data/kmeans/clusters_rand_5000.txt'
PLAYING = False

clusters = np.loadtxt(CLUSTER_FILE)[:, 1:]


for cluster in clusters:
    x = np.tile(cluster, (51, 1))
    y = imfcc(x, has_power=False)
    if PLAYING:
        play(y, fs=44100)
    else:
        wavwrite(y, 'test.wav', fs=44100, enc='pcm16')
        break
Beispiel #47
0
import numpy as np
from scikits.audiolab import play
# output one second of stereo gaussian white noise at 48000 hz
data = np.random.randn(2, 480000)
play(0.001 * data)
    
Beispiel #48
0
 def play(self, norm=True):
     if norm:
         samples = normrange(self.samples)
     else:
         samples = self.samples
     AL.play(samples, self.samplerate)