File size: 1,711 Bytes
06cd898
 
 
 
 
 
be8041d
 
06cd898
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
import warnings
warnings.filterwarnings("ignore")
import os
import re
import gradio as gr
import numpy as np
import torchaudio
import nbimporter
from transformers import pipeline
from transformers import AutoProcessor
from pyctcdecode import build_ctcdecoder
from transformers import Wav2Vec2ProcessorWithLM
from text2int import text_to_int
from isNumber import is_number
from Text2List import text_to_list
from convert2list import convert_to_list
from processDoubles import process_doubles
from replaceWords import replace_words

transcriber = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-hindi_v1")
processor = AutoProcessor.from_pretrained("cdactvm/w2v-bert-2.0-hindi_v1")

vocab_dict = processor.tokenizer.get_vocab()

sorted_vocab_dict = {k.lower(): v for k, v in sorted(vocab_dict.items(), key=lambda item: item[1])}
decoder = build_ctcdecoder(
    labels=list(sorted_vocab_dict.keys()),
    kenlm_model_path="lm.binary",
    )
processor_with_lm = Wav2Vec2ProcessorWithLM(
    feature_extractor=processor.feature_extractor,
    tokenizer=processor.tokenizer,
    decoder=decoder
    )
processor.feature_extractor._processor_class = "Wav2Vec2ProcessorWithLM"

 
def transcribe(audio):
    # # Process the audio file
    transcript = transcriber(audio)
    text_value = transcript['text']
    print(text_value)
    processd_doubles=process_doubles(text_value)
    converted_to_list=convert_to_list(processd_doubles,text_to_list())
    replaced_words = replace_words(converted_to_list)
    converted_text=text_to_int(replaced_words)
    return converted_text


demo = gr.Interface(
    transcribe,
    gr.Audio(sources="microphone", type="filepath"),
    "text",
)

demo.launch()