Convert a 3D spectrogram to object file format (.OFF)
Most deformed 3d shapes ever so far without one single correct. ; i.e., this should look like a 3d graph While the html is fine.. I tried most definitely close to everything except the answer.. I'm surprised I didn't come across the answer after so many attempts. 3d arrays in space, much spectrogram graph. Is it disconnected from go.graph obj/y/n-therefore grayscale?3, or, should we "go." in the face/vert structure? I'm happy with the shape/yet.. I'm not sure if I triangulated the stacked faces of f. Let alone np.columnstack the np.ones to get the len and tuple(map(int of the face. Totally confused. BTW can you convert from html? I will use the format mutual frequently so might come in handy.
Code:
import numpy as np import warnings warnings.filterwarnings('ignore')
import os from scipy import signal from scipy.io import wavfile import
matplotlib.pyplot as plt import librosa.display import
plotly.graph_objs as go
filename=[]
for filename in os.listdir('/Users/tom/Documents/wav/'): if 'wav' in
filename:
sample_rate, sample =
wavfile.read(f'/Users/tom/Documents/wav/{filename}')
def log_specgram(audio, sample_rate, window_size=20,
step_size=10, eps=1e-10):
nperseg = int(round(window_size * sample_rate / 1e3))
noverlap = int(round(step_size * sample_rate / 1e3))
freqs, times, spec = signal.spectrogram(audio,
fs=sample_rate,
window='hann',
nperseg=nperseg,
noverlap=noverlap,
detrend=False)
return freqs, times, np.log(spec.T.astype(np.float32) + eps)
def plot_raw_wave(samples):
plt.figure(figsize=(10, 3))
plt.title('Audio wave')
plt.ylabel('Amplitude')
#ax1.plot(np.linspace(0, sample_rate/len(samples1), sample_rate), samples1)
plt.plot(samples)
S = librosa.feature.melspectrogram(sample.astype(float),
sr=sample_rate, n_mels=128)
log_S = librosa.power_to_db(S, ref=np.max)
plt.figure(figsize=(12, 4)) librosa.display.specshow(log_S,
sr=sample_rate, x_axis='time', y_axis='mel') plt.title('Mel power
spectrogram ') plt.colorbar(format='%+02.0f dB')
plt.tight_layout()
freqs, times, spectrogram = log_specgram(sample, sample_rate) data
= [go.Surface(z=spectrogram.T)] layout = go.Layout(
title='Specgtogram 3d',)
fig = go.Figure(data=data, layout=layout)
fig.write_html(f'/Users/tom/Documents/{filename}.html')
vertices= #
#np #spectrogram.T*times#S#spectrogram.T#spectrogram/times#freqs/*().' S
faces= #
#log_S.T/times*/log_S.freq^np.log10^
with open(f'/Users/tom/Documents/{filename}.off', 'w') as fh:
fh.write('OFF\n')#C
fh.write('{} {} 0\n'.format(len(vertices), len(faces)))
#
faces_stacked = np.column_stack((
np.ones(len(faces)) * 3, faces)).astype(np.int64)#4
#
for v in vertices:
fh.write("{} {} {}\n".format(*v))
for f in faces_stacked):
fh.write("{} {} {} {}\n".format(*f))#####
Comments
Post a Comment