File size: 1,314 Bytes
83f7baa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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()