Spaces:
Runtime error
Runtime error
File size: 1,724 Bytes
0b452e3 484ff18 0b452e3 e3a183b a320278 b2a5d55 da142ce 6557512 da142ce d77f418 0b452e3 6596104 0b452e3 8458d22 b2a5d55 da142ce 0b452e3 b867ef9 e3e68b4 b867ef9 0b452e3 6596104 0b452e3 6596104 b867ef9 0b452e3 |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
from transformers import pipeline
import torch
import librosa
import json
max_duration = int(30 * 16000)
def load_model(model_name = "cawoylel/windanam_mms-1b-tts_v2"):
"""
Function to load model from hugging face
"""
pipe = pipeline("automatic-speech-recognition", model="cawoylel/windanam_mms-1b-tts_v2")
return pipe
pipeline = load_model()
def transcribe_audio(sample):
"""
Transcribe audio
"""
transcription = pipeline(sample)
return transcription["text"]
def transcribe(audio_file_mic=None, audio_file_upload=None):
if audio_file_mic:
audio_file = audio_file_mic
elif audio_file_upload:
audio_file = audio_file_upload
else:
return "Please upload an audio file or record one"
# Make sure audio is 16kHz
speech, sample_rate = librosa.load(audio_file)
if sample_rate != 16000:
speech = librosa.resample(speech, orig_sr=sample_rate, target_sr=16000)
duration = librosa.get_duration(y=speech, sr=16000)
if duration > 30:
speech = speech[:max_duration]
return transcribe_audio(speech)
description = '''windanam-mms is a Multidialectal ASR model for Fula and base on the MMS speech model: [Scaling Speech Technology to 1,000+ Languages](https://arxiv.org/abs/2305.13516).'''
iface = gr.Interface(fn=transcribe,
inputs=[
gr.Audio(source="microphone", type="filepath", label="Record Audio"),
gr.Audio(source="upload", type="filepath", label="Upload Audio"),
],
outputs=gr.Textbox(label="Transcription"),
description=description
)
iface.launch() |