Example #1
0
 def writeToAudioFile(self, filename, enc='float32'):
     if ".wav" in filename:
         wavwrite(self.data, filename, self.fs, enc)
     elif ".aiff" in filename:
         aiffwrite(self.data, filename, self.fs, enc)
     else: 
         raise TypeError("File extension not .wav or .aiff")
Example #2
0
from tempfile import mkstemp
from os.path import join, dirname
from os import remove

from audiolab import wavread, wavwrite

(tmp, fs, enc) = wavread('test.wav')
if tmp.ndim < 2:
    nc = 1
else:
    nc = tmp.shape[1]

print "The file has %d frames, %d channel(s)" % (tmp.shape[0], nc)
print "FS is %f, encoding is %s" % (fs, enc)

fd, cfilename = mkstemp('pysndfiletest.wav')
try:
    wavwrite(tmp, cfilename, fs=16000, enc='pcm24')
finally:
    remove(cfilename)
Example #3
0
db = ['/Users/grahamboyes/Desktop/taggedsounds/machine']

xs, fs, p = audiolab.wavread(target)
vecs = (xs[0:, 0], xs[0:, 1])

S = pydbm.data.SoundDatabase(db)

#if there is a transient model somewhere
n = S.sdif2array('/Users/grahamboyes/Desktop/AMEN_stereo.mrk.sdif', ['XTRD'])['XTRD']
n = (n['time'] * fs).astype(int)

D = pydbm.dictionary.SoundgrainDictionary(fs, S)

for i in xrange(len(db)):
    D.addCorpus(n, i)

v = []

for ind, x in enumerate(vecs):
    x_ = np.zeros(len(x) + max(D.atoms['duration']))
    x_[0:len(x)] = x
    mod, res, M = D.mp(x_.copy(), 300, 35)
    v.append(mod)

out = np.zeros((len(x), 2))
out[0:, 0] = v[0][0:len(x)]
out[0:, 1] = v[1][0:len(x)]

audiolab.wavwrite(out, '%s/model.wav'%outdir, fs)

Example #4
0
import pydbm.data 
import pydbm.dictionary
import pydbm.book

import audiolab
import numpy as np

x, fs, p = audiolab.wavread('/Users/grahamboyes/Documents/Work/project_m/harm_fof.wav')

list_of_corpora = ['/Users/grahamboyes/Documents/Work/project_m/16khz/ordinario/SoftMallet/forte', '/Users/grahamboyes/Documents/Work/project_m/16khz/ordinario/SoftMallet/piano']
S = pydbm.data.SoundDatabase(list_of_corpora)

D = pydbm.dictionary.SoundgrainDictionary(16000, S)
D.addCorpus(np.array([512, 1024, 2048, 4096]), 0)
D.addCorpus(np.array([512, 1024, 2048, 4096]), 1)

x_ = np.zeros(len(x) + max(D.atoms['duration']))
x_[0:len(x)] = x

mod, res, B = D.mp(x_.copy(), 30, 10)
audiolab.wavwrite(mod, '/Users/grahamboyes/Desktop/prawnprollip.wav', fs)

sout = '/Users/grahamboyes/Desktop/testDIF.sdif'
B.writeSDIF(sout)

out = B.synthesize()
audiolab.wavwrite(out, '/Users/grahamboyes/Desktop/prawnprollipsynth.wav', fs)
Example #5
0
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 18 13:00:45 2020

@author: Gulshan Rana
"""

import audiolab, scipy
a, fs, enc = audiolab.wavread('audio1.wav')
b, fs, enc = audiolab.wavread('beep.wav')
c = scipy.vstack((a,b))
audiolab.wavwrite(c, 'ab.wav', fs, enc)

d, fs, enc = audiolab.wavread('ab.wav')
e, fs, enc = audiolab.wavread('ab.wav')

f = scipy.vstack((d,e))
audiolab.wavwrite(f, 'finaud1.wav', fs, enc)
Example #6
0
x, fs, p = audiolab.wavread('../sounds/harm_fof.wav')
sdif = '/Users/grahamboyes/Documents/Work/project_m/harm_fof_shape.sdif'

list_of_corpora = ['/Users/grahamboyes/Documents/Work/sound_corpora/16k/ModernGrand/AF/ordinario_velshort/chromatic']

#Y = pydbm.data.PolygonGroup(sdif)
S = pydbm.data.SoundDatabase(list_of_corpora)

D = pydbm.dictionary.SoundgrainDictionary(fs, S)

#for y in Y.polygons:
#    D.addPolygon(x.copy(), 1024, y, 2048, 256, 6)

n = S.sdif2array('/Users/grahamboyes/Desktop/ballard.mrk.sdif', ['XTRD'])['XTRD']
n = (n['time'] * fs).astype(int)


n = np.array([0, 1000, 2000, 4000, 8000, 16000, 17000, 18000, 20000, 24000]) 
D.addCorpus(n, 0)

x_ = np.zeros(len(x) + max(D.atoms['duration']))
x_[0:len(x)] = x

#global scalar
g = max(abs(x_)) * 0.05

mod, res, M = D.mp2(x_.copy(), 100, 35, g)
#mod, res, M = D.mp(x_.copy(), 100, 35)
audiolab.wavwrite(mod[0:len(x)], '/Users/grahamboyes/Desktop/norescaleMP.wav', fs)
Example #7
0
import audiolab
import pydbm.dictionary
import pydbm.data
import numpy as np


target = '/Users/grahamboyes/Desktop/AMENS/AMEN.wav'
db = ['']
outdir = '/Users/grahamboyes/Desktop'

#a decomposition using the outdir                                                                                                                 
x, fs, p = audiolab.wavread(target)

S = pydbm.data.SoundDatabase(db)

#if there is a transient model somewhere
n = S.sdif2array('/Users/grahamboyes/Desktop/AMEN.mrk.sdif', ['XTRD'])['XTRD']
n = (n['time'] * fs).astype(int)

D = pydbm.dictionary.SoundgrainDictionary(fs, S)

for i in xrange(len(db)):
    D.addCorpus(n, i)

x_ = np.zeros(len(x) + max(D.atoms['duration']))
x_[0:len(x)] = x

mod, res, M = D.mp(x_.copy(), 300, 35)
audiolab.wavwrite(mod[0:len(x)], '%s/model.wav'%outdir, fs)

Example #8
0
import pydbm.dictionary
import numpy as np
import numpy.lib.recfunctions as rfn
import matplotlib.pyplot as plt
import audiolab

x, fs, p = audiolab.wavread('/Users/grahamboyes/Desktop/VibesMedium_7100-80.wav')

D = pydbm.dictionary.Dictionary(fs)
S = pydbm.dictionary.SpecDictionary(fs)

dtype = 'hann'
dur = 4096
hop = 128
tmin = 0
tmax = len(x)-dur 
winargs = {}

D.addSTFT(dtype, dur, 128, tmin, tmax, **winargs)
D.index()

#dtype, midicents, scales, onsets, **kwargs)
#S.addSTFT(dtype, dur, 128, tmin, tmax, **winargs)
S.addNote(dtype, 7100, [dur, 1024], [np.arange(0, tmax, hop), np.arange(0, len(x)-1024, hop/2)], **winargs)
S.index()

#signal, cmax, srr_thresh, tolmidicents, maxPeaks, dBthresh, overspec

model, res, sBook = S.mp(x.copy(), 1000, 35., 10000, 5, -80.0, 1)
audiolab.wavwrite(model, '/Users/grahamboyes/Desktop/VibesMedium_7100-80_mod.wav', fs)
Example #9
0
import audiolab

import pysdif
import scipy.fftpack as fftpack
import scipy.signal as sig

sdif_in = '/Users/grahamboyes/Documents/Work/project_m/harm_fof_shape_poly.sdif'
x, fs, p = audiolab.wavread('/Users/grahamboyes/Documents/Work/project_m/harm_fof.wav')

S = pydbm.data.PolygonGroup(sdif_in)

s1 = S.polygons[1]

p = s1.getPolyHull(16000, 128, 2048)

plt.scatter(s1.polyHull['hop'], s1.polyHull['bin'])
plt.hold(True)
plt.scatter(s1.tfPoints['hop'], s1.tfPoints['bin'], c='r')

D = pydbm.dictionary.Dictionary(fs)

ps = [(1024, 2048, 128), (256, 512, 64), (512, 4096, 128)]
kwargs = {}

for ls in ps:

    D.addPolygon(s1, 'hann', *ls, **kwargs)

mod, res, book = D.mp(x.copy(), 100, 35)
audiolab.wavwrite(mod, '/Users/grahamboyes/Desktop/foo.wav', fs)
Example #10
0
I = sig.lfilter([1.], coefs, imp)

F = fftpack.fft(I)
Fe = np.real(F)

p = 2*np.pi * np.random.random_sample(len(Fe)) - np.pi

out = np.real(fftpack.ifft(Fe + 1j*p))


plt.figure(0)
plt.plot(20*np.log10(abs(fftpack.fft(I))/len(I))[0:len(I)/2])
plt.show()

#out = sig.fftconvolve(out, h)

out /= max(abs(out))
out *= 0.8

audiolab.wavwrite(out, '/Users/grahamboyes/Desktop/weoruy.wav', fs)
plt.figure(1)
plt.plot(out)


#plt.figure(1)
#plt.colorbar()

#plt.xlabel('time (s)')
#plt.ylabel('frequency (Hz)')
Example #11
0
from tempfile import mkstemp
from os.path import join, dirname
from os import remove

from audiolab import wavread, wavwrite

(tmp, fs, enc)  = wavread('test.wav')
if tmp.ndim < 2:
    nc  = 1
else:
    nc  = tmp.shape[1]

print "The file has %d frames, %d channel(s)" % (tmp.shape[0], nc)
print "FS is %f, encoding is %s" % (fs, enc)

fd, cfilename   = mkstemp('pysndfiletest.wav')
try:
    wavwrite(tmp, cfilename, fs = 16000, enc = 'pcm24')
finally:
    remove(cfilename)
Example #12
0
    i = sig.lfilter([1.], coefs, imp)
    I = fftpack.fft(i, k*4)
    Ir = np.real(I)
    #p = 2*np.pi * np.random.random_sample(w) - np.pi
    p = np.imag(I)
    grain = H.window(w*4) * np.real(fftpack.ifft(Ir + 1j*p, k*4)) 
    out[pin:pin+w*4] += grain
    pin += hop
    

#h = np.random.randn(size) #* sig.lfilter([0.5, 0.7] , 1 ,np.random.randn(size))
#out = H.window(size) * sig.lfilter([1.], coefs, h)

#I = sig.lfilter([1.], coefs, imp)


plt.figure(0)
plt.plot(20*np.log10(abs(I)/len(I))[0:len(I)/2])
plt.show()

#out = sig.fftconvolve(out, h)

out /= max(abs(out))
out *= 0.8

audiolab.wavwrite(out, '/Users/grahamboyes/Desktop/wumpscut.wav', fs)
plt.figure(1)
plt.plot(out)


Example #13
0
                bits.append(0)
        return bits

    def get_message(fsk):
        message = ""
        for i in range(0, len(fsk), 10):
            current_byte = (fsk[i:i + 10])[1:9]  # Get the middle 8 bits
            pow = [2**j for j in range(8)]  # Get powers of 2 for total bits
            ascii = np.dot(current_byte, pow)  # Get the ascii value
            message += chr(ascii)  # Convert ascii to char
        return message

    print(get_message(get_FSK(mark_freq,
                              space_freq)))  # Print the hidden message

elif choice == 3:
    message_to_hide = str(
        input("Please enter the path of the encoded message to hide: "))
    file_to_hide_in = str(
        input("Please enter the name of the file to hide the message in: "))
    a, fs, enc = audiolab.wavread(message_to_hide)
    b, fs, enc = audiolab.wavread(file_to_hide_in)
    c = scipy.vstack((a, b))
    audiolab.wavwrite(c, 'hidden.wav', fs, enc)
    print("New file saved as 'hidden.wav'")

else:
    print("Your input is not correct!")

sys.exit()