Spaces:
Running on Zero
Running on Zero
Stop active microphone recording before transcription and simplify instructions
Browse files
app.py
CHANGED
|
@@ -43,16 +43,43 @@ def create_app() -> gr.Blocks:
|
|
| 43 |
# Provide one audio input and one transcription action.
|
| 44 |
# ---------------------------------------------------------
|
| 45 |
with gr.Blocks(title="LambdaAudio v6", delete_cache=(3600, 3600)) as app:
|
| 46 |
-
gr.Markdown(
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
"[モデルの詳細](https://huggingface.co/KeisukeMiyamoto/lambda-audio-v6)"
|
| 51 |
-
)
|
| 52 |
-
audio = gr.Audio(sources=["upload", "microphone"], type="filepath", format="wav", label="音声", editable=False)
|
| 53 |
-
button = gr.Button("文字起こし", variant="primary")
|
| 54 |
output = gr.Textbox(label="文字起こし結果", lines=5, interactive=False, buttons=["copy"])
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
return app.queue(max_size=10)
|
| 57 |
|
| 58 |
|
|
|
|
| 43 |
# Provide one audio input and one transcription action.
|
| 44 |
# ---------------------------------------------------------
|
| 45 |
with gr.Blocks(title="LambdaAudio v6", delete_cache=(3600, 3600)) as app:
|
| 46 |
+
gr.Markdown("# LambdaAudio v6\n日本語の音声をアップロードするか、マイクで録音してください。\n\n[モデルの詳細](https://huggingface.co/KeisukeMiyamoto/lambda-audio-v6)")
|
| 47 |
+
audio = gr.Audio(sources=["upload", "microphone"], type="filepath", format="wav", label="音声", editable=False, elem_id="recording-input")
|
| 48 |
+
button = gr.Button("文字起こし", variant="primary", elem_id="transcribe-button")
|
| 49 |
+
submit = gr.Button(visible="hidden", elem_id="transcribe-submit")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
output = gr.Textbox(label="文字起こし結果", lines=5, interactive=False, buttons=["copy"])
|
| 51 |
+
submit.click(transcribe_recording, inputs=audio, outputs=output, api_name="transcribe", concurrency_limit=1)
|
| 52 |
+
|
| 53 |
+
# ---------------------------------------------------------
|
| 54 |
+
# Stop the browser recorder before submitting its uploaded audio.
|
| 55 |
+
# The stop_recording event fires after Gradio finishes uploading.
|
| 56 |
+
# ---------------------------------------------------------
|
| 57 |
+
button.click(
|
| 58 |
+
fn=None,
|
| 59 |
+
queue=False,
|
| 60 |
+
js="""() => {
|
| 61 |
+
const audio = document.getElementById('recording-input');
|
| 62 |
+
if (audio.dataset.submitAfterRecording) return;
|
| 63 |
+
const stop = [...audio.querySelectorAll('.stop-button, .stop-button-paused')]
|
| 64 |
+
.find(button => button.checkVisibility());
|
| 65 |
+
if (stop) {
|
| 66 |
+
audio.dataset.submitAfterRecording = 'true';
|
| 67 |
+
stop.click();
|
| 68 |
+
return;
|
| 69 |
+
}
|
| 70 |
+
document.getElementById('transcribe-submit').click();
|
| 71 |
+
}""",
|
| 72 |
+
)
|
| 73 |
+
audio.stop_recording(
|
| 74 |
+
fn=None,
|
| 75 |
+
queue=False,
|
| 76 |
+
js="""() => {
|
| 77 |
+
const audio = document.getElementById('recording-input');
|
| 78 |
+
if (!audio.dataset.submitAfterRecording) return;
|
| 79 |
+
delete audio.dataset.submitAfterRecording;
|
| 80 |
+
document.getElementById('transcribe-submit').click();
|
| 81 |
+
}""",
|
| 82 |
+
)
|
| 83 |
return app.queue(max_size=10)
|
| 84 |
|
| 85 |
|