CoolFace
Apppublic

Add-Vishnu/Whisper_CPP_ASR_CLI

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
app.py79 linesDownload Raw Back to root
1import gradio as gr2import soundfile as sf3import tempfile4import shutil5import os6import librosa7import time8import numpy as np9import subprocess 10 11# command = r"""wine './whisper_blas_bin_v1_3_0/main.exe' -h"""12# wine_command = """sudo apt-get install wine"""13command2 = """chmod +777 ./whisper_blas_bin_v1_3_0/main.exe"""14# wine_c = subprocess.run(wine_command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE, text=True)15perm = subprocess.run(command2, shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE, text=True)16# result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)17# print("Wine Installation: ",wine_c)18print("Access Installation: ",perm)19# Fpr win32 instalattion while using medium model20# command3 = "apt install sudo"21# command4 = "dpkg --add-architecture i386"22# command5 = "apt-get update"23# command6 = "apt-get install wine32:i386"24# t1= subprocess.run(command3, shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE, text=True)25# t2= subprocess.run(command4, shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE, text=True)26# t3= subprocess.run(command5, shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE, text=True)27# t4= subprocess.run(command6, shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE, text=True)28# print("T1: ",t1)29# print("T2: ",t2)30# print("T3: ",t3)31# print("T4: ",t4)32 33 34def resample_to_16k(audio, orig_sr):35    y_resampled = librosa.resample(y=audio, orig_sr=orig_sr, target_sr = 16000)36    return y_resampled37 38def transcribe(audio):39    sr,y = audio40    y = y.astype(np.float32)41    y /= np.max(np.abs(y))42    y_resampled = resample_to_16k(y, sr)43    44    45    with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio:46        temp_audio_path = temp_audio.name47        sf.write(temp_audio_path, y_resampled, 16000)48 49 50    51    # command = rf"""wine './whisper_blas_bin_v1_3_0/main.exe' -m './whisper_blas_bin_v1_3_0/models/ggml-model-whisper-small.en.bin' -osrt -f '{temp_audio_path}' -nt"""  # English only52    command = rf"""wine './whisper_blas_bin_v1_3_0/main.exe' -m './whisper_blas_bin_v1_3_0/models/ggml-model-whisper-base.bin' -osrt -f '{temp_audio_path}' -nt"""    # Multilingual53    # win32 error while using medium model54    # command = rf"""wine './whisper_blas_bin_v1_3_0/main.exe' -m './whisper_blas_bin_v1_3_0/models/ggml-model-whisper-medium-q5_0.bin' -osrt -f '{temp_audio_path}' -nt"""    # Multilingual55    56    start_time = time.time()57    result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)58    end_time = time.time()59    print("Output",result.stdout)60    print("Error",result.stderr)61    transcription = result.stdout62    print(transcription)63    64    print("--------------------------")65    print(f"Execution time: {end_time - start_time} seconds")66    return transcription, (end_time - start_time)67 68 69 70demo = gr.Interface(71    transcribe,72    inputs = "microphone",73    # gr.Audio(sources=["microphone"]),74    outputs = [gr.Textbox(label="CLI_Transcription"),gr.Textbox(label="Time taken for Transcription")],75    examples=["./Samples/Hindi_1.mp3","./Samples/Hindi_2.mp3","./Samples/Tamil_1.mp3","./Samples/Tamil_2.mp3","./Samples/Marathi_1.mp3","./Samples/Marathi_2.mp3","./Samples/Nepal_1.mp3","./Samples/Nepal_2.mp3","./Samples/Telugu_1.wav","./Samples/Telugu_2.wav","./Samples/Malayalam_1.wav","./Samples/Malayalam_2.wav","./Samples/Gujarati_1.wav","./Samples/Gujarati_2.wav","./Samples/Bengali_1.wav","./Samples/Bengali_2.wav"]76 77)78 79demo.launch()