timsainb / python_spectrograms_and_inversion Goto Github PK
View Code? Open in Web Editor NEWSpectrograms, MFCCs, and Inversion Demo in a jupyter notebook
Spectrograms, MFCCs, and Inversion Demo in a jupyter notebook
i got error ๐คข at that line
wav_spectrogram = pretty_spectrogram(data.astype('float64'), fft_size = fft_size,
step_size = step_size, log = True , thresh = spec_thresh)
TypeError Traceback (most recent call last)
in
1 wav_spectrogram = pretty_spectrogram(data.astype('float64'), fft_size = fft_size,
----> 2 step_size = step_size, log = True , thresh = spec_thresh)
in pretty_spectrogram(d, log, thresh, fft_size, step_size)
83 """
84 specgram = np.abs(stft(d, fftsize=fft_size, step=step_size, real=False,
---> 85 compute_onesided=True))
86
87 if log == True:
in stft(X, fftsize, step, mean_normalize, real, compute_onesided)
68 X -= X.mean()
69
---> 70 X = overlap(X, fftsize, step)
71
72 size = fftsize
in overlap(X, window_size, window_step)
41 valid = len(a) - ws
42 nw = (valid) // ss
---> 43 out = np.ndarray((nw,ws),dtype = a.dtype)
44
45 for i in xrange(nw):
TypeError: 'float' object cannot be interpreted as an integer
after runing mel_spec = make_mel(wav_spectrogram, mel_filter, shorten_factor = shorten_factor)
I tried to plot mel spectrogram but some errors happening as follows:
fig, ax = plt.subplots(nrows=1,ncols=1, figsize=(20,4))
cax = ax.matshow(mel_spec,
interpolation='nearest',
aspect='auto',
cmap=plt.cm.afmhot,
origin='lower')
fig.colorbar(cax)
plt.title('mel Spectrogram')
ValueError Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in post_execute()
147 def post_execute():
148 if matplotlib.is_interactive():
--> 149 draw_all()
150
151 # IPython >= 2
~/anaconda3/lib/python3.6/site-packages/matplotlib/_pylab_helpers.py in draw_all(cls, force)
134 for f_mgr in cls.get_all_fig_managers():
135 if force or f_mgr.canvas.figure.stale:
--> 136 f_mgr.canvas.draw_idle()
137
138 atexit.register(Gcf.destroy_all)
~/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py in draw_idle(self, *args, **kwargs)
2053 if not self._is_idle_drawing:
2054 with self._idle_draw_cntx():
-> 2055 self.draw(*args, **kwargs)
2056
2057 def draw_cursor(self, event):
~/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in draw(self)
431 # if toolbar:
432 # toolbar.set_cursor(cursors.WAIT)
--> 433 self.figure.draw(self.renderer)
434 # A GUI class may be need to update a window using this draw, so
435 # don't forget to call the superclass.
~/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py in draw(self, renderer)
1473
1474 mimage._draw_list_compositing_images(
-> 1475 renderer, self, artists, self.suppressComposite)
1476
1477 renderer.close_group('figure')
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
139 if not_composite or not has_images:
140 for a in artists:
--> 141 a.draw(renderer)
142 else:
143 # Composite any adjacent images together
~/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2605 renderer.stop_rasterizing()
2606
-> 2607 mimage._draw_list_compositing_images(renderer, self, artists)
2608
2609 renderer.close_group('axes')
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
139 if not_composite or not has_images:
140 for a in artists:
--> 141 a.draw(renderer)
142 else:
143 # Composite any adjacent images together
~/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in draw(self, renderer, *args, **kwargs)
591 else:
592 im, l, b, trans = self.make_image(
--> 593 renderer, renderer.get_image_magnification())
594 if im is not None:
595 renderer.draw_image(gc, l, b, im)
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in make_image(self, renderer, magnification, unsampled)
839 return self._make_image(
840 self._A, bbox, transformed_bbox, self.axes.bbox, magnification,
--> 841 unsampled=unsampled)
842
843 def _check_unsampled_image(self, renderer):
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)
436 self.get_resample(), 1.0,
437 self.get_filternorm() or 0.0,
--> 438 self.get_filterrad() or 0.0)
439
440 # we are done with A_scaled now, remove from namespace
ValueError: Unsupported dtype
ValueError Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/IPython/core/formatters.py in call(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)
~/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py in (fig)
239
240 if 'png' in formats:
--> 241 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
242 if 'retina' in formats or 'png2x' in formats:
243 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
~/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
123
124 bytes_io = BytesIO()
--> 125 fig.canvas.print_figure(bytes_io, **kw)
126 data = bytes_io.getvalue()
127 if fmt == 'svg':
~/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2210 orientation=orientation,
2211 dryrun=True,
-> 2212 **kwargs)
2213 renderer = self.figure._cachedRenderer
2214 bbox_inches = self.figure.get_tightbbox(renderer)
~/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
511
512 def print_png(self, filename_or_obj, *args, **kwargs):
--> 513 FigureCanvasAgg.draw(self)
514 renderer = self.get_renderer()
515 original_dpi = renderer.dpi
~/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in draw(self)
431 # if toolbar:
432 # toolbar.set_cursor(cursors.WAIT)
--> 433 self.figure.draw(self.renderer)
434 # A GUI class may be need to update a window using this draw, so
435 # don't forget to call the superclass.
~/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py in draw(self, renderer)
1473
1474 mimage._draw_list_compositing_images(
-> 1475 renderer, self, artists, self.suppressComposite)
1476
1477 renderer.close_group('figure')
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
139 if not_composite or not has_images:
140 for a in artists:
--> 141 a.draw(renderer)
142 else:
143 # Composite any adjacent images together
~/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2605 renderer.stop_rasterizing()
2606
-> 2607 mimage._draw_list_compositing_images(renderer, self, artists)
2608
2609 renderer.close_group('axes')
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
139 if not_composite or not has_images:
140 for a in artists:
--> 141 a.draw(renderer)
142 else:
143 # Composite any adjacent images together
~/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in draw(self, renderer, *args, **kwargs)
591 else:
592 im, l, b, trans = self.make_image(
--> 593 renderer, renderer.get_image_magnification())
594 if im is not None:
595 renderer.draw_image(gc, l, b, im)
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in make_image(self, renderer, magnification, unsampled)
839 return self._make_image(
840 self._A, bbox, transformed_bbox, self.axes.bbox, magnification,
--> 841 unsampled=unsampled)
842
843 def _check_unsampled_image(self, renderer):
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)
436 self.get_resample(), 1.0,
437 self.get_filternorm() or 0.0,
--> 438 self.get_filterrad() or 0.0)
439
440 # we are done with A_scaled now, remove from namespace
ValueError: Unsupported dtype
print (''.join(['mel Spectrogram Size: ',str(np.shape(mel_spec))]))
print (''.join(['Original Spectrogram Size: ',str(np.shape(np.transpose(wav_spectrogram)))]))
print (''.join(['Original Waveform Size: ',str(np.shape(data))]))
print (''.join(['Length (s): ', str(len(data)/float(rate))]))
print (''.join(['Original Sampling Rate (ms) : ', str(1./float(rate))]))
print (''.join(['New Sampling Rate (ms): ', str(float(np.shape(mel_spec)[1]) / (len(data)/float(rate)))]))
mel Spectrogram Size: (64, 153)
Original Spectrogram Size: (1024, 1552)
Original Waveform Size: (200542,)
Length (s): 4.547437641723356
Original Sampling Rate (ms) : 2.2675736961451248e-05
New Sampling Rate (ms): 33.64532117960328
mel_inverted_spectrogram = mel_to_spectrogram(mel_spec, mel_inversion_filter,
spec_thresh=spec_thresh,
shorten_factor=shorten_factor)
ValueError Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in post_execute()
147 def post_execute():
148 if matplotlib.is_interactive():
--> 149 draw_all()
150
151 # IPython >= 2
~/anaconda3/lib/python3.6/site-packages/matplotlib/_pylab_helpers.py in draw_all(cls, force)
134 for f_mgr in cls.get_all_fig_managers():
135 if force or f_mgr.canvas.figure.stale:
--> 136 f_mgr.canvas.draw_idle()
137
138 atexit.register(Gcf.destroy_all)
~/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py in draw_idle(self, *args, **kwargs)
2053 if not self._is_idle_drawing:
2054 with self._idle_draw_cntx():
-> 2055 self.draw(*args, **kwargs)
2056
2057 def draw_cursor(self, event):
~/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in draw(self)
431 # if toolbar:
432 # toolbar.set_cursor(cursors.WAIT)
--> 433 self.figure.draw(self.renderer)
434 # A GUI class may be need to update a window using this draw, so
435 # don't forget to call the superclass.
~/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py in draw(self, renderer)
1473
1474 mimage._draw_list_compositing_images(
-> 1475 renderer, self, artists, self.suppressComposite)
1476
1477 renderer.close_group('figure')
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
139 if not_composite or not has_images:
140 for a in artists:
--> 141 a.draw(renderer)
142 else:
143 # Composite any adjacent images together
~/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2605 renderer.stop_rasterizing()
2606
-> 2607 mimage._draw_list_compositing_images(renderer, self, artists)
2608
2609 renderer.close_group('axes')
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
139 if not_composite or not has_images:
140 for a in artists:
--> 141 a.draw(renderer)
142 else:
143 # Composite any adjacent images together
~/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in draw(self, renderer, *args, **kwargs)
591 else:
592 im, l, b, trans = self.make_image(
--> 593 renderer, renderer.get_image_magnification())
594 if im is not None:
595 renderer.draw_image(gc, l, b, im)
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in make_image(self, renderer, magnification, unsampled)
839 return self._make_image(
840 self._A, bbox, transformed_bbox, self.axes.bbox, magnification,
--> 841 unsampled=unsampled)
842
843 def _check_unsampled_image(self, renderer):
~/anaconda3/lib/python3.6/site-packages/matplotlib/image.py in _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)
436 self.get_resample(), 1.0,
437 self.get_filternorm() or 0.0,
--> 438 self.get_filterrad() or 0.0)
439
440 # we are done with A_scaled now, remove from namespace
ValueError: Unsupported dtype
Greetings @timsainb ,
is it posibble to run this github on python2.7 and not in Ipython ?
i try to converted it but unable to get the display output...
i appreciate for you to help a newbie like me
Hi Tim! vert useful and interesting job. Unfortunately I got an error.
I cloned the git, ran the example and, after step 13, i.e., after:
mel_spec = make_mel(wav_spectrogram, mel_filter, shorten_factor = shorten_factor)
got the following warning:
/usr/local/lib/python2.7/dist-packages/scipy/ndimage/interpolation.py:600: UserWarning: From scipy 0.13.0, the output shape of zoom() is calculated with round() instead of int() - for these inputs the size of the returned array has changed.
"the returned array has changed.", UserWarning)
then at the following step 14, i.e. after:
# plot the compressed spec
fig, ax = plt.subplots(nrows=1,ncols=1, figsize=(20,4))
cax = ax.matshow(mel_spec, interpolation='nearest', aspect='auto', cmap=plt.cm.afmhot, origin='lower')
fig.colorbar(cax)
plt.title('mel Spectrogram')
I got the following error message:
ValueError Traceback (most recent call last)
/usr/local/lib/python2.7/dist-packages/IPython/core/formatters.pyc in __call__(self, obj)
305 pass
306 else:
--> 307 return printer(obj)
308 # Finally look for special method names
309 method = get_real_method(obj, self.print_method)
/usr/local/lib/python2.7/dist-packages/IPython/core/pylabtools.pyc in <lambda>(fig)
238
239 if 'png' in formats:
--> 240 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
241 if 'retina' in formats or 'png2x' in formats:
242 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
/usr/local/lib/python2.7/dist-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)
122
123 bytes_io = BytesIO()
--> 124 fig.canvas.print_figure(bytes_io, **kw)
125 data = bytes_io.getvalue()
126 if fmt == 'svg':
/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2198 orientation=orientation,
2199 dryrun=True,
-> 2200 **kwargs)
2201 renderer = self.figure._cachedRenderer
2202 bbox_inches = self.figure.get_tightbbox(renderer)
/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
543
544 def print_png(self, filename_or_obj, *args, **kwargs):
--> 545 FigureCanvasAgg.draw(self)
546 renderer = self.get_renderer()
547 original_dpi = renderer.dpi
/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.pyc in draw(self)
462
463 try:
--> 464 self.figure.draw(self.renderer)
465 finally:
466 RendererAgg.lock.release()
/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
/usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in draw(self, renderer)
1142
1143 mimage._draw_list_compositing_images(
-> 1144 renderer, self, dsu, self.suppressComposite)
1145
1146 renderer.close_group('figure')
/usr/local/lib/python2.7/dist-packages/matplotlib/image.pyc in _draw_list_compositing_images(renderer, parent, dsu, suppress_composite)
137 if not_composite or not has_images:
138 for zorder, a in dsu:
--> 139 a.draw(renderer)
140 else:
141 # Composite any adjacent images together
/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in draw(self, renderer, inframe)
2424 renderer.stop_rasterizing()
2425
-> 2426 mimage._draw_list_compositing_images(renderer, self, dsu)
2427
2428 renderer.close_group('axes')
/usr/local/lib/python2.7/dist-packages/matplotlib/image.pyc in _draw_list_compositing_images(renderer, parent, dsu, suppress_composite)
137 if not_composite or not has_images:
138 for zorder, a in dsu:
--> 139 a.draw(renderer)
140 else:
141 # Composite any adjacent images together
/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
/usr/local/lib/python2.7/dist-packages/matplotlib/image.pyc in draw(self, renderer, *args, **kwargs)
541 else:
542 im, l, b, trans = self.make_image(
--> 543 renderer, renderer.get_image_magnification())
544 if im is not None:
545 renderer.draw_image(gc, l, b, im)
/usr/local/lib/python2.7/dist-packages/matplotlib/image.pyc in make_image(self, renderer, magnification, unsampled)
768 return self._make_image(
769 self._A, bbox, transformed_bbox, self.axes.bbox, magnification,
--> 770 unsampled=unsampled)
771
772 def _check_unsampled_image(self, renderer):
/usr/local/lib/python2.7/dist-packages/matplotlib/image.pyc in _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)
424 A, output, t, _interpd_[self.get_interpolation()],
425 self.get_resample(), alpha,
--> 426 self.get_filternorm() or 0.0, self.get_filterrad() or 0.0)
427
428 if created_rgba_mask:
ValueError: 3-dimensional arrays must be of dtype unsigned byte, unsigned short, float32 or float64
Would you, please, advice on how to solve this problem?
Thank you very much for your help
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.