File size: 2,749 Bytes
4449a5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6899aff
 
9d7dce1
 
6899aff
f0dfb53
6899aff
f0dfb53
 
2772053
f0dfb53
 
 
6899aff
 
 
 
102c007
 
6899aff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1aa123
6899aff
 
e1aa123
6899aff
 
e1aa123
 
 
 
 
 
 
 
6899aff
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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 processDoubles import process_doubles
from replaceWords import replace_words

transcriber_hindi_new = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-hindi_v1")
transcriber_hindi_old = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-hindi_old")


def transcribe_hindi_new(audio):
    # # Process the audio file
    transcript = transcriber_hindi_new(audio)
    text_value = transcript['text']
    processd_doubles=process_doubles(text_value)
    replaced_words = replace_words(processd_doubles)
    converted_text=text_to_int(replaced_words)
    return converted_text

def transcribe_hindi_old(audio):
    # # Process the audio file
    transcript = transcriber_hindi_old(audio)
    text_value = transcript['text']
    cleaned_text=text_value.replace("<s>","")
    processd_doubles=process_doubles(cleaned_text)
    replaced_words = replace_words(processd_doubles)
    converted_text=text_to_int(replaced_words)
    return converted_text
    
def sel_lng(lng, mic=None, file=None):
    if mic is not None:
        audio = mic
    elif file is not None:
        audio = file
    else:
        return "You must either provide a mic recording or a file"
    
    if lng == "hindi_old":
        return transcribe_hindi_old(audio)
    elif lng == "hindi_new":
        return transcribe_hindi_new(audio)
        
# demo=gr.Interface(
#     transcribe,
#     inputs=[
#         gr.Audio(sources=["microphone","upload"], type="filepath"),
#     ],
#     outputs=[
#         "textbox"
#     ],
#     title="Automatic Speech Recognition",
#     description = "Demo for Automatic Speech Recognition. Use microphone to record speech. Please press Record button. Initially it will take some time to load the model. The recognized text will appear in the output textbox",
#       ).launch()

demo=gr.Interface(
    fn=sel_lng, 
      
    inputs=[
        gr.Dropdown([
            "hindi_new","hindi_old"],label="Select Language"),
        gr.Audio(sources=["microphone","upload"], type="filepath"),
    ],
    outputs=[
        "textbox"
    ],
    title="Automatic Speech Recognition",
    description = "Demo for Automatic Speech Recognition. Use microphone to record speech. Please press Record button. Initially it will take some time to load the model. The recognized text will appear in the output textbox",
      ).launch()