Update app.py
Browse files
app.py
CHANGED
@@ -213,7 +213,30 @@ def main():
|
|
213 |
print(f"\nThis is likely a watermarked audio: {result}")
|
214 |
|
215 |
# Run on an unwatermarked audio
|
216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
print(f"This is likely an unwatermarked audio: {result2}")
|
218 |
st.markdown(result)
|
219 |
|
|
|
213 |
print(f"\nThis is likely a watermarked audio: {result}")
|
214 |
|
215 |
# Run on an unwatermarked audio
|
216 |
+
tmp_input_audio_file = os.path.join("/tmp/", audio_file.name)
|
217 |
+
file_extension = os.path.splitext(tmp_input_audio_file)[1].lower()
|
218 |
+
if file_extension in [".wav", ".flac"]:
|
219 |
+
with open("test.wav", "wb") as f:
|
220 |
+
f.write(audio_file.getbuffer())
|
221 |
+
|
222 |
+
elif file_extension == ".mp3":
|
223 |
+
with open("test.mp3", "wb") as f:
|
224 |
+
f.write(audio_file.getbuffer())
|
225 |
+
|
226 |
+
#Load the WAV file using torchaudio
|
227 |
+
if file_extension in [".wav", ".flac"]:
|
228 |
+
wav, sample_rate = torchaudio.load("test.wav")
|
229 |
+
|
230 |
+
elif file_extension == ".mp3":
|
231 |
+
# Load an MP3 file
|
232 |
+
audio = AudioSegment.from_mp3("test.mp3")
|
233 |
+
|
234 |
+
# Export it as a WAV file
|
235 |
+
audio.export("test.wav", format="wav")
|
236 |
+
wav3, sample_rate = torchaudio.load("test.wav")
|
237 |
+
wav= wav3.unsqueeze(0)
|
238 |
+
|
239 |
+
result2, message2 = detector.detect_watermark(wav3, sample_rate=default_sr, message_threshold=0.5)
|
240 |
print(f"This is likely an unwatermarked audio: {result2}")
|
241 |
st.markdown(result)
|
242 |
|