baseline
Browse files- .gitattributes +1 -0
- app.py +133 -0
- audio.wav +3 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
audio.wav filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ggwave
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def encode_text_to_audio(text, protocol_id=1, volume=20):
|
| 7 |
+
"""
|
| 8 |
+
Encode text to audio waveform using ggwave
|
| 9 |
+
|
| 10 |
+
Args:
|
| 11 |
+
text: Text to encode
|
| 12 |
+
protocol_id: ggwave protocol (0-8, default 1)
|
| 13 |
+
volume: Audio volume (0-100, default 20)
|
| 14 |
+
|
| 15 |
+
Returns:
|
| 16 |
+
Tuple of (sample_rate, audio_data) for Gradio audio output
|
| 17 |
+
"""
|
| 18 |
+
if not text:
|
| 19 |
+
return None
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
waveform = ggwave.encode(text, protocolId=protocol_id, volume=volume)
|
| 23 |
+
audio_data = np.frombuffer(waveform, dtype=np.float32)
|
| 24 |
+
return 48000, audio_data
|
| 25 |
+
except Exception as e:
|
| 26 |
+
raise gr.Error(f"Encoding failed: {str(e)}")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def decode_audio_to_text(audio_data):
|
| 30 |
+
"""
|
| 31 |
+
Decode audio waveform to text using ggwave
|
| 32 |
+
|
| 33 |
+
Args:
|
| 34 |
+
audio_data: Tuple of (sample_rate, audio_array) from Gradio
|
| 35 |
+
|
| 36 |
+
Returns:
|
| 37 |
+
Decoded text string
|
| 38 |
+
"""
|
| 39 |
+
if audio_data is None:
|
| 40 |
+
return "No audio provided"
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
sample_rate, audio = audio_data
|
| 44 |
+
if audio.dtype != np.float32:
|
| 45 |
+
audio = audio.astype(np.float32)
|
| 46 |
+
if sample_rate != 48000:
|
| 47 |
+
duration = len(audio) / sample_rate
|
| 48 |
+
new_length = int(duration * 48000)
|
| 49 |
+
audio = np.interp(
|
| 50 |
+
np.linspace(0, len(audio), new_length), np.arange(len(audio)), audio
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
instance = ggwave.init()
|
| 54 |
+
chunk_size = 1024
|
| 55 |
+
decoded_text = ""
|
| 56 |
+
|
| 57 |
+
for i in range(0, len(audio), chunk_size):
|
| 58 |
+
chunk = audio[i : i + chunk_size]
|
| 59 |
+
chunk_bytes = chunk.tobytes()
|
| 60 |
+
|
| 61 |
+
res = ggwave.decode(instance, chunk_bytes)
|
| 62 |
+
if res is not None:
|
| 63 |
+
try:
|
| 64 |
+
decoded_text = res.decode("utf-8")
|
| 65 |
+
break
|
| 66 |
+
except:
|
| 67 |
+
pass
|
| 68 |
+
|
| 69 |
+
ggwave.free(instance)
|
| 70 |
+
|
| 71 |
+
if decoded_text:
|
| 72 |
+
return f"✅ Decoded: {decoded_text}"
|
| 73 |
+
else:
|
| 74 |
+
return "❌ No ggwave signal detected in audio"
|
| 75 |
+
|
| 76 |
+
except Exception as e:
|
| 77 |
+
return f"❌ Decoding failed: {str(e)}"
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
encode_interface = gr.Interface(
|
| 81 |
+
fn=encode_text_to_audio,
|
| 82 |
+
inputs=[
|
| 83 |
+
gr.Textbox(
|
| 84 |
+
label="Text to Encode",
|
| 85 |
+
placeholder="Enter text to convert to audio...",
|
| 86 |
+
lines=3,
|
| 87 |
+
),
|
| 88 |
+
gr.Slider(
|
| 89 |
+
minimum=0,
|
| 90 |
+
maximum=8,
|
| 91 |
+
value=1,
|
| 92 |
+
step=1,
|
| 93 |
+
label="Protocol ID",
|
| 94 |
+
info="ggwave protocol (0-8, affects speed/reliability)",
|
| 95 |
+
),
|
| 96 |
+
gr.Slider(
|
| 97 |
+
minimum=0,
|
| 98 |
+
maximum=100,
|
| 99 |
+
value=20,
|
| 100 |
+
step=1,
|
| 101 |
+
label="Volume",
|
| 102 |
+
info="Audio volume (0-100)",
|
| 103 |
+
),
|
| 104 |
+
],
|
| 105 |
+
outputs=gr.Audio(label="Generated Audio", type="numpy"),
|
| 106 |
+
title="📤 Encode Text to Audio",
|
| 107 |
+
description="Convert text into an audio signal using ggwave protocol",
|
| 108 |
+
examples=[
|
| 109 |
+
["Hello World", 1, 20],
|
| 110 |
+
["GGWave is cool!", 1, 30],
|
| 111 |
+
["Testing 123", 2, 25],
|
| 112 |
+
],
|
| 113 |
+
theme="default",
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
decode_interface = gr.Interface(
|
| 117 |
+
fn=decode_audio_to_text,
|
| 118 |
+
inputs=gr.Audio(
|
| 119 |
+
label="Upload Audio File", type="numpy", sources=["upload", "microphone"]
|
| 120 |
+
),
|
| 121 |
+
outputs=gr.Textbox(label="Decoded Text", lines=5),
|
| 122 |
+
title="📥 Decode Audio to Text",
|
| 123 |
+
description="Extract text from an audio signal using ggwave protocol",
|
| 124 |
+
theme="default",
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
demo = gr.TabbedInterface(
|
| 128 |
+
[encode_interface, decode_interface],
|
| 129 |
+
tab_names=["📤 Encode", "📥 Decode"],
|
| 130 |
+
title="🎵 GGWave Audio Encoder/Decoder",
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
demo.launch(debug=True, mcp_server=True)
|
audio.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b5312c493329500cc6e4ec86eae210ca745a2daeaf1933e4fb41f4d529763736
|
| 3 |
+
size 139308
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ggwave @ git+https://github.com/not-lain/ggwave.git@python#subdirectory=bindings/python
|
| 2 |
+
gradio
|
| 3 |
+
pyaudio
|