File size: 2,592 Bytes
51cfe72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Import necessary libraries and filter warnings
import warnings
warnings.filterwarnings("ignore")

import os
import re
import torchaudio
import gradio as gr
import numpy as np
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_multiples
from replaceWords import replace_words

pipe = pipeline(task="automatic-speech-recognition", model="C:/Users/WCHL/Desktop/huggingface_english/hf_eng")


def transcribe_english(audio):
    # # Process the audio file
    transcript = pipe(audio)
    text_value = transcript['text']
    cleaned_text=text_value.replace("<s>", "")
    converted_to_list=convert_to_list(cleaned_text,text_to_list())
    processd_multiples=process_multiples(converted_to_list)
    replaced_words = replace_words(processd_multiples)
    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 == "model_1":
#         return transcribe_hindi_old(audio)
#     elif lng == "model_2":
#         return transcribe_hindi_new(audio)
#     elif lng== "model_3":
#         return transcribe_hindi_lm(audio)
        
demo=gr.Interface(
    transcribe_english,
    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([
#             "model_1","model_2","model_3"],label="Select Model"),
#         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()