MarcosAutuori commited on
Commit
90cb461
路
verified 路
1 Parent(s): ab5fa9c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import wave
4
+ import struct
5
+ import math
6
+
7
+ # Fun莽茫o para garantir que os arquivos existam (mesma l贸gica do jogo)
8
+ def ensure_sounds():
9
+ if not os.path.exists("sounds"):
10
+ os.makedirs("sounds")
11
+
12
+ sounds = {
13
+ "sounds/click.wav": 440,
14
+ "sounds/correct.wav": 880,
15
+ "sounds/wrong.wav": 220
16
+ }
17
+
18
+ for filename, freq in sounds.items():
19
+ if not os.path.exists(filename):
20
+ sample_rate = 44100
21
+ duration = 0.2
22
+ volume = 0.3
23
+ n_samples = int(sample_rate * duration)
24
+ with wave.open(filename, 'w') as f:
25
+ f.setnchannels(1)
26
+ f.setsampwidth(2)
27
+ f.setframerate(sample_rate)
28
+ for i in range(n_samples):
29
+ val = int(volume * 32767.0 * math.sin(2.0 * math.pi * freq * i / sample_rate))
30
+ f.writeframesraw(struct.pack('<h', val))
31
+ print(f"Created: {filename}")
32
+
33
+ ensure_sounds()
34
+
35
+ def play_sound(file_type):
36
+ path = f"sounds/{file_type}.wav"
37
+ if os.path.exists(path):
38
+ return path, f"Playing: {path}"
39
+ return None, f"Error: {path} not found!"
40
+
41
+ with gr.Blocks(title="Autuori Sound Test") as demo:
42
+ gr.Markdown("# 馃攰 Sound Diagnostic Tool")
43
+ gr.Markdown("Click the buttons below to test if the browser can play the generated files.")
44
+
45
+ with gr.Row():
46
+ btn_click = gr.Button("Test Click")
47
+ btn_correct = gr.Button("Test Correct")
48
+ btn_wrong = gr.Button("Test Wrong")
49
+
50
+ # Player vis铆vel para diagn贸stico
51
+ audio_player = gr.Audio(label="Audio Output", interactive=False, autoplay=True)
52
+ status = gr.Textbox(label="File Status")
53
+
54
+ btn_click.click(fn=lambda: play_sound("click"), outputs=[audio_player, status])
55
+ btn_correct.click(fn=lambda: play_sound("correct"), outputs=[audio_player, status])
56
+ btn_wrong.click(fn=lambda: play_sound("wrong"), outputs=[audio_player, status])
57
+
58
+ if __name__ == "__main__":
59
+ demo.launch()