Spaces:
Build error
Build error
Commit
·
7f66b95
1
Parent(s):
8d7bec1
Update app.py
Browse files
app.py
CHANGED
@@ -44,18 +44,35 @@ def translate_voice(audio, target_lang):
|
|
44 |
return filename, text, translated_text, target_lang
|
45 |
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
def record_audio():
|
|
|
48 |
fs = 16000
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
51 |
sd.wait()
|
52 |
return audio.flatten()
|
53 |
|
54 |
|
|
|
|
|
|
|
55 |
iface = gr.Interface(
|
56 |
fn=translate_voice,
|
57 |
inputs=[
|
58 |
-
gr.inputs.
|
59 |
gr.inputs.Dropdown(choices=['en', 'ru', 'de', 'fr'], label="Target Language")
|
60 |
],
|
61 |
outputs=[
|
@@ -66,3 +83,4 @@ iface = gr.Interface(
|
|
66 |
]
|
67 |
)
|
68 |
iface.launch()
|
|
|
|
44 |
return filename, text, translated_text, target_lang
|
45 |
|
46 |
|
47 |
+
def toggle_record(button):
|
48 |
+
global is_recording
|
49 |
+
if button:
|
50 |
+
button.text = "Stop Recording"
|
51 |
+
is_recording = True
|
52 |
+
else:
|
53 |
+
button.text = "Start Recording"
|
54 |
+
is_recording = False
|
55 |
+
|
56 |
+
|
57 |
def record_audio():
|
58 |
+
global is_recording
|
59 |
fs = 16000
|
60 |
+
audio = []
|
61 |
+
while is_recording:
|
62 |
+
block = sd.rec(int(fs), samplerate=fs, channels=1)
|
63 |
+
audio.append(block)
|
64 |
+
audio = sd.playrec(audio, samplerate=fs, channels=1)
|
65 |
sd.wait()
|
66 |
return audio.flatten()
|
67 |
|
68 |
|
69 |
+
is_recording = False
|
70 |
+
|
71 |
+
|
72 |
iface = gr.Interface(
|
73 |
fn=translate_voice,
|
74 |
inputs=[
|
75 |
+
gr.inputs.Button(label="Start Recording", type="boolean", toggle=True, default=False, onclick=toggle_record),
|
76 |
gr.inputs.Dropdown(choices=['en', 'ru', 'de', 'fr'], label="Target Language")
|
77 |
],
|
78 |
outputs=[
|
|
|
83 |
]
|
84 |
)
|
85 |
iface.launch()
|
86 |
+
|