本文整理汇总了Python中thinkdsp.read_wave函数的典型用法代码示例。如果您正苦于以下问题:Python read_wave函数的具体用法?Python read_wave怎么用?Python read_wave使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_wave函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: plot_response
def plot_response():
thinkplot.preplot(cols=2)
response = thinkdsp.read_wave("180961__kleeb__gunshots.wav")
response = response.segment(start=0.26, duration=5.0)
response.normalize()
response.plot()
thinkplot.config(xlabel="time", xlim=[0, 5.0], ylabel="amplitude", ylim=[-1.05, 1.05])
thinkplot.subplot(2)
transfer = response.make_spectrum()
transfer.plot()
thinkplot.config(xlabel="frequency", xlim=[0, 22500], ylabel="amplitude")
thinkplot.save(root="systems6")
wave = thinkdsp.read_wave("92002__jcveliz__violin-origional.wav")
wave.ys = wave.ys[: len(response)]
wave.normalize()
spectrum = wave.make_spectrum()
output = (spectrum * transfer).make_wave()
output.normalize()
wave.plot(color="0.7")
output.plot(alpha=0.4)
thinkplot.config(xlabel="time", xlim=[0, 5.0], ylabel="amplitude", ylim=[-1.05, 1.05])
thinkplot.save(root="systems7")
开发者ID:younlonglin,项目名称:ThinkDSP,代码行数:28,代码来源:systems.py
示例2: plot_bass
def plot_bass():
wave = thinkdsp.read_wave('328878__tzurkan__guitar-phrase-tzu.wav')
wave.normalize()
wave.plot()
wave.make_spectrum(full=True).plot()
sampled = sample(wave, 4)
sampled.make_spectrum(full=True).plot()
spectrum = sampled.make_spectrum(full=True)
boxcar = make_boxcar(spectrum, 4)
boxcar.plot()
filtered = (spectrum * boxcar).make_wave()
filtered.scale(4)
filtered.make_spectrum(full=True).plot()
plot_segments(wave, filtered)
diff = wave.ys - filtered.ys
#thinkplot.plot(diff)
np.mean(abs(diff))
sinc = boxcar.make_wave()
ys = np.roll(sinc.ys, 50)
thinkplot.plot(ys[:100])
开发者ID:vpillajr,项目名称:ThinkDSP,代码行数:29,代码来源:sampling.py
示例3: main
def main():
wave = thinkdsp.read_wave('328878__tzurkan__guitar-phrase-tzu.wav')
wave.normalize()
plot_sampling3(wave, 'sampling5')
plot_sincs(wave)
plot_beeps()
plot_am()
wave = thinkdsp.read_wave('263868__kevcio__amen-break-a-160-bpm.wav')
wave.normalize()
plot_impulses(wave)
plot_sampling(wave, 'sampling3')
plot_sampling2(wave, 'sampling4')
开发者ID:EricAtTCC,项目名称:ThinkDSP,代码行数:16,代码来源:sampling.py
示例4: plot_convolution
def plot_convolution():
response = thinkdsp.read_wave("180961__kleeb__gunshots.wav")
response = response.segment(start=0.26, duration=5.0)
response.normalize()
dt = 1
shift = dt * response.framerate
factor = 0.5
gun2 = response + shifted_scaled(response, shift, factor)
gun2.plot()
thinkplot.config(xlabel="time (s)", ylabel="amplitude", ylim=[-1.05, 1.05], legend=False)
thinkplot.save(root="systems8")
signal = thinkdsp.SawtoothSignal(freq=410)
wave = signal.make_wave(duration=0.1, framerate=response.framerate)
total = 0
for j, y in enumerate(wave.ys):
total += shifted_scaled(response, j, y)
total.normalize()
wave.make_spectrum().plot(high=500, color="0.7", label="original")
segment = total.segment(duration=0.2)
segment.make_spectrum().plot(high=1000, label="convolved")
thinkplot.config(xlabel="frequency (Hz)", ylabel="amplitude")
thinkplot.save(root="systems9")
开发者ID:younlonglin,项目名称:ThinkDSP,代码行数:28,代码来源:systems.py
示例5: __init__
def __init__(self,filename = "flesh_wound.wav", signal_type = "saw", pitch = 240, num_channel = 1024, num_band = 32):
self.num_bands = num_band
self.num_channels = num_channel
if filename == 'record':
chunk = 1024
self.framerate = 41000
self.pya = pyaudio.PyAudio() # initialize pyaudio
self.stream = self.pya.open(format = pyaudio.paInt16,
channels = 1,
rate = self.framerate,
input = True,
output = True,
frames_per_buffer = chunk)
data = get_samples_from_mic(self.framerate,300,chunk)
self.voice_wave = thinkdsp.Wave(data,self.framerate)
self.stream.close()
self.pya.terminate()
else:
self.voice_wave = thinkdsp.read_wave(filename) # read in recording
self.framerate= self.voice_wave.framerate # determine framerate
self.duration = self.voice_wave.duration # determine duration
self.voice_wave.normalize
self.signal_type = signal_type # list of the type of signals to generate
self.pitch = pitch # list of fundementals for the generated waves
seg_voi = self.segmentor(self.voice_wave)
self.sig_wave = self.Sig_generate()
seg_sig = self.segmentor(self.sig_wave)
voded_wave = self.vocode(seg_voi,seg_sig)
self.vocoded_wave = voded_wave
开发者ID:jabb1123,项目名称:Vocoder_project-SigSys,代码行数:35,代码来源:Vocoder.py
示例6: segment_violin
def segment_violin(start=1.2, duration=0.6):
wave = thinkdsp.read_wave('92002__jcveliz__violin-origional.wav')
# extract a segment
segment = wave.segment(start, duration)
segment.normalize()
segment.apodize()
segment.write('violin_segment1.wav')
# plot the spectrum
spectrum = segment.make_spectrum()
n = len(spectrum.hs)
spectrum.plot(high=n/2)
thinkplot.Save(root='violin2',
xlabel='frequency (Hz)',
ylabel='amplitude density')
# print the top 5 peaks
peaks = spectrum.peaks()
for amp, freq in peaks[:10]:
print freq, amp
# compare the segments to a 440 Hz Triangle wave
note = thinkdsp.make_note(69, 0.6,
sig_cons=thinkdsp.TriangleSignal,
framerate=segment.framerate)
wfile = thinkdsp.WavFileWriter('violin_segment2.wav', note.framerate)
wfile.write(note)
wfile.write(segment)
wfile.write(note)
wfile.close()
开发者ID:ManickYoj,项目名称:ThinkDSP,代码行数:32,代码来源:violin.py
示例7: segment_violin
def segment_violin(start=1.2, duration=0.6):
"""Load a violin recording and plot its spectrum.
start: start time of the segment in seconds
duration: in seconds
"""
wave = thinkdsp.read_wave('92002__jcveliz__violin-origional.wav')
# extract a segment
segment = wave.segment(start, duration)
segment.normalize()
# plot the spectrum
spectrum = segment.make_spectrum()
thinkplot.preplot(1)
spectrum.plot(high=10000)
thinkplot.Save(root='sounds3',
xlabel='Frequency (Hz)',
ylabel='Amplitude',
formats=FORMATS,
legend=False)
# print the top 5 peaks
peaks = spectrum.peaks()
for amp, freq in peaks[:10]:
print(freq, amp)
开发者ID:kjcole,项目名称:ThinkDSP,代码行数:27,代码来源:sounds.py
示例8: segment_spectrum
def segment_spectrum(filename, start, duration=1.0):
"""Plots the spectrum of a segment of a WAV file.
Output file names are the given filename plus a suffix.
filename: string
start: start time in s
duration: segment length in s
"""
wave = thinkdsp.read_wave(filename)
plot_waveform(wave)
# extract a segment
segment = wave.segment(start, duration)
segment.ys = segment.ys[:1024]
print len(segment.ys)
segment.normalize()
segment.apodize()
spectrum = segment.make_spectrum()
segment.play()
# plot the spectrum
n = len(spectrum.hs)
spectrum.plot()
thinkplot.save(root=filename,
xlabel='frequency (Hz)',
ylabel='amplitude density')
开发者ID:antoniopessotti,项目名称:ThinkDSP,代码行数:30,代码来源:noise.py
示例9: violin_example
def violin_example(start=1.2, duration=0.6):
"""Demonstrates methods in the thinkdsp module.
"""
# read the violin recording
wave = thinkdsp.read_wave('92002__jcveliz__violin-origional.wav')
# extract a segment
segment = wave.segment(start, duration)
# make the spectrum
spectrum = segment.make_spectrum()
# apply a filter
spectrum.low_pass(600)
# invert the spectrum
filtered = spectrum.make_wave()
# prepare the original and filtered segments
filtered.normalize()
filtered.apodize()
segment.apodize()
# write the original and filtered segments to a file
filename = 'filtered.wav'
wfile = thinkdsp.WavFileWriter(filename, segment.framerate)
wfile.write(segment)
wfile.write(filtered)
wfile.close()
thinkdsp.play_wave(filename)
开发者ID:antoniopessotti,项目名称:ThinkDSP,代码行数:31,代码来源:example1.py
示例10: main
def main():
# make_figures()
wave = thinkdsp.read_wave('28042__bcjordan__voicedownbew.wav')
wave.unbias()
wave.normalize()
track_pitch(wave)
return
thinkplot.preplot(rows=1, cols=2)
plot_shifted(wave, 0.0003)
thinkplot.config(xlabel='time (s)',
ylabel='amplitude',
ylim=[-1, 1])
thinkplot.subplot(2)
plot_shifted(wave, 0.00225)
thinkplot.config(xlabel='time (s)',
ylim=[-1, 1])
thinkplot.save(root='autocorr3')
开发者ID:PMKeene,项目名称:ThinkDSP,代码行数:25,代码来源:autocorr.py
示例11: plot_amen2
def plot_amen2():
wave = thinkdsp.read_wave('263868__kevcio__amen-break-a-160-bpm.wav')
wave.normalize()
ax1 = thinkplot.preplot(6, rows=4)
wave.make_spectrum(full=True).plot(label='spectrum')
xlim = [-22050-250, 22050]
thinkplot.config(xlim=xlim, xticklabels='invisible')
ax2 = thinkplot.subplot(2)
impulses = make_impulses(wave, 4)
impulses.make_spectrum(full=True).plot(label='impulses')
thinkplot.config(xlim=xlim, xticklabels='invisible')
ax3 = thinkplot.subplot(3)
sampled = wave * impulses
spectrum = sampled.make_spectrum(full=True)
spectrum.plot(label='sampled')
thinkplot.config(xlim=xlim, xticklabels='invisible')
ax4 = thinkplot.subplot(4)
spectrum.low_pass(5512.5)
spectrum.plot(label='filtered')
thinkplot.config(xlim=xlim, xlabel='Frequency (Hz)')
thinkplot.save(root='sampling4',
formats=FORMATS)
开发者ID:vpillajr,项目名称:ThinkDSP,代码行数:27,代码来源:sampling.py
示例12: plot_beeps
def plot_beeps():
wave = thinkdsp.read_wave('253887__themusicalnomad__positive-beeps.wav')
wave.normalize()
thinkplot.preplot(3)
# top left
ax1 = plt.subplot2grid((4, 2), (0, 0), rowspan=2)
plt.setp(ax1.get_xticklabels(), visible=False)
wave.plot()
thinkplot.config(title='Input waves', legend=False)
# bottom left
imp_sig = thinkdsp.Impulses([0.01, 0.4, 0.8, 1.2],
amps=[1, 0.5, 0.25, 0.1])
impulses = imp_sig.make_wave(start=0, duration=1.3,
framerate=wave.framerate)
ax2 = plt.subplot2grid((4, 2), (2, 0), rowspan=2, sharex=ax1)
impulses.plot()
thinkplot.config(xlabel='Time (s)')
# center right
convolved = wave.convolve(impulses)
ax3 = plt.subplot2grid((4, 2), (1, 1), rowspan=2)
plt.title('Convolution')
convolved.plot()
thinkplot.config(xlabel='Time (s)')
thinkplot.save(root='sampling1',
formats=FORMATS,
legend=False)
开发者ID:vpillajr,项目名称:ThinkDSP,代码行数:34,代码来源:sampling.py
示例13: read_response
def read_response():
"""Reads the impulse response file and removes the initial silence.
"""
response = thinkdsp.read_wave('180960__kleeb__gunshot.wav')
start = 0.26
response = response.segment(start=start)
response.shift(-start)
response.normalize()
return response
开发者ID:AllenDowney,项目名称:ThinkDSP,代码行数:9,代码来源:systems.py
示例14: getSpectrum
def getSpectrum(start=0, duration=1, input_file="raw-epdf.wav", low_pass=22000, high_pass=20):
# read the recording
wave = thinkdsp.read_wave(input_file)
segment = wave.segment(start, duration)
spectrum = segment.make_spectrum()
spectrum.low_pass(low_pass)
spectrum.high_pass(high_pass)
return spectrum
开发者ID:nlintz,项目名称:ThinkDSP,代码行数:11,代码来源:helpers.py
示例15: violin_spectrogram
def violin_spectrogram():
"""Makes a spectrogram of a violin recording.
"""
wave = thinkdsp.read_wave("92002__jcveliz__violin-origional.wav")
seg_length = 2048
spectrogram = wave.make_spectrogram(seg_length)
spectrogram.plot(high=seg_length / 8)
# TODO: try imshow?
thinkplot.save("spectrogram1", xlabel="time (s)", ylabel="frequency (Hz)", formats=["pdf"])
开发者ID:quakig,项目名称:ThinkDSP,代码行数:12,代码来源:example3.py
示例16: vocode_audiofiles
def vocode_audiofiles(filepath_1, filepath_2, num_filters=20, chunk_size=1024):
"""
"Fuses" two audiofiles using the Vocoder-algorithm.
Note: If the length of the audiofiles differ, the longer file gets cut to the length of the shorter one.
If the framerate differs, the file with the lower framerate is converted to the higher one, using the average-algorithm.
# TODO: Implement what is described up there /\
:param filepath_1 (str): Path to a .wav file
:param filepath_2 (str): Path to a .wav file
:param num_filters (int: Amount of filters the vocoder uses
:param chunk_size (int): Size each chunk should have (debug)
:return: toolset.Wave
"""
assert isinstance(filepath_1, str) and isinstance(filepath_1, str), "Filepaths must be of type %s" % type(" ")
wave1 = toolset.to_wave(thinkdsp.read_wave(filepath_1))
wave2 = toolset.to_wave(thinkdsp.read_wave(filepath_2))
smaller_signal_length = min(wave1.length, wave2.length)
result = np.zeros(smaller_signal_length - (smaller_signal_length % chunk_size))
print "Starting to vocode two signals with length %i..." % smaller_signal_length
vocoder = vc.Vocoder(wave1.framerate, np.hamming, num_filters, chunk_size)
debug_num_chunks = len(result) / chunk_size - 1
debug_factor = 100.0 / debug_num_chunks
for i in range(len(result) / chunk_size - 1):
# Status update:
print "%g%% done, processing chunk no. %i out of %i " % (round(i * debug_factor, 2), i, debug_num_chunks)
# Start - und ende des momentanen Chunks berechnen:
start, end = i * chunk_size, (i + 1) * chunk_size
# Modulator- und Carrier-Chunk "herausschneiden":
modulator = toolset.Wave(wave1.ys[start:end], wave1.framerate)
carrier = toolset.Wave(wave2.ys[start:end], wave2.framerate)
# Vocoder-Effekt auf die beiden Signale Anwenden:
result[start:end] = vocoder.vocode(modulator, carrier)
print "~job's done~"
return toolset.Wave(result, wave1.framerate)
开发者ID:NSasquatch,项目名称:vocoder,代码行数:40,代码来源:main.py
示例17: plot_amen
def plot_amen():
wave = thinkdsp.read_wave('263868__kevcio__amen-break-a-160-bpm.wav')
wave.normalize()
ax1 = thinkplot.preplot(2, rows=2)
wave.make_spectrum(full=True).plot()
xlim = [-22050, 22050]
thinkplot.config(xlim=xlim, xticklabels='invisible')
ax2 = thinkplot.subplot(2, sharey=ax1)
sampled = sample(wave, 4)
sampled.make_spectrum(full=True).plot()
thinkplot.config(xlim=xlim, xlabel='Frequency (Hz)')
thinkplot.show()
return
开发者ID:vpillajr,项目名称:ThinkDSP,代码行数:17,代码来源:sampling.py
示例18: plot_correlate
def plot_correlate():
"""Plots the autocorrelation function computed by np.
"""
wave = thinkdsp.read_wave('28042__bcjordan__voicedownbew.wav')
wave.normalize()
segment = wave.segment(start=0.2, duration=0.01)
lags, corrs = autocorr(segment)
N = len(segment)
corrs2 = np.correlate(segment.ys, segment.ys, mode='same')
lags = np.arange(-N//2, N//2)
thinkplot.plot(lags, corrs2)
thinkplot.config(xlabel='Lag',
ylabel='Correlation',
xlim=[-N//2, N//2])
thinkplot.save(root='autocorr9')
开发者ID:AllenDowney,项目名称:ThinkDSP,代码行数:17,代码来源:autocorr.py
示例19: plot_tuning
def plot_tuning(start=7.0, duration=0.006835):
"""Plots three cycles of a tuning fork playing A4.
duration: float
"""
period = duration/3
freq = 1/period
print period, freq
wave = thinkdsp.read_wave('18871__zippi1__sound-bell-440hz.wav')
segment = wave.segment(start, duration)
segment.normalize()
segment.plot()
thinkplot.Save(root='tuning1',
xlabel='time (s)',
axis=[0, duration, -1.05, 1.05])
开发者ID:ManickYoj,项目名称:ThinkDSP,代码行数:18,代码来源:violin.py
示例20: plot_violin
def plot_violin(start=1.30245, duration=0.00683):
"""Plots three cycles of a violin playing A4.
duration: float
"""
period = duration/3
freq = 1/period
print freq
wave = thinkdsp.read_wave('92002__jcveliz__violin-origional.wav')
segment = wave.segment(start, duration)
segment.normalize()
segment.plot()
thinkplot.Save(root='violin1',
xlabel='time (s)',
axis=[0, duration, -1.05, 1.05])
开发者ID:ManickYoj,项目名称:ThinkDSP,代码行数:18,代码来源:violin.py
注:本文中的thinkdsp.read_wave函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论