Politrees commited on
Commit
ff61c28
·
verified ·
1 Parent(s): 4b5ced5

Update steganography.py

Browse files
Files changed (1) hide show
  1. steganography.py +11 -11
steganography.py CHANGED
@@ -42,14 +42,14 @@ def text_to_spectrogram_image(text, base_width=512, height=256, max_font_size=80
42
  image = np.where(image > 0, 255, image)
43
  return image
44
 
45
- # Converting an image to an audio signal
46
  def spectrogram_image_to_audio(image, sr=22050):
47
  flipped_image = np.flipud(image)
48
  S = flipped_image.astype(np.float32) / 255.0 * 100.0
49
  y = librosa.griffinlim(S)
50
  return y
51
 
52
- # Function for creating an audio file and a spectrogram from text
53
  def create_audio_with_spectrogram(text, base_width, height, max_font_size, margin, letter_spacing):
54
  spec_image = text_to_spectrogram_image(text, base_width, height, max_font_size, margin, letter_spacing)
55
  y = spectrogram_image_to_audio(spec_image)
@@ -74,7 +74,7 @@ def display_audio_spectrogram(audio_path):
74
  plt.close()
75
  return spectrogram_path
76
 
77
- # Convert the uploaded image to a sound spectrogram
78
  def image_to_spectrogram_audio(image_path, sr=22050):
79
  image = Image.open(image_path).convert('L')
80
  image = np.array(image)
@@ -103,13 +103,13 @@ with gr.Blocks(title='Audio Steganography', theme=gr.themes.Soft(primary_hue="gr
103
  with gr.Row(variant='panel'):
104
  base_width = gr.Slider(value=512, label="Image Width", visible=False)
105
  height = gr.Slider(value=256, label="Image Height", visible=False)
106
- max_font_size = gr.Slider(minimum=10, maximum=130, step=5, value=80, label="Font Size")
107
  margin = gr.Slider(minimum=0, maximum=50, step=1, value=10, label="Indent")
108
- letter_spacing = gr.Slider(minimum=0, maximum=50, step=1, value=5, label="Distance between letters")
109
  generate_button = gr.Button("Generate")
110
 
111
  with gr.Column(variant='panel'):
112
- output_audio = gr.Audio(type="filepath", label="Generated Sound")
113
  output_image = gr.Image(type="filepath", label="Spectrogram")
114
 
115
  def gradio_interface_fn(text, base_width, height, max_font_size, margin, letter_spacing):
@@ -124,11 +124,11 @@ with gr.Blocks(title='Audio Steganography', theme=gr.themes.Soft(primary_hue="gr
124
  with gr.Tab("Image to Spectrogram"):
125
  with gr.Group():
126
  with gr.Row(variant='panel'):
127
- upload_image = gr.Image(type="filepath", label="Upload an image")
128
- convert_button = gr.Button("Convert to Audio")
129
 
130
  with gr.Column(variant='panel'):
131
- output_audio_from_image = gr.Audio(type="filepath", label="Generated Sound")
132
 
133
  def gradio_image_to_audio_fn(upload_image):
134
  return image_to_spectrogram_audio(upload_image)
@@ -142,8 +142,8 @@ with gr.Blocks(title='Audio Steganography', theme=gr.themes.Soft(primary_hue="gr
142
  with gr.Tab("Audio Spectrogram"):
143
  with gr.Group():
144
  with gr.Row(variant='panel'):
145
- upload_audio = gr.Audio(type="filepath", label="Upload an audio file")
146
- decode_button = gr.Button("Show a spectrogram")
147
 
148
  with gr.Column(variant='panel'):
149
  decoded_image = gr.Image(type="filepath", label="Audio Spectrogram")
 
42
  image = np.where(image > 0, 255, image)
43
  return image
44
 
45
+ # Converting an image to audio
46
  def spectrogram_image_to_audio(image, sr=22050):
47
  flipped_image = np.flipud(image)
48
  S = flipped_image.astype(np.float32) / 255.0 * 100.0
49
  y = librosa.griffinlim(S)
50
  return y
51
 
52
+ # Function for creating an audio file and spectrogram from text
53
  def create_audio_with_spectrogram(text, base_width, height, max_font_size, margin, letter_spacing):
54
  spec_image = text_to_spectrogram_image(text, base_width, height, max_font_size, margin, letter_spacing)
55
  y = spectrogram_image_to_audio(spec_image)
 
74
  plt.close()
75
  return spectrogram_path
76
 
77
+ # Converting a downloaded image to an audio spectrogram
78
  def image_to_spectrogram_audio(image_path, sr=22050):
79
  image = Image.open(image_path).convert('L')
80
  image = np.array(image)
 
103
  with gr.Row(variant='panel'):
104
  base_width = gr.Slider(value=512, label="Image Width", visible=False)
105
  height = gr.Slider(value=256, label="Image Height", visible=False)
106
+ max_font_size = gr.Slider(minimum=10, maximum=130, step=5, value=80, label="Font size")
107
  margin = gr.Slider(minimum=0, maximum=50, step=1, value=10, label="Indent")
108
+ letter_spacing = gr.Slider(minimum=0, maximum=50, step=1, value=5, label="Letter spacing")
109
  generate_button = gr.Button("Generate")
110
 
111
  with gr.Column(variant='panel'):
112
+ output_audio = gr.Audio(type="filepath", label="Generated audio")
113
  output_image = gr.Image(type="filepath", label="Spectrogram")
114
 
115
  def gradio_interface_fn(text, base_width, height, max_font_size, margin, letter_spacing):
 
124
  with gr.Tab("Image to Spectrogram"):
125
  with gr.Group():
126
  with gr.Row(variant='panel'):
127
+ upload_image = gr.Image(type="filepath", label="Upload image")
128
+ convert_button = gr.Button("Convert to audio")
129
 
130
  with gr.Column(variant='panel'):
131
+ output_audio_from_image = gr.Audio(type="filepath", label="Generated audio")
132
 
133
  def gradio_image_to_audio_fn(upload_image):
134
  return image_to_spectrogram_audio(upload_image)
 
142
  with gr.Tab("Audio Spectrogram"):
143
  with gr.Group():
144
  with gr.Row(variant='panel'):
145
+ upload_audio = gr.Audio(type="filepath", label="Upload audio")
146
+ decode_button = gr.Button("Show spectrogram")
147
 
148
  with gr.Column(variant='panel'):
149
  decoded_image = gr.Image(type="filepath", label="Audio Spectrogram")