Spaces:
Sleeping
Sleeping
Mostafa Shahin
commited on
Commit
•
6837b6d
1
Parent(s):
c2a23c7
Fix figure
Browse files
app.py
CHANGED
@@ -92,7 +92,7 @@ def scale_vector(vector, new_min, new_max):
|
|
92 |
|
93 |
|
94 |
|
95 |
-
def create_spectrogram_with_att(wav_file, att_contour, att):
|
96 |
# Read the WAV file
|
97 |
sampling_rate, data = wavfile.read(wav_file)
|
98 |
|
@@ -101,19 +101,21 @@ def create_spectrogram_with_att(wav_file, att_contour, att):
|
|
101 |
fig, ax = plt.subplots(figsize=(10, 5))
|
102 |
|
103 |
# Plot the spectrogram
|
104 |
-
ax.pcolormesh(t, f, 10 * np.log10(Sxx), shading='gouraud')
|
105 |
ax.set_ylabel('Frequency (Hz)')
|
106 |
ax.set_xlabel('Time (s)')
|
107 |
ax.set_title(f'Spectrogram with {att} Contour')
|
108 |
ax.set_ylim(0, 8000) # Adjust the frequency range if necessary
|
109 |
|
|
|
110 |
# Plot the att contour
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
|
115 |
return fig
|
116 |
|
|
|
117 |
def plot_contour(audio_file, att):
|
118 |
indx = engine.processor.tokenizer.convert_tokens_to_ids([f'p_{att}'])
|
119 |
att_contour = engine.logits.squeeze()[:,indx]
|
|
|
92 |
|
93 |
|
94 |
|
95 |
+
def create_spectrogram_with_att(wav_file, att_contour, att ):
|
96 |
# Read the WAV file
|
97 |
sampling_rate, data = wavfile.read(wav_file)
|
98 |
|
|
|
101 |
fig, ax = plt.subplots(figsize=(10, 5))
|
102 |
|
103 |
# Plot the spectrogram
|
104 |
+
ax.pcolormesh(t, f, 10 * np.log10(Sxx), shading='gouraud') # Use grayscale colormap
|
105 |
ax.set_ylabel('Frequency (Hz)')
|
106 |
ax.set_xlabel('Time (s)')
|
107 |
ax.set_title(f'Spectrogram with {att} Contour')
|
108 |
ax.set_ylim(0, 8000) # Adjust the frequency range if necessary
|
109 |
|
110 |
+
ax_att = ax.twinx()
|
111 |
# Plot the att contour
|
112 |
+
time_att = np.arange(0, len(att_contour) * 0.02, 0.02) # Assuming pitch_contour is sampled every 20 ms
|
113 |
+
ax_att.plot(time_att, att_contour, color='blue', label=f'{att} Contour')
|
114 |
+
ax_att.legend()
|
115 |
|
116 |
return fig
|
117 |
|
118 |
+
|
119 |
def plot_contour(audio_file, att):
|
120 |
indx = engine.processor.tokenizer.convert_tokens_to_ids([f'p_{att}'])
|
121 |
att_contour = engine.logits.squeeze()[:,indx]
|