Spaces:
Build error
Build error
File size: 1,418 Bytes
0566261 62a78c6 69502c9 62a78c6 69502c9 f13ae93 5cac893 0566261 62a78c6 69502c9 62a78c6 dd689bb 3740191 62a78c6 dd689bb 00d34db dd689bb 00d34db 62a78c6 dd689bb 797417d 62a78c6 3f864d3 797417d 47991e5 62a78c6 |
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 |
import gradio as gr
import librosa
from transformers import AutoFeatureExtractor, AutoTokenizer, SpeechEncoderDecoderModel
feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/wav2vec2-xls-r-300m-en-to-15", use_auth_token="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")
tokenizer = AutoTokenizer.from_pretrained("facebook/wav2vec2-xls-r-300m-en-to-15", use_auth_token="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", use_fast=False)
model = SpeechEncoderDecoderModel.from_pretrained("facebook/wav2vec2-xls-r-300m-en-to-15", use_auth_token="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")
def process_audio_file(file):
data, sr = librosa.load(file)
if sr != 16000:
data = librosa.resample(data, sr, 16000)
print(data.shape)
input_values = feature_extractor(data, return_tensors="pt").input_values
return input_values
def transcribe(target_language, file):
print("Target", target_language)
input_values = process_audio_file(file)
sequences = model.generate(input_values)
transcription = tokenizer.batch_decode(sequences, skip_special_tokens=True)
return transcription[0]
target_languages = ["German", "French", "Italian"]
iface = gr.Interface(
fn=transcribe,
inputs=[
gr.inputs.Dropdown(target_languages),
gr.inputs.Audio(source="microphone", type='filepath'),
],
outputs="text",
)
iface.launch() |