Spaces:
Sleeping
Sleeping
OthmaneLKH
commited on
Commit
•
642305f
1
Parent(s):
a8d57ec
Update app.py
Browse files
app.py
CHANGED
@@ -437,6 +437,25 @@ def save_recorded_audio(audio):
|
|
437 |
audio.export(file_path, format="wav") # Save the audio as a .wav file
|
438 |
return file_path
|
439 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
440 |
|
441 |
|
442 |
|
@@ -505,6 +524,14 @@ with demo:
|
|
505 |
"""
|
506 |
)
|
507 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
508 |
########################## Step 1.1: Record Audio ##########################
|
509 |
|
510 |
gr.Markdown("## Step 1.1: Record an Audio File")
|
@@ -524,6 +551,20 @@ with demo:
|
|
524 |
outputs=[gen_key_btn],
|
525 |
) """
|
526 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
527 |
########################## Main document Part ##########################
|
528 |
|
529 |
gr.Markdown("<hr />")
|
|
|
437 |
audio.export(file_path, format="wav") # Save the audio as a .wav file
|
438 |
return file_path
|
439 |
|
440 |
+
def click_js():
|
441 |
+
return """function audioRecord() {
|
442 |
+
var xPathRes = document.evaluate ('//*[@id="audio"]//button', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
|
443 |
+
xPathRes.singleNodeValue.click();}"""
|
444 |
+
|
445 |
+
|
446 |
+
def action(btn):
|
447 |
+
"""Changes button text on click"""
|
448 |
+
if btn == 'Speak': return 'Stop'
|
449 |
+
else: return 'Speak'
|
450 |
+
|
451 |
+
|
452 |
+
def check_btn(btn):
|
453 |
+
"""Checks for correct button text before invoking transcribe()"""
|
454 |
+
if btn != 'Speak': raise Exception('Recording...')
|
455 |
+
|
456 |
+
|
457 |
+
def transcribe():
|
458 |
+
return 'Success'
|
459 |
|
460 |
|
461 |
|
|
|
524 |
"""
|
525 |
)
|
526 |
|
527 |
+
gen_key_btn = gr.Button("Generate the secret and evaluation keys")
|
528 |
+
|
529 |
+
gen_key_btn.click(
|
530 |
+
key_gen_fn,
|
531 |
+
inputs=[],
|
532 |
+
outputs=[gen_key_btn],
|
533 |
+
)
|
534 |
+
|
535 |
########################## Step 1.1: Record Audio ##########################
|
536 |
|
537 |
gr.Markdown("## Step 1.1: Record an Audio File")
|
|
|
551 |
outputs=[gen_key_btn],
|
552 |
) """
|
553 |
|
554 |
+
msg = gr.Textbox()
|
555 |
+
audio_box = gr.Audio(label="Audio", source="microphone", type="filepath", elem_id='audio')
|
556 |
+
|
557 |
+
with gr.Row():
|
558 |
+
audio_btn = gr.Button('Speak')
|
559 |
+
clear = gr.Button("Clear")
|
560 |
+
|
561 |
+
audio_btn.click(fn=action, inputs=audio_btn, outputs=audio_btn).\
|
562 |
+
then(fn=lambda: None, _js=click_js()).\
|
563 |
+
then(fn=check_btn, inputs=audio_btn).\
|
564 |
+
success(fn=transcribe, outputs=msg)
|
565 |
+
|
566 |
+
clear.click(lambda: None, None, msg, queue=False)
|
567 |
+
|
568 |
########################## Main document Part ##########################
|
569 |
|
570 |
gr.Markdown("<hr />")
|