Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydub import AudioSegment
|
| 2 |
+
from io import BytesIO
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import binascii
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def handler(input_text):
|
| 8 |
+
hex_data = input_text
|
| 9 |
+
audio_bytes = binascii.unhexlify(hex_data)
|
| 10 |
+
audio_segment = AudioSegment.from_file(BytesIO(audio_bytes), format="mp3")
|
| 11 |
+
|
| 12 |
+
output_buffer = BytesIO()
|
| 13 |
+
audio_segment.export(output_buffer, format="mp3")
|
| 14 |
+
|
| 15 |
+
return output_buffer
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# 创建 Gradio 界面
|
| 19 |
+
def create_interface():
|
| 20 |
+
with gr.Blocks() as demo:
|
| 21 |
+
with gr.Row():
|
| 22 |
+
input_text = gr.Text(label="Input HexCode", lines=10)
|
| 23 |
+
output_audio = gr.Audio(label="Audio")
|
| 24 |
+
|
| 25 |
+
submit_btn = gr.Button("Submit")
|
| 26 |
+
submit_btn.click(
|
| 27 |
+
fn=handler,
|
| 28 |
+
inputs=[input_text],
|
| 29 |
+
outputs=output_audio
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
return demo
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
demo = create_interface()
|
| 36 |
+
demo.launch()
|