ABOUT = """ # Moonshine ASR Unofficial demo for [Moonshine ASR](https://github.com/usefulsensors/moonshine) by Useful Sensors, a fast & efficient ASR model outperforming Whisper """ import os os.environ["KERAS_BACKEND"] = "torch" import gradio as gr import spaces import moonshine from pydub import AudioSegment @spaces.GPU def transcribe(audio, chosen_model): audio_file = AudioSegment.from_file(audio) if len(audio_file) / 1000 >= 64: raise gr.Error("Moonshine only supports audio segments up to 64s long. Please pre-segment your audio and try again.") try: transcription = moonshine.transcribe(audio, chosen_model) except Exception as e: raise gr.Error("Moonshine backend error: " + str(e)) return ' '.join(transcription).strip() with gr.Blocks() as demo: gr.Markdown(ABOUT) aud = gr.Audio(label="Audio", type="filepath", interactive=True) modelname = gr.Radio(label="Model", choices=['moonshine/tiny', 'moonshine/base'], value="moonshine/tiny", interactive=True) btn = gr.Button("Transcribe", variant="primary") out = gr.Textbox(label="Transcription", interactive=False) btn.click(transcribe, inputs=[aud, modelname], outputs=out) gr.Markdown("Unofficial demo by [mrfakename](https://x.com/realmrfakename)") demo.queue().launch()