File size: 1,629 Bytes
8389164
 
 
 
84ee29a
8389164
 
f263ba4
8389164
f263ba4
8389164
 
 
84ee29a
8389164
84ee29a
 
8389164
 
 
84ee29a
d1adb8f
8389164
f263ba4
 
 
 
84ee29a
 
f263ba4
104c95a
f263ba4
294ff0d
f263ba4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84ee29a
f263ba4
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
from transformers import pipeline
import gradio as gr
import os

model_id = "HarshitJoshi/whisper-small-Hindi"
pipe = pipeline("automatic-speech-recognition", model=model_id)

def transcribe_speech(audio):
    output = pipe(
        audio,
        max_new_tokens=256,
        generate_kwargs={
            "task": "transcribe",
            "language": "hindi",
        },
        chunk_length_s=10,
        batch_size=4,
    )
    return output["text"]

example_folder = "./examples"
example_files = [f for f in os.listdir(example_folder) if f.endswith('.wav') or f.endswith('.mp3')]

def play_and_transcribe(filename):
    filepath = os.path.join(example_folder, filename)
    transcription = transcribe_speech(filepath)
    return filepath, transcription

with gr.Blocks() as demo:
    gr.Markdown("# Hindi Speech Transcription")
    
    with gr.Tab("Transcribe"):
        audio_input = gr.Audio(type="filepath", label="Audio Input")
        transcribe_button = gr.Button("Transcribe")
        output_text = gr.Textbox(label="Transcription")

        transcribe_button.click(
            fn=transcribe_speech,
            inputs=audio_input,
            outputs=output_text
        )

    with gr.Tab("Examples"):
        example_dropdown = gr.Dropdown(choices=example_files, label="Select an example")
        example_audio = gr.Audio(label="Audio Playback")
        example_transcription = gr.Textbox(label="Transcription")

        example_dropdown.change(
            fn=play_and_transcribe,
            inputs=example_dropdown,
            outputs=[example_audio, example_transcription]
        )

demo.launch(debug=True)