Spaces:
Running
Running
Update steganography.py
Browse files- steganography.py +3 -9
steganography.py
CHANGED
@@ -10,8 +10,6 @@ from PIL import Image, ImageDraw, ImageFont
|
|
10 |
|
11 |
DEFAULT_FONT_PATH = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
|
12 |
DEFAULT_SAMPLE_RATE = 22050
|
13 |
-
N_MELS = 128 # Количество мел-частотных полос
|
14 |
-
N_FFT = 2048 # Длина окна FFT
|
15 |
|
16 |
logging.basicConfig(level=logging.INFO)
|
17 |
|
@@ -56,11 +54,7 @@ def create_text_image(text, font, base_width=512, height=256, margin=10, letter_
|
|
56 |
def spectrogram_image_to_audio(image, sr=DEFAULT_SAMPLE_RATE):
|
57 |
flipped_image = np.flipud(image)
|
58 |
S = flipped_image.astype(np.float32) / 255.0 * 100.0
|
59 |
-
|
60 |
-
# Ensure the spectrogram has the correct shape
|
61 |
-
S = librosa.util.fix_length(S, size=N_MELS)
|
62 |
-
|
63 |
-
y = librosa.griffinlim(S, n_iter=60, window='hann', n_fft=N_FFT, hop_length=N_FFT//4)
|
64 |
return y
|
65 |
|
66 |
def create_audio_with_spectrogram(text, base_width, height, max_font_size, margin, letter_spacing):
|
@@ -72,7 +66,7 @@ def create_audio_with_spectrogram(text, base_width, height, max_font_size, margi
|
|
72 |
audio_path = temp_audio.name
|
73 |
sf.write(audio_path, y, DEFAULT_SAMPLE_RATE)
|
74 |
|
75 |
-
S = librosa.feature.melspectrogram(y=y, sr=DEFAULT_SAMPLE_RATE
|
76 |
S_dB = librosa.power_to_db(S, ref=np.max)
|
77 |
plt.figure(figsize=(10, 4))
|
78 |
librosa.display.specshow(S_dB, sr=DEFAULT_SAMPLE_RATE, x_axis="time", y_axis="mel")
|
@@ -88,7 +82,7 @@ def create_audio_with_spectrogram(text, base_width, height, max_font_size, margi
|
|
88 |
|
89 |
def display_audio_spectrogram(audio_path):
|
90 |
y, sr = librosa.load(audio_path, sr=None)
|
91 |
-
S = librosa.feature.melspectrogram(y=y, sr=sr
|
92 |
S_dB = librosa.power_to_db(S, ref=np.max)
|
93 |
|
94 |
plt.figure(figsize=(10, 4))
|
|
|
10 |
|
11 |
DEFAULT_FONT_PATH = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
|
12 |
DEFAULT_SAMPLE_RATE = 22050
|
|
|
|
|
13 |
|
14 |
logging.basicConfig(level=logging.INFO)
|
15 |
|
|
|
54 |
def spectrogram_image_to_audio(image, sr=DEFAULT_SAMPLE_RATE):
|
55 |
flipped_image = np.flipud(image)
|
56 |
S = flipped_image.astype(np.float32) / 255.0 * 100.0
|
57 |
+
y = librosa.griffinlim(S)
|
|
|
|
|
|
|
|
|
58 |
return y
|
59 |
|
60 |
def create_audio_with_spectrogram(text, base_width, height, max_font_size, margin, letter_spacing):
|
|
|
66 |
audio_path = temp_audio.name
|
67 |
sf.write(audio_path, y, DEFAULT_SAMPLE_RATE)
|
68 |
|
69 |
+
S = librosa.feature.melspectrogram(y=y, sr=DEFAULT_SAMPLE_RATE)
|
70 |
S_dB = librosa.power_to_db(S, ref=np.max)
|
71 |
plt.figure(figsize=(10, 4))
|
72 |
librosa.display.specshow(S_dB, sr=DEFAULT_SAMPLE_RATE, x_axis="time", y_axis="mel")
|
|
|
82 |
|
83 |
def display_audio_spectrogram(audio_path):
|
84 |
y, sr = librosa.load(audio_path, sr=None)
|
85 |
+
S = librosa.feature.melspectrogram(y=y, sr=sr)
|
86 |
S_dB = librosa.power_to_db(S, ref=np.max)
|
87 |
|
88 |
plt.figure(figsize=(10, 4))
|