From 02e1113d955832990cc97a0c00315753e7100837 Mon Sep 17 00:00:00 2001 From: EliasVincent Date: Mon, 13 Mar 2023 21:41:19 +0100 Subject: [PATCH] add auto-transcribe option --- extensions/whisper_stt/script.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/extensions/whisper_stt/script.py b/extensions/whisper_stt/script.py index b2e840a8..6ef60c57 100644 --- a/extensions/whisper_stt/script.py +++ b/extensions/whisper_stt/script.py @@ -32,13 +32,23 @@ def update_hijack(val): return val +def auto_transcribe(audio, audio_auto, text_state=""): + if audio is None: + return "", "" + if audio_auto: + return do_stt(audio, text_state) + return "", "" + + def ui(): tr_state = gr.State(value="") output_transcription = gr.Textbox(label="STT-Input", placeholder="Speech Preview. Click \"Generate\" to send", interactive=True) output_transcription.change(fn=update_hijack, inputs=[output_transcription], outputs=[tr_state]) + audio_auto = gr.Checkbox(label="Auto-Transcribe", value=True) with gr.Row(): audio = gr.Audio(source="microphone") + audio.change(fn=auto_transcribe, inputs=[audio, audio_auto, tr_state], outputs=[output_transcription, tr_state]) transcribe_button = gr.Button(value="Transcribe") transcribe_button.click(do_stt, inputs=[audio, tr_state], outputs=[output_transcription, tr_state])