Spaces:
Running
Running
Update steganography.py
Browse files- steganography.py +18 -8
steganography.py
CHANGED
@@ -57,9 +57,19 @@ def create_audio_with_spectrogram(text, base_width, height, max_font_size, margi
|
|
57 |
y = spectrogram_image_to_audio(spec_image)
|
58 |
audio_path = 'output.wav'
|
59 |
sf.write(audio_path, y, DEFAULT_SAMPLE_RATE)
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
# Function for displaying the spectrogram of an audio file
|
65 |
def display_audio_spectrogram(audio_path):
|
@@ -69,11 +79,11 @@ def display_audio_spectrogram(audio_path):
|
|
69 |
|
70 |
plt.figure(figsize=(10, 4))
|
71 |
librosa.display.specshow(S_dB, sr=sr, x_axis='time', y_axis='mel')
|
72 |
-
plt.axis('off')
|
73 |
-
plt.tight_layout(pad=0)
|
74 |
|
75 |
spectrogram_path = 'uploaded_spectrogram.png'
|
76 |
-
plt.savefig(spectrogram_path, bbox_inches='tight', pad_inches=0, transparent=True)
|
77 |
plt.close()
|
78 |
return spectrogram_path
|
79 |
|
@@ -102,13 +112,13 @@ with gr.Blocks(title='Audio Steganography', theme=gr.themes.Soft(primary_hue="gr
|
|
102 |
with gr.Column(variant='panel'):
|
103 |
with gr.Group():
|
104 |
output_audio = gr.Audio(type="filepath", label="Generated audio")
|
105 |
-
|
106 |
|
107 |
def gradio_interface_fn(text, base_width, height, max_font_size, margin, letter_spacing):
|
108 |
print("\n", text)
|
109 |
return create_audio_with_spectrogram(text, base_width, height, max_font_size, margin, letter_spacing)
|
110 |
|
111 |
-
generate_button.click(gradio_interface_fn, inputs=[text, base_width, height, max_font_size, margin, letter_spacing], outputs=[output_audio,
|
112 |
|
113 |
with gr.Tab("Image to Spectrogram"):
|
114 |
with gr.Group():
|
|
|
57 |
y = spectrogram_image_to_audio(spec_image)
|
58 |
audio_path = 'output.wav'
|
59 |
sf.write(audio_path, y, DEFAULT_SAMPLE_RATE)
|
60 |
+
|
61 |
+
# Create spectrogram from audio
|
62 |
+
S = librosa.feature.melspectrogram(y=y, sr=DEFAULT_SAMPLE_RATE)
|
63 |
+
S_dB = librosa.power_to_db(S, ref=np.max)
|
64 |
+
plt.figure(figsize=(10, 4))
|
65 |
+
librosa.display.specshow(S_dB, sr=DEFAULT_SAMPLE_RATE, x_axis='time', y_axis='mel')
|
66 |
+
plt.axis('off')
|
67 |
+
plt.tight_layout(pad=0)
|
68 |
+
spectrogram_path = 'spectrogram.png'
|
69 |
+
plt.savefig(spectrogram_path, bbox_inches='tight', pad_inches=0, transparent=True)
|
70 |
+
plt.close()
|
71 |
+
|
72 |
+
return audio_path, spectrogram_path
|
73 |
|
74 |
# Function for displaying the spectrogram of an audio file
|
75 |
def display_audio_spectrogram(audio_path):
|
|
|
79 |
|
80 |
plt.figure(figsize=(10, 4))
|
81 |
librosa.display.specshow(S_dB, sr=sr, x_axis='time', y_axis='mel')
|
82 |
+
plt.axis('off')
|
83 |
+
plt.tight_layout(pad=0)
|
84 |
|
85 |
spectrogram_path = 'uploaded_spectrogram.png'
|
86 |
+
plt.savefig(spectrogram_path, bbox_inches='tight', pad_inches=0, transparent=True)
|
87 |
plt.close()
|
88 |
return spectrogram_path
|
89 |
|
|
|
112 |
with gr.Column(variant='panel'):
|
113 |
with gr.Group():
|
114 |
output_audio = gr.Audio(type="filepath", label="Generated audio")
|
115 |
+
output_spectrogram = gr.Image(type="filepath", label="Spectrogram")
|
116 |
|
117 |
def gradio_interface_fn(text, base_width, height, max_font_size, margin, letter_spacing):
|
118 |
print("\n", text)
|
119 |
return create_audio_with_spectrogram(text, base_width, height, max_font_size, margin, letter_spacing)
|
120 |
|
121 |
+
generate_button.click(gradio_interface_fn, inputs=[text, base_width, height, max_font_size, margin, letter_spacing], outputs=[output_audio, output_spectrogram])
|
122 |
|
123 |
with gr.Tab("Image to Spectrogram"):
|
124 |
with gr.Group():
|